day08 task 1

This commit is contained in:
Johannes
2019-12-08 10:03:13 +01:00
parent ea9e2646ca
commit 397fd52aa0
5 changed files with 28 additions and 1 deletions

1
input/day08.txt Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
mod tasks; mod tasks;
fn main() { fn main() {
tasks::day06::run(); tasks::day08::run();
} }

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
#[allow(dead_code)]
pub fn run() { pub fn run() {
let input = std::fs::read_to_string("input/day06.txt").unwrap(); let input = std::fs::read_to_string("input/day06.txt").unwrap();
let orbits: Vec<_> = input let orbits: Vec<_> = input

24
src/tasks/day08.rs Normal file
View File

@@ -0,0 +1,24 @@
#[allow(dead_code)]
pub fn run() {
let size = 25 * 6;
let raw: Vec<u8> = std::fs::read_to_string("input/day08.txt")
.unwrap()
.chars()
.map(|c| c.to_digit(10).unwrap() as u8)
.collect();
let mut images = Vec::<Vec<u8>>::new();
for chunk in raw.chunks(size) {
images.push(chunk.iter().map(|it| *it).collect());
}
task1(&images);
}
fn task1(images: &Vec<Vec<u8>>) {
let fewest_zeros_layer = images
.iter()
.min_by_key(|it| it.iter().filter(|i| **i == 0).count())
.unwrap();
let ones = fewest_zeros_layer.iter().filter(|i| **i == 1).count();
let twos = fewest_zeros_layer.iter().filter(|i| **i == 2).count();
println!("Task 1: {}", ones * twos);
}

View File

@@ -2,3 +2,4 @@ pub mod day01;
pub mod day03; pub mod day03;
pub mod day04; pub mod day04;
pub mod day06; pub mod day06;
pub mod day08;