From: Grégory Burri Date: Mon, 9 Dec 2019 06:37:03 +0000 (+0100) Subject: Beginning of day 5 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=86c6a0f249b07e8e7d96e40809ad23ae04d15fd2;p=advent_of_code_2019.git Beginning of day 5 --- diff --git a/data/day05.input b/data/day05.input new file mode 100644 index 0000000..cc24dae --- /dev/null +++ b/data/day05.input @@ -0,0 +1 @@ +3,225,1,225,6,6,1100,1,238,225,104,0,101,14,135,224,101,-69,224,224,4,224,1002,223,8,223,101,3,224,224,1,224,223,223,102,90,169,224,1001,224,-4590,224,4,224,1002,223,8,223,1001,224,1,224,1,224,223,223,1102,90,45,224,1001,224,-4050,224,4,224,102,8,223,223,101,5,224,224,1,224,223,223,1001,144,32,224,101,-72,224,224,4,224,102,8,223,223,101,3,224,224,1,223,224,223,1102,36,93,225,1101,88,52,225,1002,102,38,224,101,-3534,224,224,4,224,102,8,223,223,101,4,224,224,1,223,224,223,1102,15,57,225,1102,55,49,225,1102,11,33,225,1101,56,40,225,1,131,105,224,101,-103,224,224,4,224,102,8,223,223,1001,224,2,224,1,224,223,223,1102,51,39,225,1101,45,90,225,2,173,139,224,101,-495,224,224,4,224,1002,223,8,223,1001,224,5,224,1,223,224,223,1101,68,86,224,1001,224,-154,224,4,224,102,8,223,223,1001,224,1,224,1,224,223,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,108,226,677,224,1002,223,2,223,1006,224,329,1001,223,1,223,1007,226,226,224,1002,223,2,223,1006,224,344,101,1,223,223,1008,226,226,224,102,2,223,223,1006,224,359,1001,223,1,223,107,226,677,224,1002,223,2,223,1005,224,374,101,1,223,223,1107,677,226,224,102,2,223,223,1006,224,389,101,1,223,223,108,677,677,224,102,2,223,223,1006,224,404,1001,223,1,223,1108,677,226,224,102,2,223,223,1005,224,419,101,1,223,223,1007,677,226,224,1002,223,2,223,1006,224,434,101,1,223,223,1107,226,226,224,1002,223,2,223,1006,224,449,101,1,223,223,8,677,226,224,102,2,223,223,1006,224,464,1001,223,1,223,1107,226,677,224,102,2,223,223,1005,224,479,1001,223,1,223,1007,677,677,224,102,2,223,223,1005,224,494,1001,223,1,223,1108,677,677,224,102,2,223,223,1006,224,509,101,1,223,223,1008,677,677,224,102,2,223,223,1005,224,524,1001,223,1,223,107,226,226,224,1002,223,2,223,1005,224,539,101,1,223,223,7,226,226,224,102,2,223,223,1005,224,554,101,1,223,223,1108,226,677,224,1002,223,2,223,1006,224,569,1001,223,1,223,107,677,677,224,102,2,223,223,1005,224,584,101,1,223,223,7,677,226,224,1002,223,2,223,1005,224,599,101,1,223,223,108,226,226,224,1002,223,2,223,1005,224,614,101,1,223,223,1008,677,226,224,1002,223,2,223,1005,224,629,1001,223,1,223,7,226,677,224,102,2,223,223,1005,224,644,101,1,223,223,8,677,677,224,102,2,223,223,1005,224,659,1001,223,1,223,8,226,677,224,102,2,223,223,1006,224,674,1001,223,1,223,4,223,99,226 \ No newline at end of file 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 {