diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:24:37 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:24:37 +0200 |
commit | c99848b907d2d63577ffdc81fc11a77e4d328a92 (patch) | |
tree | a8a0f1880c624572bf502cd33087c4ecdc9edbc7 /2017/src/bin/day_5.rs | |
parent | 24fb5e0204a4d69286473b660fd64a8d4a254eaf (diff) |
Refile for merging repos
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); +} |