Skip to content

Instantly share code, notes, and snippets.

@mloc
Created December 6, 2017 13:50
Show Gist options
  • Save mloc/216484cc315f34b98551868c3ad4de07 to your computer and use it in GitHub Desktop.
Save mloc/216484cc315f34b98551868c3ad4de07 to your computer and use it in GitHub Desktop.
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