Created
December 6, 2017 13:50
-
-
Save mloc/216484cc315f34b98551868c3ad4de07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::Read; | |
fn main() { | |
let mut f = File::open("d5.in").expect("input file not found"); | |
let mut s = String::new(); | |
f.read_to_string(&mut s).unwrap(); | |
let mut v: Vec<isize> = s.split("\n") | |
.filter(|s| s != &"") | |
.map(|s| s.parse::<isize>().unwrap()) | |
.collect(); | |
let mut c = 0; | |
let mut idx = 0; | |
while idx >= 0 && idx < v.len() as isize { | |
let ni = idx + v[idx as usize]; | |
v[idx as usize] += if v[idx as usize] < 3 { | |
1 | |
} else { | |
-1 | |
}; | |
idx = ni; | |
c += 1; | |
} | |
println!("{}", c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment