-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25.rs
40 lines (34 loc) · 942 Bytes
/
25.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
#![feature(test)]
type Input = Vec<Vec<Vec<bool>>>;
fn setup(input: &str) -> Input {
input
.trim()
.split("\n\n")
.map(|block| {
block
.lines()
.map(|line| line.bytes().map(|b| b == b'#').collect())
.collect()
})
.collect()
}
fn part1(input: &Input) -> usize {
let filtered = |keys| {
input.iter().filter(move |b| b[0][0] ^ keys).map(|b| {
(0..b[0].len())
.map(|i| b.iter().filter(|r| r[i]).count())
.collect::<Vec<_>>()
})
};
let locks = filtered(false).collect::<Vec<_>>();
filtered(true)
.flat_map(|k| {
locks.iter().filter(move |l| {
k.iter()
.zip(l.iter())
.all(|(&k, &l)| k + l <= input[0].len())
})
})
.count()
}
aoc::main!(2024, 25, ex: 1[a]);