diff --git a/src/aoc2022/day10/mod.rs b/src/aoc2022/day10/mod.rs index 12abef1..3f9b3be 100644 --- a/src/aoc2022/day10/mod.rs +++ b/src/aoc2022/day10/mod.rs @@ -29,5 +29,49 @@ pub fn task_one(input: &str) -> String { } pub fn task_two(input: &str) -> String { - String::new() + let mut x = 1; + let mut cycle = 1; + let mut output: Vec = Vec::new(); + + for line in input.trim().lines() { + let mut split = line.split_whitespace(); + + match split.next().unwrap() { + "noop" => { + if (x - 1) <= cycle % 40 && cycle % 40 <= (x + 1) { + output.push('#'); + } else { + output.push('.'); + } + } + "addx" => { + if (x - 1) <= cycle % 40 && cycle % 40 <= (x + 1) { + output.push('#'); + } else { + output.push('.'); + } + + cycle += 1; + + x += split.next().unwrap().parse::().unwrap(); + + if (x - 1) <= cycle % 40 && cycle % 40 <= (x + 1) { + output.push('#'); + } else { + output.push('.'); + } + } + _ => panic!(), + } + + cycle += 1; + } + + println!("{}", String::from_iter(output.get(0..40).unwrap().iter())); + println!("{}", String::from_iter(output.get(40..80).unwrap().iter())); + println!("{}", String::from_iter(output.get(80..120).unwrap().iter())); + println!("{}", String::from_iter(output.get(120..160).unwrap().iter())); + println!("{}", String::from_iter(output.get(160..200).unwrap().iter())); + println!("{}", String::from_iter(output.get(200..240).unwrap().iter())); + "print above PBZGRAZA".to_string() }