fn main() { let input = include_str!("input.txt").as_bytes(); const LAYER_SIZE: usize = 6*25; assert_eq!(input.len() % LAYER_SIZE, 0); let layers = input.chunks(LAYER_SIZE).collect::>(); let min0_product12 = layers.iter().map(|layer| { let mut count = [0, 0, 0]; for b in *layer { let digit = *b - b'0'; if digit < 3 { count[digit as usize] += 1; } } (count[0], count[1]*count[2]) }).min_by_key(|(zeroes, _product12)| *zeroes).unwrap().1; println!("Product of counts of 1 and 2 for the layer with min 0s: {}", min0_product12); let mut image = [2u8; LAYER_SIZE]; for layer in layers { for (ndx, b) in layer.into_iter().enumerate() { let digit = *b - b'0'; if image[ndx] != 2 { continue; } image[ndx] = digit; } } for row in image.chunks(25) { for cell in row { match cell { 1 => print!("#"), _ => print!(" "), } } println!(""); } }