1
0
Fork 0
This commit is contained in:
Lars Martens 2021-12-06 12:38:41 +01:00
parent b26a3830d2
commit 4b4d4bdadd
3 changed files with 40 additions and 0 deletions

1
input/06-test.txt Normal file
View file

@ -0,0 +1 @@
3,4,3,1,2

1
input/06.txt Normal file
View file

@ -0,0 +1 @@
1,1,3,5,1,1,1,4,1,5,1,1,1,1,1,1,1,3,1,1,1,1,2,5,1,1,1,1,1,2,1,4,1,4,1,1,1,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,3,5,1,1,1,1,4,1,5,4,1,1,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,5,1,1,1,3,4,1,1,1,1,3,1,1,1,1,1,4,1,1,3,1,1,3,1,1,1,1,1,3,1,5,2,3,1,2,3,1,1,2,1,2,4,5,1,5,1,4,1,1,1,1,2,1,5,1,1,1,1,1,5,1,1,3,1,1,1,1,1,1,4,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,1,1,1,1,2,2,1,2,1,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,5,1,1,1,1,1,1,1,1,3,1,1,3,3,1,1,1,3,5,1,1,4,1,1,1,1,1,4,1,1,3,1,1,1,1,1,1,1,1,2,1,5,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1

38
src/bin/06.rs Normal file
View file

@ -0,0 +1,38 @@
use std::collections::VecDeque;
type School = VecDeque<u64>;
fn main() {
let mut fish = input();
for _ in 0..80 {
step(&mut fish);
}
println!("First solution: {}", sum(&fish));
let mut fish = input();
for _ in 0..256 {
step(&mut fish);
}
println!("Second solution: {}", sum(&fish));
}
fn step(fish: &mut School) {
let front = fish.pop_front().unwrap();
fish.push_back(front);
fish[6] += front;
}
fn sum(fish: &School) -> u64 {
fish.iter().sum()
}
fn input() -> School {
let init: School = vec![0; 9].into();
include_str!("../../input/06.txt")
.split(',')
.map(|n| n.parse().unwrap())
.fold(init, |mut acc, n| {
acc[n] += 1;
acc
})
}