1const WIDTH: usize = 25;
3const HEIGHT: usize = 6;
4const LAYER_SIZE: usize = WIDTH * HEIGHT;
5
6pub fn parse(input: &str) -> &[u8] {
7 input.as_bytes()
8}
9
10pub fn part1(input: &[u8]) -> u32 {
12 let (ones, twos) = input
13 .chunks_exact(LAYER_SIZE)
14 .map(|layer| {
15 layer.iter().fold((0, 0), |(ones, twos), &b| {
16 (ones + u32::from(b & 1), twos + u32::from((b >> 1) & 1))
17 })
18 })
19 .max_by_key(|&(ones, twos)| ones + twos)
20 .unwrap();
21
22 ones * twos
23}
24
25pub fn part2(input: &[u8]) -> String {
28 let mut result = String::with_capacity((WIDTH + 1) * HEIGHT);
30
31 for y in 0..HEIGHT {
32 result.push('\n');
33
34 for x in 0..WIDTH {
35 let mut i = WIDTH * y + x;
36
37 while input[i] == b'2' {
38 i += LAYER_SIZE;
39 }
40
41 result.push(if input[i] == b'1' { '#' } else { '.' });
42 }
43 }
44
45 result
46}