summaryrefslogtreecommitdiff
path: root/2017/src/bin/day_5.rs
diff options
context:
space:
mode:
Diffstat (limited to '2017/src/bin/day_5.rs')
-rw-r--r--2017/src/bin/day_5.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/2017/src/bin/day_5.rs b/2017/src/bin/day_5.rs
new file mode 100644
index 0000000..49bdbd1
--- /dev/null
+++ b/2017/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);
+}