From e9e83bada467f57e3e9812d8b4ce5fbcd043c325 Mon Sep 17 00:00:00 2001 From: Bizcochito Date: Mon, 12 Dec 2022 08:39:39 +0100 Subject: [PATCH] day 10 done :3 --- day10/src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/day10/src/main.rs b/day10/src/main.rs index 7c199bb..92b8a08 100644 --- a/day10/src/main.rs +++ b/day10/src/main.rs @@ -9,6 +9,24 @@ fn main() { println!("The sum of the asked for signals is: {}", get_dump(&contents).iter().enumerate().take_while(|(n, _)| n<=&220).map(|(c, rx)| (c+1 ,(c+1) as i32*rx)) .filter(|(n, _)| (n/20)%2==1).step_by(20).map(|(_, out)| out).sum::()); + print!("{}", get_pixels(get_dump(&contents))); +} + +fn get_pixels(i: Vec) -> String { + let mut screen = String::new(); + let mut pixel = 0; + while pixel < i.len() { + for r in 0..40{ + if r-1 == i[pixel] || r == i[pixel] || r+1 == i[pixel]{ + screen.push('#') + }else{ + screen.push('.') + } + pixel +=1; + } + screen.push_str("\n") + } + screen } fn get_dump(s: &str) -> Vec { @@ -183,4 +201,14 @@ noop"#; assert_eq!(get_dump(INPUT).iter().enumerate().take_while(|(n, _)| n<=&220).map(|(c, rx)| (c+1 ,(c+1) as i32*rx)) .filter(|(n, _)| (n/20)%2==1).step_by(20).map(|(_, out)| out).sum::(), 13140); } + #[test] + fn crt2() { + assert_eq!(get_pixels(get_dump(INPUT)), r#"##..##..##..##..##..##..##..##..##..##.. +###...###...###...###...###...###...###. +####....####....####....####....####.... +#####.....#####.....#####.....#####..... +######......######......######......#### +#######.......#######.......#######..... +"#); + } } \ No newline at end of file