summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-12-05 20:11:10 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-12-05 20:11:10 +0200
commit895f9bdc60c476861757c083c98a516b8238c84a (patch)
treef4b517093e54a4947be3477606fca96945c3b01e /src
parentf1aa1ef9471d98c5422a02a1077d34865bbe5ee9 (diff)
Day 5: CPU jumps
Diffstat (limited to 'src')
-rw-r--r--src/bin/day_5.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bin/day_5.rs b/src/bin/day_5.rs
new file mode 100644
index 0000000..49bdbd1
--- /dev/null
+++ b/src/bin/day_5.rs
@@ -0,0 +1,25 @@
+extern crate advent_of_code_2017;
+use advent_of_code_2017::*;
+
+fn main() {
+ let args = AdventArgs::init();
+
+ let mut jumps: Vec<i32> = args.input.iter().map(|line| line.parse().unwrap()).collect();
+ let mut steps_taken = 0;
+ let mut current_position: i32 = 0;
+
+ while current_position >= 0 && (current_position as usize) < jumps.len() {
+ let previous_position = current_position;
+ current_position += jumps[current_position as usize];
+
+ if args.part == 1 || jumps[previous_position as usize] < 3 {
+ jumps[previous_position as usize] += 1;
+ } else {
+ jumps[previous_position as usize] -= 1;
+ }
+
+ steps_taken += 1;
+ }
+
+ println!("Escaped in {} jumps", steps_taken);
+}