1pub fn parse(input: &str) -> &str {
4 input
5}
6
7pub fn part1(input: &str) -> u32 {
14 let bytes = input.as_bytes();
15 let mut index = 0;
16 let mut ones = 0;
17 let mut twos = 0;
18 let mut most = 0;
19 let mut result = 0;
20
21 for _ in 0..100 {
22 for _ in 0..18 {
24 let slice = &bytes[index..(index + 8)];
25 let n = u64::from_be_bytes(slice.try_into().unwrap());
26 ones += (n & 0x0101010101010101).count_ones();
27 twos += (n & 0x0202020202020202).count_ones();
28 index += 8;
29 }
30
31 let slice = &bytes[(index - 2)..(index + 6)];
34 let n = u64::from_be_bytes(slice.try_into().unwrap());
35 ones += (n & 0x0000010101010101).count_ones();
36 twos += (n & 0x0000020202020202).count_ones();
37 index += 6;
38
39 if ones + twos > most {
40 most = ones + twos;
41 result = ones * twos;
42 }
43
44 ones = 0;
45 twos = 0;
46 }
47
48 result
49}
50
51pub fn part2(input: &str) -> String {
54 let bytes = input.as_bytes();
55 let mut image = ['.'; 150];
56
57 for (i, pixel) in image.iter_mut().enumerate() {
58 let mut j = i;
59
60 while bytes[j] == b'2' {
61 j += 150;
62 }
63
64 if bytes[j] == b'1' {
65 *pixel = '#';
66 }
67 }
68
69 let mut result =
70 image.chunks_exact(25).map(|row| row.iter().collect()).collect::<Vec<String>>().join("\n");
71 result.insert(0, '\n');
72 result
73}