-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rs
27 lines (27 loc) · 969 Bytes
/
main.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
pub fn main() {
println!(
"{}",
include_bytes!("../input.txt")
.split(|b| b == &b'\n')
.enumerate()
.filter_map(|(game_id, line)| {
let mut rgb = [0, 0, 0];
line.splitn(2, |b| b == &b':')
.nth(1)
.unwrap()
.split(|b| b == &b',' || b == &b';')
.all(|item| {
let i = match item[1..].splitn(2, |b| *b == b' ').nth(1).unwrap() {
b"red" => 0usize,
b"green" => 1,
b"blue" => 2,
_ => unreachable!(),
};
rgb[i] = rgb[i].max(atoi::atoi(&item[1..]).unwrap());
rgb[i] <= 12 + i as u32
})
.then_some(game_id + 1)
})
.sum::<usize>()
);
}