-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rs
26 lines (26 loc) · 906 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
pub fn main() {
println!(
"{}",
include_bytes!("../input.txt")
.split(|b| b == &b'\n')
.map(|line| {
line.splitn(2, |b| b == &b':')
.nth(1)
.unwrap()
.split(|b| b == &b',' || b == &b';')
.fold([0, 0, 0], |mut rgb, 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
})
.iter()
.product::<u32>()
})
.sum::<u32>()
);
}