summaryrefslogtreecommitdiff
path: root/2017/src/bin/day_5.rs
blob: 49bdbd12924e9adbb4d60c4b3cd601788393b6f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
}