day08 task 2
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use itertools::Itertools;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn run() {
|
||||
let size = 25 * 6;
|
||||
@@ -11,6 +13,7 @@ pub fn run() {
|
||||
images.push(chunk.iter().map(|it| *it).collect());
|
||||
}
|
||||
task1(&images);
|
||||
task2(&images);
|
||||
}
|
||||
|
||||
fn task1(images: &Vec<Vec<u8>>) {
|
||||
@@ -22,3 +25,22 @@ fn task1(images: &Vec<Vec<u8>>) {
|
||||
let twos = fewest_zeros_layer.iter().filter(|i| **i == 2).count();
|
||||
println!("Task 1: {}", ones * twos);
|
||||
}
|
||||
|
||||
fn task2(images: &Vec<Vec<u8>>) {
|
||||
let n_pixels = images[0].len();
|
||||
let result: Vec<u8> = (0..n_pixels)
|
||||
.map(|pix| images.iter().find(|layer| layer[pix] != 2).unwrap()[pix])
|
||||
.collect();
|
||||
for row in result.chunks(25) {
|
||||
println!(
|
||||
"{}",
|
||||
row.iter()
|
||||
.map(|it| if *it == 0 {
|
||||
format!(" ")
|
||||
} else {
|
||||
format!("{}", it)
|
||||
})
|
||||
.join("")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user