From 813ef23a27ca4b4cc708dbf21bdbcf39d186118c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9gory=20Burri?= Date: Mon, 9 Dec 2019 07:37:03 +0100 Subject: [PATCH] Beginning of day 5 --- src/day02.rs | 6 +++--- src/day05.rs | 33 +++++++++++++++++++++++++++++++++ src/main.rs | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/day05.rs diff --git a/src/day02.rs b/src/day02.rs index 9db5379..81dfaaf 100644 --- a/src/day02.rs +++ b/src/day02.rs @@ -1,10 +1,10 @@ -pub fn execute_op_code_with_state_fixed(code : &mut [i32]) -> i32 { +pub fn execute_op_code_with_state_fixed(code: &mut [i32]) -> i32 { code[1] = 12; code[2] = 2; execute_op_code(code) } -fn execute_op_code(code : &mut [i32]) -> i32 { +fn execute_op_code(code: &mut [i32]) -> i32 { let mut cursor = 0; loop { match code[cursor] { @@ -17,7 +17,7 @@ fn execute_op_code(code : &mut [i32]) -> i32 { } } -pub fn find_noun_and_verb(code : &[i32]) -> i32 { +pub fn find_noun_and_verb(code: &[i32]) -> i32 { loop { for verb in 0..=99 { for noun in 0..=99 { diff --git a/src/day05.rs b/src/day05.rs new file mode 100644 index 0000000..1ff5739 --- /dev/null +++ b/src/day05.rs @@ -0,0 +1,33 @@ +fn read_code(code: i32) -> (i32, Vec) { + +} + +fn execute_op_code(code: &mut [i32], input: &[i32]) -> Vec { + let mut cursor = 0; + let mut output = Vec::::new(); + loop { + match code[cursor] { + 1 => code[code[cursor + 3] as usize] = code[code[cursor + 1] as usize] + code[code[cursor + 2] as usize], + 2 => code[code[cursor + 3] as usize] = code[code[cursor + 1] as usize] * code[code[cursor + 2] as usize], + 99 => return code[0], + _ => panic!("Unkown code: {}", code[cursor]) + } + cursor += 4; + } +} + + + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn part1() { + } + + #[test] + fn part2() { + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b508728..f00a372 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::time::Instant; mod day01; mod day02; mod day03; +mod day05; mod common; fn day01() -> String { -- 2.45.2