-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.rs
More file actions
20 lines (19 loc) · 696 Bytes
/
main.rs
File metadata and controls
20 lines (19 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#[allow(clippy::unit_cmp)]
pub fn main() {
println!(
"{}",
include_str!("../input.txt")
.lines()
.filter_map(|seq| seq
.bytes()
.scan(Vec::with_capacity(64), |s, c| Some(match c {
c if matches!(c, b'(' | b'[' | b'{' | b'<') => (s.push(c) != ()).then(|| b' '),
b')' => (s.pop().unwrap() != b'(').then(|| b')'),
c => (s.pop().unwrap() != c - 2).then(|| c),
}))
.skip_while(Option::is_none)
.map(|c| [3, 25137, 57, 1197][c.unwrap() as usize / 30 - 1])
.next())
.sum::<usize>()
);
}