diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2017-12-10 07:52:37 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2017-12-10 07:52:37 +0200 |
commit | 138acea6881bc1610705ea4de31e7c60030e0852 (patch) | |
tree | 9fd1174eb9f69bcf3edc0f1814d7f530c6179340 /src/bin/day_9.rs | |
parent | 4123ba15c9b2d2d474d9ff586b080fca2e5783f1 (diff) |
Day 9: Cleaning up garbage
Diffstat (limited to 'src/bin/day_9.rs')
-rw-r--r-- | src/bin/day_9.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/bin/day_9.rs b/src/bin/day_9.rs new file mode 100644 index 0000000..e0ca0c0 --- /dev/null +++ b/src/bin/day_9.rs @@ -0,0 +1,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); + } +} |