-
Notifications
You must be signed in to change notification settings - Fork 0
/
six.rs
35 lines (29 loc) · 772 Bytes
/
six.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use libaoc::{Day, DayNumber};
fn solve<const TICKS: usize>(input: &str) -> Box<usize> {
let fish: Vec<usize> = input
.split_once('\n')
.unwrap()
.0
.split(',')
.map(|number| number.parse().unwrap())
.collect();
let mut counts = [0; 9];
for &i in &fish {
counts[i] += 1;
}
for _ in 0..TICKS {
let mut new_counts = [0; 9];
new_counts[..9 - 1].copy_from_slice(&counts[1..9]);
new_counts[6] += &counts[0];
new_counts[8] += &counts[0];
counts = new_counts;
}
Box::new(counts.iter().sum::<usize>())
}
pub fn six() -> Day<2021> {
Day::new(
DayNumber::Six,
|input| solve::<80>(input),
|input| solve::<256>(input),
)
}