-
Notifications
You must be signed in to change notification settings - Fork 0
/
day9.p
89 lines (74 loc) · 18.9 KB
/
day9.p
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
--- Day 9: Stream Processing ---
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.
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.
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.
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 !.
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.
Here are some self-contained pieces of garbage:
<>, empty garbage.
<random characters>, garbage containing random characters.
<<<<>, because the extra < are ignored.
<{!>}>, because the first > is canceled.
<!!>, because the second ! is canceled, allowing the > to terminate the garbage.
<!!!>>, because the second ! and the first > are canceled.
<{o"i!a,<{i<a>, which ends at the first >.
Here are some examples of whole streams and the number of groups they contain:
{}, 1 group.
{{{}}}, 3 groups.
{{},{}}, also 3 groups.
{{{},{},{{}}}}, 6 groups.
{<{},{},{{}}>}, 1 group (which itself contains garbage).
{<a>,<a>,<a>,<a>}, 1 group.
{{<a>},{<a>},{<a>},{<a>}}, 5 groups.
{{<!>},{<!>},{<!>},{<a>}}, 2 groups (since all but the last > are canceled).
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.)
{}, score of 1.
{{{}}}, score of 1 + 2 + 3 = 6.
{{},{}}, score of 1 + 2 + 2 = 5.
{{{},{},{{}}}}, score of 1 + 2 + 3 + 3 + 3 + 4 = 16.
{<a>,<a>,<a>,<a>}, score of 1.
{{<ab>},{<ab>},{<ab>},{<ab>}}, score of 1 + 2 + 2 + 2 + 2 = 9.
{{<!!>},{<!!>},{<!!>},{<!!>}}, score of 1 + 2 + 2 + 2 + 2 = 9.
{{<a!>},{<a!>},{<a!>},{<ab>}}, score of 1 + 2 = 3.
*/
DEFINE VARIABLE cInput AS CHARACTER NO-UNDO.
/* cInput = "~{~{<a!>},~{<a!>},~{<a!>},~{<ab>}}". */
cInput = "~{~{~{~{~{},~{<>,<!!u'!!!>,,}!>~"!!!!!>},<>}}},~{~{~{~{~{~{~{<!>,<~"}!i~"!>},<a!!,<!>},<~{oo<~{!!~"!>!a>},<~"!!''!>},<!!!>!,ie!>,!!!>>}},~{~{}},~{~{~{<!>},<~{e!>,>,<!!e~{,o}o~"!>!>,<~"~"~{uu~{!!'a>},<}a!!!!>},~{~{<,,ua~"o!>!>,<!!a,>}},~{~{}}}},~{~{},~{<!a~{}<!>,<!>,<!!u>},~{~{},<i,ai'}!>},<!!!!!}e''!!!!~{>}},~{~{~{<!>!!,i!>},<u!!!>o~",<!!~{a!!u'e!>},<,!>},<>},<>},~{~{<!>},<!>}}!!!>a!!u!!'!>,<aa!!,e>},~{<!o!>},<}'u!!ii!>!!!>!!!>~{<}!!!>!!<i!!}!!!>>}}}},~{~{~{~{~{<i!~"!!!!!>!}!!!>!>,<a~"!>},<,!!!!i~{>},<<!!!><!!!>'!!!>},<e!>e,!<~{!>,<!a>},~{<!a'i!>,<!'!!!>!>},<<i~">,<~{o!uu!>},<~{>},~{~{~{~{<ii!>~"~{!>},<>},<o!>},<e!>!!!,>}},~{~{}},~{<!u!>},<<u!!a!>ae,'u!!a!!uu<>,~{}}}},~{~{~{~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!>a!o!>i>,~{}}},~{~{<aou>}}},~{~{<<!aii'}<>},~{<,u!!!>!!!>,<u>}}},~{~{<!>},<a>,~{}}},~{}},~{~{<ieao!>},<~{e,i!!!>}!>,<}i>},<!!!>,<!!!>,o>}}}},~{}}}}}".
DEFINE VARIABLE iChar AS INTEGER NO-UNDO.
DEFINE VARIABLE cChar AS CHARACTER NO-UNDO.
DEFINE VARIABLE iGroup AS INTEGER NO-UNDO.
DEFINE VARIABLE iGarbage AS INTEGER NO-UNDO.
DEFINE VARIABLE iScore AS INTEGER NO-UNDO.
DEFINE VARIABLE cScores AS CHARACTER NO-UNDO.
DO iChar = 1 TO LENGTH(cInput):
cChar = SUBSTRING(cInput,iChar,1).
CASE cChar:
WHEN "!" THEN iChar = iChar + 1. /* skip next */
WHEN "~{" THEN DO:
IF iGarbage = 0 THEN DO:
iGroup = iGroup + 1.
iScore = iScore + iGroup.
END.
END.
WHEN "}" THEN DO:
IF iGarbage = 0 THEN
iGroup = iGroup - 1.
END.
WHEN "<" THEN DO:
IF iGarbage = 0 THEN
iGarbage = iGarbage + 1.
END.
WHEN ">" THEN DO:
iGarbage = iGarbage - 1.
END.
WHEN "," THEN .
OTHERWISE IF iGarbage = 0 THEN
MESSAGE "illegal character:" cChar
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END CASE.
/* MESSAGE cchar skip iGroup iGarbage iScore cScores
VIEW-AS ALERT-BOX INFO BUTTONS OK.*/
END.
MESSAGE iScore SKIP iGroup iGarbage
VIEW-AS ALERT-BOX INFO BUTTONS OK.