-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.rs
More file actions
20 lines (20 loc) · 689 Bytes
/
main.rs
File metadata and controls
20 lines (20 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pub fn main() {
let input = include_bytes!("../input.txt");
let col = input.iter().position(|&b| b == b':').unwrap();
let sep = input.iter().position(|&b| b == b'|').unwrap();
println!(
"{}",
input
.split(|&b| b == b'\n')
.map(|game| {
let win_seq = &game[col + 1..sep];
let win_count = game[sep + 1..]
.chunks_exact(3)
.map(|n| &n[1..])
.filter(|n| win_seq.chunks_exact(3).map(|n| &n[1..]).any(|c| &c == n))
.count() as u32;
2usize.pow(win_count) >> 1
})
.sum::<usize>()
);
}