-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.rs
More file actions
19 lines (17 loc) · 525 Bytes
/
main.rs
File metadata and controls
19 lines (17 loc) · 525 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
pub fn main() {
let program: Vec<(&[u8], isize)> = include_bytes!("../input.txt")
.split(|b| b == &b'\n')
.map(|ins| (&ins[0..3], atoi::atoi(&ins[4..]).unwrap()))
.collect();
let (mut visited, mut pc, mut acc) = (vec![], 0, 0);
while !visited.contains(&pc) {
visited.push(pc);
match program[pc] {
(b"acc", val) => acc += val,
(b"jmp", val) => pc += val as usize - 1,
_ => {}
}
pc += 1;
}
println!("{}", acc);
}