-
Notifications
You must be signed in to change notification settings - Fork 0
/
06.rs
41 lines (35 loc) · 906 Bytes
/
06.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
36
37
38
39
40
41
#![feature(test)]
use rustc_hash::FxHashSet;
type Input = Vec<Vec<Vec<u8>>>;
fn setup(input: &str) -> Input {
input
.split("\n\n")
.map(|group| group.lines().map(|line| line.bytes().collect()).collect())
.collect()
}
fn part1(input: &Input) -> usize {
input
.iter()
.map(|group| group.iter().flatten().collect::<FxHashSet<_>>().len())
.sum()
}
fn part2(input: &Input) -> usize {
input
.iter()
.map(|group| {
let l = group.len();
group
.iter()
.fold([0; 256], |mut acc, xs| {
for &x in xs {
acc[x as usize] += 1;
}
acc
})
.into_iter()
.filter(|&x| x == l)
.count()
})
.sum()
}
aoc::main!(2020, 6, ex: 1);