Private Leaderboard: join 265794-f7a74408 https://adventofcode.com/2019/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aoc2019/day8/src/main.rs

39 lines
908 B

3 years ago
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::<Vec<_>>();
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!("");
}
}