diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:29:56 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:29:56 +0200 |
commit | 34c0aa87fada4bf3bc75ff0493e0876e65289697 (patch) | |
tree | 599148bcbb7f05941edfac5ab3454a878129e997 /2017/src/bin/day_5.rs | |
parent | 174772b5b8d9f5bf5e3c8e8152adfd89f0e83f6b (diff) | |
parent | c99848b907d2d63577ffdc81fc11a77e4d328a92 (diff) |
Merge branch '2017-main'
Diffstat (limited to '2017/src/bin/day_5.rs')
-rw-r--r-- | 2017/src/bin/day_5.rs | 25 |
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); +} |