Day 10, puzzle 1

This commit is contained in:
jazzpi
2022-12-15 15:44:37 +01:00
parent 71984d10d6
commit 05f3d9411a
3 changed files with 85 additions and 0 deletions

16
src/bin/d10p1.rs Normal file
View File

@ -0,0 +1,16 @@
use aoc22::{day10, util};
pub fn main() {
let instructions = day10::parse_instructions(&util::parse_input());
let mut cpu = day10::CPU::new(instructions);
let mut sum = 0;
for _ in 0..221 {
if (cpu.cycle - (20 - 1)) % 40 == 0 {
sum += cpu.signal_strength();
}
cpu.do_cycle().expect("No more instructions?");
}
println!("Sum of 20 + 40n cycles: {}", sum);
}