#[path = "../lib.rs"] mod lib; use std::convert::TryFrom; fn main() { let mut cycle: i64 = 1; let mut x: i64 = 1; let mut part1_sum: i64 = 0; let mut screen = [[false; 40]; 6]; for line in lib::iter_input() { let (duration, value) = match line.split(" ").collect::>()[..] { ["noop"] => (1, 0), ["addx", v] => (2, v.parse::().unwrap()), _ => unreachable!(), }; for _ in 0..duration { if cycle % 40 == 20 { part1_sum += cycle * x; } let screen_x = (cycle - 1) % 40; if (x - screen_x).abs() <= 1 { let screen_y = ((cycle - 1) / 40) % 6; let ux = usize::try_from(screen_x).unwrap(); let uy = usize::try_from(screen_y).unwrap(); screen[uy][ux] = true; } cycle += 1; } x += value; } println!("part1: {}", part1_sum); println!("part2:"); for row in screen.iter() { for cell in row.iter() { print!("{}", if *cell { "#" } else { " " }); } print!("\n"); } }