Beginning of day 5
authorGrégory Burri <gregory.burri@matisa.ch>
Mon, 9 Dec 2019 06:37:03 +0000 (07:37 +0100)
committerGrégory Burri <gregory.burri@matisa.ch>
Mon, 9 Dec 2019 06:37:03 +0000 (07:37 +0100)
data/day05.input [new file with mode: 0644]
src/day02.rs
src/day05.rs [new file with mode: 0644]
src/main.rs

diff --git a/data/day05.input b/data/day05.input
new file mode 100644 (file)
index 0000000..cc24dae
--- /dev/null
@@ -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
index 9db5379..81dfaaf 100644 (file)
@@ -1,10 +1,10 @@
-pub fn execute_op_code_with_state_fixed(code : &mut [i32]) -> i32 {\r
+pub fn execute_op_code_with_state_fixed(code: &mut [i32]) -> i32 {\r
     code[1] = 12;\r
     code[2] = 2;\r
     execute_op_code(code)\r
 }\r
 \r
-fn execute_op_code(code : &mut [i32]) -> i32 {\r
+fn execute_op_code(code: &mut [i32]) -> i32 {\r
     let mut cursor = 0;\r
     loop {\r
         match code[cursor] {\r
@@ -17,7 +17,7 @@ fn execute_op_code(code : &mut [i32]) -> i32 {
     }\r
 }\r
 \r
-pub fn find_noun_and_verb(code : &[i32]) -> i32 {\r
+pub fn find_noun_and_verb(code: &[i32]) -> i32 {\r
     loop {\r
         for verb in 0..=99 {\r
             for noun in 0..=99 {\r
diff --git a/src/day05.rs b/src/day05.rs
new file mode 100644 (file)
index 0000000..1ff5739
--- /dev/null
@@ -0,0 +1,33 @@
+fn read_code(code: i32) -> (i32, Vec<bool>) {\r
+\r
+}\r
+\r
+fn execute_op_code(code: &mut [i32], input: &[i32]) -> Vec<i32> {\r
+    let mut cursor = 0;\r
+    let mut output = Vec::<i32>::new();\r
+    loop {\r
+        match code[cursor] {\r
+            1 => code[code[cursor + 3] as usize] = code[code[cursor + 1] as usize] + code[code[cursor + 2] as usize],\r
+            2 => code[code[cursor + 3] as usize] = code[code[cursor + 1] as usize] * code[code[cursor + 2] as usize],\r
+            99 => return code[0],\r
+            _ => panic!("Unkown code: {}", code[cursor])\r
+        }\r
+        cursor += 4;\r
+    }\r
+}\r
+\r
+\r
+\r
+\r
+#[cfg(test)]\r
+mod tests {\r
+    use super::*;\r
+\r
+    #[test]\r
+    fn part1() {\r
+    }\r
+\r
+    #[test]\r
+    fn part2() {\r
+    }\r
+}
\ No newline at end of file
index b508728..f00a372 100644 (file)
@@ -5,6 +5,7 @@ use std::time::Instant;
 mod day01;
 mod day02;
 mod day03;
+mod day05;
 mod common;
 
 fn day01() -> String {