Skip to content

Commit d12273d

Browse files
authored
Merge pull request #59 from romellem/2017/day-9
2017 - Day 9
2 parents b2fbcf5 + 298f093 commit d12273d

File tree

6 files changed

+182
-0
lines changed

6 files changed

+182
-0
lines changed

2017/9/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Answers
2+
3+
| Part 1 | Part 2 |
4+
|---------|--------|
5+
| `10050` | `4482` |
6+
7+
## --- Day 9: Stream Processing ---
8+
9+
A large stream blocks your path. According to the locals, it's not safe to cross the stream at the moment because it's full of _garbage_. You look down at the stream; rather than water, you discover that it's a _stream of characters_.
10+
11+
You sit for a while and record part of the stream (your puzzle input). The characters represent _groups_ - sequences that begin with `{` and end with `}`. Within a group, there are zero or more other things, separated by commas: either another _group_ or _garbage_. Since groups can contain other groups, a `}` only closes the _most-recently-opened unclosed group_ - that is, they are nestable. Your puzzle input represents a single, large group which itself contains many smaller ones.
12+
13+
Sometimes, instead of a group, you will find _garbage_. Garbage begins with `<` and ends with `>`. Between those angle brackets, almost any character can appear, including `{` and `}`. _Within_ garbage, `<` has no special meaning.
14+
15+
In a futile attempt to clean up the garbage, some program has _canceled_ some of the characters within it using `!`: inside garbage, _any_ character that comes after `!` should be _ignored_, including `<`, `>`, and even another `!`.
16+
17+
You don't see any characters that deviate from these rules. Outside garbage, you only find well-formed groups, and garbage always terminates according to the rules above.
18+
19+
Here are some self-contained pieces of garbage:
20+
21+
* `<>`, empty garbage.
22+
* `<random characters>`, garbage containing random characters.
23+
* `<<<<>`, because the extra `<` are ignored.
24+
* `<{!>}>`, because the first `>` is canceled.
25+
* `<!!>`, because the second `!` is canceled, allowing the `>` to terminate the garbage.
26+
* `<!!!>>`, because the second `!` and the first `>` are canceled.
27+
* `<{o"i!a,<{i<a>`, which ends at the first `>`.
28+
29+
Here are some examples of whole streams and the number of groups they contain:
30+
31+
* `{}`, `1` group.
32+
* `{{{}}}`, `3` groups.
33+
* `{{},{}}`, also `3` groups.
34+
* `{{{},{},{{}}}}`, `6` groups.
35+
* `{<{},{},{{}}>}`, `1` group (which itself contains garbage).
36+
* `{<a>,<a>,<a>,<a>}`, `1` group.
37+
* `{{<a>},{<a>},{<a>},{<a>}}`, `5` groups.
38+
* `{{<!>},{<!>},{<!>},{<a>}}`, `2` groups (since all but the last `>` are canceled).
39+
40+
Your goal is to find the total score for all groups in your input. Each group is assigned a _score_ which is one more than the score of the group that immediately contains it. (The outermost group gets a score of `1`.)
41+
42+
* `{}`, score of `1`.
43+
* `{{{}}}`, score of `1 + 2 + 3 = 6`.
44+
* `{{},{}}`, score of `1 + 2 + 2 = 5`.
45+
* `{{{},{},{{}}}}`, score of `1 + 2 + 3 + 3 + 3 + 4 = 16`.
46+
* `{<a>,<a>,<a>,<a>}`, score of `1`.
47+
* `{{<ab>},{<ab>},{<ab>},{<ab>}}`, score of `1 + 2 + 2 + 2 + 2 = 9`.
48+
* `{{<!!>},{<!!>},{<!!>},{<!!>}}`, score of `1 + 2 + 2 + 2 + 2 = 9`.
49+
* `{{<a!>},{<a!>},{<a!>},{<ab>}}`, score of `1 + 2 = 3`.
50+
51+
_What is the total score_ for all groups in your input?
52+
53+
-----------------
54+
55+
## --- Part Two ---
56+
57+
Now, you're ready to remove the garbage.
58+
59+
To prove you've removed it, you need to count all of the characters within the garbage. The leading and trailing `<` and `>` don't count, nor do any canceled characters or the `!` doing the canceling.
60+
61+
* `<>`, `0` characters.
62+
* `<random characters>`, `17` characters.
63+
* `<<<<>`, `3` characters.
64+
* `<{!>}>`, `2` characters.
65+
* `<!!>`, `0` characters.
66+
* `<!!!>>`, `0` characters.
67+
* `<{o"i!a,<{i<a>`, `10` characters.
68+
69+
_How many non-canceled characters are within the garbage_ in your puzzle input?

2017/9/input.js

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)