summaryrefslogtreecommitdiff
path: root/2017/src/bin/day_9.rs
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2022-04-19 20:29:56 +0200
committerJustin Wernick <justin@worthe-it.co.za>2022-04-19 20:29:56 +0200
commit34c0aa87fada4bf3bc75ff0493e0876e65289697 (patch)
tree599148bcbb7f05941edfac5ab3454a878129e997 /2017/src/bin/day_9.rs
parent174772b5b8d9f5bf5e3c8e8152adfd89f0e83f6b (diff)
parentc99848b907d2d63577ffdc81fc11a77e4d328a92 (diff)
Merge branch '2017-main'
Diffstat (limited to '2017/src/bin/day_9.rs')
-rw-r--r--2017/src/bin/day_9.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/2017/src/bin/day_9.rs b/2017/src/bin/day_9.rs
new file mode 100644
index 0000000..e0ca0c0
--- /dev/null
+++ b/2017/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);
+ }
+}