blob: e0ca0c02ba091de326a6947c2db91e1bae7d55b2 (
plain)
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
41
42
|
extern crate advent_of_code_2017;
use advent_of_code_2017::*;
fn main() {
let args = AdventArgs::init();
let mut cancelled = false;
let mut in_garbage = false;
let mut depth = 0;
let mut total_score = 0;
let mut total_garbage = 0;
for c in args.input[0].chars() {
if cancelled {
cancelled = false;
} else if c == '!' {
cancelled = true;
} else if in_garbage {
if c == '>' {
in_garbage = false;
} else {
total_garbage += 1;
}
} else {
if c == '<' {
in_garbage = true;
} else if c == '{' {
depth += 1;
total_score += depth;
} else if c == '}' {
depth -= 1;
}
}
}
if args.part == 1 {
println!("Total score is {}", total_score);
} else {
println!("Total garbage is {}", total_garbage);
}
}
|