This commit is contained in:
Stefan Bühler 2020-12-19 17:00:58 +01:00
parent 2f8493d9a3
commit 9eaf76344d
2 changed files with 737 additions and 0 deletions

534
data/day19/input Normal file
View File

@ -0,0 +1,534 @@
21: 71 69
100: 92 69 | 13 54
116: 34 13 | 41 92
101: 92 93 | 13 96
122: 13 22 | 92 19
124: 70 13 | 76 92
29: 9 92 | 133 13
2: 13 75 | 92 73
117: 132 92 | 109 13
0: 8 11
43: 92 13 | 13 13
56: 41 13 | 34 92
54: 92 92
16: 92 128 | 13 106
39: 13 82 | 92 72
121: 99 13 | 70 92
110: 59 13 | 123 92
4: 63 13 | 33 92
120: 130 92 | 54 13
7: 41 71
119: 76 13 | 68 92
63: 13 99 | 92 76
44: 92 13 | 92 92
3: 57 92 | 117 13
30: 13 68
127: 91 13 | 1 92
49: 13 98 | 92 5
5: 41 13 | 112 92
74: 92 17 | 13 25
58: 13 34 | 92 68
128: 43 13
92: "a"
77: 13 37 | 92 128
112: 13 92
130: 92 92 | 13 13
46: 92 83 | 13 122
31: 13 3 | 92 26
85: 69 92 | 60 13
111: 13 41 | 92 70
76: 92 13
24: 76 13 | 70 92
93: 92 84 | 13 50
78: 92 21 | 13 135
57: 66 92 | 40 13
84: 13 45 | 92 41
109: 48 92 | 78 13
17: 92 60 | 13 43
103: 115 13 | 56 92
99: 13 92 | 71 13
65: 13 95 | 92 120
79: 121 92 | 128 13
134: 34 13 | 76 92
68: 13 92 | 92 13
14: 60 13 | 76 92
83: 4 92 | 27 13
70: 13 92 | 92 71
62: 92 79 | 13 90
66: 2 92 | 108 13
52: 54 92 | 130 13
47: 13 38 | 92 52
108: 119 13 | 134 92
33: 13 130 | 92 45
9: 13 43 | 92 69
64: 24 13 | 86 92
118: 71 70
6: 112 13 | 130 92
72: 71 43
69: 13 13 | 92 71
97: 89 92 | 62 13
135: 36 92 | 99 13
82: 13 70 | 92 54
61: 77 92 | 28 13
90: 92 125 | 13 100
129: 13 45 | 92 54
86: 130 92 | 41 13
106: 92 99 | 13 54
38: 92 99 | 13 69
126: 92 74 | 13 105
45: 13 92 | 13 13
10: 61 13 | 94 92
28: 30 13 | 35 92
71: 13 | 92
27: 118 92 | 9 13
1: 88 92 | 126 13
11: 42 31
105: 13 21 | 92 102
41: 92 92 | 13 92
34: 13 13
125: 60 13 | 112 92
55: 13 41 | 92 43
20: 13 45 | 92 60
113: 43 92
96: 13 111 | 92 113
104: 92 99 | 13 130
87: 54 92 | 112 13
132: 103 92 | 110 13
12: 124 13 | 20 92
133: 13 45 | 92 76
50: 54 13 | 76 92
26: 46 13 | 97 92
42: 13 127 | 92 67
131: 119 92 | 121 13
73: 92 36 | 13 76
19: 55 13 | 129 92
8: 42
75: 60 13 | 130 92
102: 13 68 | 92 99
13: "b"
22: 92 6 | 13 85
80: 13 54 | 92 70
107: 14 92 | 80 13
48: 92 58 | 13 21
23: 92 116 | 13 113
98: 70 92 | 69 13
37: 54 13 | 41 92
59: 13 76 | 92 45
35: 71 99
40: 92 15 | 13 23
81: 13 51 | 92 114
89: 92 49 | 13 32
94: 92 64 | 13 107
36: 71 71
18: 92 65 | 13 53
53: 92 7 | 13 100
15: 119 92 | 87 13
60: 13 71 | 92 92
115: 60 92 | 41 13
91: 92 18 | 13 101
123: 76 13 | 44 92
51: 47 92 | 29 13
114: 13 16 | 92 12
25: 60 13 | 99 92
88: 13 131 | 92 39
95: 92 45 | 13 68
67: 81 92 | 10 13
32: 50 13 | 104 92
bbabbaaaabbaabbbaabbabaabbaabbaababaabab
abaababbbaaaaaabbabbabaabbabbaaaabaababbababbbab
baaabbbaabbabaabbbbbbbaa
bbaaaabababbbaaabbbabaab
ababbababbabbababaaababaabbbbaaaabbaabba
bbaabbabbbbbabbabaaabbbaabbabbab
bbabbaaaabbbabbaabbbabbabbabbbaa
abbbaaababbaaaaababaabaaaabababbabbaabab
abaabbabbbabaaaabaabaaba
aabaaabbaaaaabaabbabbbba
aabbbaaaaabbbbabbaabbbaabaabbbbbbbbababbbbbbaabbbbbaabaaabbbabbabbabaaaababaaaaabbbabbbabbaabbaa
abbaabaaabbaaabbaaaaaaabbbabababbbaabababbbaababaababbabbaabbaaaaaaaabbb
bbbbababbabbaabbbabaaabbaaaabbab
baaabababaabbbaabaabbaab
abbabbbbbbbbbbbaabaaabaaabbbbbababbabaaaabbbaaabbaaabaab
bbabababbaaabbbaaabaabbababbaabaaabbababbbbbbaaa
aaabbbaaaaaaababaabbaabb
ababbababaaabbabbbaaababbaaaaaaa
aaaaababbbabbaabbabaaabaabbababaaabbaaaa
aabaabbababababaabbabbab
babbbbbaaabbaaababbabbab
abaaaabbbabaaaabababaabb
babbbaaaabaaababaabababb
abaaaabbbaaaabaaaabaaaab
aabbaaabbaabbbaaabbbaaba
babbbaabababbbbbaabbbabbaaababbbbaabababaabaabaaabaaaaab
ababbabbbaaabaaaaababbabababbbaababaaaabababababbbbabababaaabaaaaabbbbaa
babaaabbbbaaabbabbbababa
bbbaababbbababaabbabbabb
babbabbbaaaabaaabaabaaaa
abaaaaaaaabbbabbbabbaabaaaaabbbb
bbaabaaaabaabaaaaabaaaabaabbbbbbbaaaabaaabbbaabababbbbbabaabaabbbbbababaabaababa
bbabaabbbababababbabbaabbbbababbaabbbbba
aaaabaabbaababbabbabbbaa
bbbbaabbbabaaaaaabbaaaba
aaaabbaaaabaabbbabbabbaabbbabaaa
abbbabaabbaababaaababaabbabbabab
bbbabbaabbbabbbabbababbabaaaababaababaaabbaabbaa
baabbbababbabbaaabaaababaabbbbba
bbbaabbabaabbbaabbaabbab
aaabbabbbbaabbabaabababa
aaaabaaaaabbbaaaabbaabbbabbabaaabbbabbbb
abbbabbbbbababbaababbaab
aababbbbbbabbbbbbaabbabaaabbbababbbbbaba
aabaabbbbaaababaabababaa
baaaaabaabbabbaaabbbbaaa
aaabbbabbbabbaaaabbbabab
bbababaabbaaabbbaaaaabaababaabaabaaabaab
abaabaababaababbbabbaababbaabbbbaabaabaa
abaaaabbbbabababaabbaaaa
babaabaaaaaabbaabbbbabbbabbabbbaaaabbabaaaabbbbbbabababaababbbbbbaaaaaab
abaabbababababbbbbaaabbaaabaaaaa
abbbaaabbbabaabbbababbaaaaaaaaba
abbabaabbbabababbbbbaabaaabbaabbaabaaabbaaabbbbaaaaabbabaaaaabaa
babbaaabbbbbbbbaababbaab
ababbabaababbaaabbabaaba
abababababababbbabaabbaa
abaabababbbbbbbaabbbbaaa
bbbbababbbaabbbbbababbab
bbaabbabababababbbaaaaba
aabaabbabbabbbaaabaaababbaaaaabaaabbbabbbaaabbabbaabbaba
baaabbaaaaababbabbbbabababaababaabbaaabbbbbbaaaabbababbb
baababbbbbbaaaabbbbbbbaaaaaababaabbaaabaaaabaabababaaaaa
bbabababaaabababaabbaabaabaaaabbababbbbaabaaaaab
abbabbbababaababaaaaabbbaabaaabb
babababbabbbbaabbbaaababaabbbaab
baabbbaaaaaabaaabbbaabbaaaabbabbaaaabbbbbaabbaaabbaaaabbbabaababbabbbbabaababbab
bbaaabaaaaabbbaababbaaabbabaaabbabbabbba
abaaababbabbabaaabababbbababaaaaabbaaaaa
abaababaaabbaaababaabbabaabbbbbb
abaababbbbbababbbbbaabbaaabbbaaaaabbbabb
aaabbbaabbaabababbabbbbb
abaaababbabbbaaababbbbbb
baaaabaaabbbabaabbaaabbb
babbaabbabaaaaaabbbbaabbaaaaaaabbbbbabbabbbbabaa
babaabbbaaaaaabbbaaaabbaaaabaaaababbaabbabbaababbbbaaabb
babaaabbabbbbababaaaaabababbabbabaaaaaababaabbbb
abaaaabababbaabbaabbabaaaaaabaabbbabbbbbabbbaaabbaaaabba
baabbbbaabbbbababbbbabaa
bbaaaaabbbbbbbbababaabbabbbbaaaaabbaaaab
abbbabbbbabababbaaabababaabababbbaaaaabaaaabbaaaabbabaaabbaabbba
baaaaabaaaababbbaaaaababbaaabaababaaabba
aaaabaabbbaabbababbababbabaaabbbbbaabbabaaabaaab
abbabaababaaaababbbbbbaabbaaaaaaaaaaaabb
aaaabbaababbabbabbaaabbb
baabababbabaabbaaabbabbbbbbbababbaababbaabbaabbbabaaabba
baaaabaabaabbabaabbbbbbbaaaababbaaabbaab
aabbbbbbabbbbaaaaabbbbbbbbbbabbb
baaabbaabbabababaaaabaabbbbaabbabaaaaaaaaabbbbababbbbbabaabbaaaaabaaabba
abaaababbabbbaaabaaaabaabbaaaabbaabaabaa
babbbabababaaaaaababbbab
baababbbbbaaabaabaabbbaaabbaabbaabbbabab
abaabbababbbbbbabbababaabbbbbbbaaaabaabbbaaaabbb
aaaaaaababaabbaaaabaaaaabbbabbbb
abbbabaabaabbbaabaabbaab
abbabbaaabbbbbbaaaabbaabbabbbaaababaabba
baaabababababaabaabbbabbabaabbabbabaaabbbabbabbbbbababbb
aaaaaaabaaababbababaaaba
bbaababababaaaabbbbbaaaa
bbbbaabbbbbbaabbbbbabaab
abaaaabaabbabaaaababababbbabbbbbbabbabab
babbaabbabbabbaaabbabbbbaabbbabbaabaaaaaaababbbb
babaaaabaaaabaaababbabaabbbbbbaababbaaaa
abbaabaaaaabbaaabbaaabbb
bbbabbabaaababbaabaabbbaaaaaabaa
bbaaabbababaabbbaaabababbabbaababbbbaabaabaabbaaaabaaabbbabaabbabaaabbababbaababbaabbaaa
bbbaaabababbabababaaaabaaabbabbbbaaabbabaaaabbbaabbababbbaaaabababaabaaabbbababb
babbbaaabbbbabababbbbabb
baaaaabbaabbaabaabbaabba
babbbaabbababaabaaaabaaaaaaabababbbaabbbababbabbbbabaabababbbabbaababaaa
baabbbbaaabaababababbaaa
abbbabbbaaabbaaababbabab
bbabbaabbbaabaabbbbaaabaabaaababbbabbaabbbabaaaaabbabaaabbababbbaababbaa
babaaabbbabaaabbbbabbaabbbbabaab
abbbbbaabaaaaabababaabbabaabbbaaabbbaaabbbbabababbabbbbbbaababbbaababbab
aaababbbbbaabbbaabbbabbaaaaaaaabbbaaaaaabbaaabbbbbbbbabb
ababbabaababbabbbaaabbbababbabbabbbbaaabbaabbaab
ababbabaaabaababbbabbabaaabbaaaabaaaabab
aabbaaaabaabbbbbaaabaaba
babbbbbaaaababbbbbaaaabbbbbbbababaabbbab
abbbbbbabababaabbabbbaabbbaabbaa
bbaaabaabbbaababbaaabbbb
aabbabaaaaabbbaaabababaa
aabbaaababbbbaabbaabaaab
bbbbbbabaaaabbbabbbbababaabbbaab
babbaabbbbbbbbbabbaaaaababbabbabaaaaabaa
bbbaaabaaaaabaabbaaaaaaabaabaaba
baabbabbbbaabbababbaaabbaaaababa
ababaaaaababbaababbbbbaabbbaaaaaaabaaaababbaaaab
abbaaabbbbaabbababbbabbaaabaabaaaaaababb
ababbaaabbaaaabbabbaaaaabbaabaabbbaaaaba
ababbbbbabaaaabaabaaaaab
babababbababbbaabbabbaab
baaaabaababbbbbaabbbabbaaaabababaaabbaaaaaaaabbbbabbababbbbaabbbabbaaaab
bbbbababaaaaaaabbaaabbabaabbabbaaaabbbbaabbbaaba
baaaaabaabaaababaaaaabbaaaabbaaaabbbaabb
bbbbabbabbabbbaabaabbbaaabaabaabbabbbabb
bbaaabaaaabaabbaaaaababb
abbababaaababaabbabbbbaa
aabaabbaaaaaababbabbaaabaaabaaba
abbbbaabbbbabbabaaaaaaaaaabbabbabbaabaaaaabbbbbaaaaaaabb
bbaaabbababbaaabbbaaabaaabbaaaaa
aabaaabbabbbaababababbaa
bbbbaababbabaaaaababbbba
abbbbaabbaaaaabbabbabaabbbbbaabbbbaabbabaabaaaaa
aaaabbbabaababbaabbbbbab
babababbaabbaaaaaabbbbaa
babbaaabaaabbabbabaabaababbaaaaabaabbbbb
bbaabbbaabaababbbbbaaabb
baaababaaabbaabaaabbaabb
baaaaabaabbbabbabbbaabbb
abaababbbbaabbbbabbbabaabbbaabbaababbbba
babababbabaaaaaaaababbbaabbaabbbaabababbaaaabbab
aababaabbabbaaabaaaababababaabbb
aaaaabbaaabbaaabbbaaaababbbbabbbabbabbbbaabababababaaababbaaabab
aaabbbabbbbbaaaaaabababb
bbbbbbaaaaabbabbabbbbbabbaaabaababbbaaabbbbbbabaabbbaaaa
ababbbbbbaaaaabaaaaabbaabaabbbbaababababbbbabaab
bbaaabaaababbabababaabbaaabbaaabaaabaaab
baaaabaaababababaababbaaaaaaabababaabbbabbaabaabbbbabbabbaaabbab
babbabbabaabababaaaaaabb
aaaabababbabbaaabbbbaabababaaaabbbaabababbabbbbb
baabbbabbbaaabaaabbbababaabbababbabaaabbbabaabaabaaababaabbabaaaaabbbaba
baaaaabbbabbbabaaaaaabaa
bbaabababbabbaaabbbaaababaaaabab
babbaaabbaaaaaabaabababa
bbabbabbbbbabababaaaabba
bbabbbaaababababaabaabbbaaababbbbabbbbaa
baaabbaaabbaaabbbaaaabba
abbbbbaababbbbbaabaaabba
aaabbbabbaabbbbabbaaaaaa
aaaababaabbbabaaabbabababaabaaabaaabbaba
bbbaabbaabaabababaaabbaaababbabb
bbbabbabbbaaaaabbaaaaaabbbababba
baabbaababbaaabbabbaaaabaabbaabbbaabbaaaabbbaaaa
abbabbbbaabaaaabaaaabaaabaaaababababbaaababbbaaaabbabbbbaabbbaaaaaaabaaaabbababbbaaabababbabbbba
bbaaabbabbaaabaababaabab
bbababaabababaabaaaaabaa
bbbaabaaabbaabaaaaaaaabb
abbabbaabaabbbaabbbaabbb
aabbbabbbabbbaabaabbaaabaaaababbaabbbbbb
abbbaaaaabaababbabbbbabb
bbbaaabaabbabaabaaabababbbbabbbaaaabbabbaababaabaaabaabb
bbbaabbabaaabbabbbaaaaaa
baabbbaaababaaabbbabbabaabaabababbbbaaaa
bbbbbbababbbabaaabababbbaaaababbabbbaaabaababbbbaabbbababbaaabbb
bbbabbabbaababbbbbabbbaaabbababbbabaaaba
aaababbabbbbababababbbba
bbbbbbabababbbaabbbbaabababaaaababbbaaaabaabbababbbbbbab
abaaababbaaababababbbabb
abbabbbaabbbbabbbaabbbababaaabbaababbbababaabbaabaaaaaab
abbabbbbaaaabaaaaabbbaba
bbbaaababbabaabbabaababbaabbaabb
aaababababbabbaabaabbaaa
babbabaaabbbbababababbaabbabbbbb
bbbabbaabbbabbbabaaabbaaaabbabbabbbabaaa
babbabaabaaaaaabbbbbbbbababaabaa
bbaabbbabaabbbbaababbbbbbbaababaabbaaaabaaabaaab
aababbbbbabbababbbababaabaaabbaa
aabbabbbbaabbbababaaabbb
aaababbbaabaababbbabbabaababaaba
abaaaaaaaaaababababbaaabbaaaaaababaaabababbababbbbabbaababbbbabbbbabbbab
abaaaabbbbbbbaabbbabbbaaabbbaabb
bbabaabbaaaabbbaabbbabbbabaaaaaabbaabbbbaabbaabbbbbaabbbbbabbbab
aabbabaabaababbababbbbbaabbaaabbbbbababbbbbababaabbbbabb
bbabaaaabbaaabbaabbbabab
babaaaabbaababbbbbaabbbabbbbbbbaaaaabababbabbaab
abaabbbaabaabababaababbababbbbaa
ababbbbbbbaababaaabbabbbababbbbaabaabbbb
aababbbaaabbaaabaabaaaaa
babbaaaaabbbbababbbaabaabaabbaaa
aabbbaaaabbaabbbbaababbababababaabababaabbbbaaaa
abaababaababbbaaaababaabbabababbababababaababaaabababbbb
aaaabbbaabaabaaaababbaabbbbbbbbb
baaabbabaabbabbbbaababbabaaaaaababbabbbb
babbaaaababaaaabaabaabbabbbaaabbaabbaabb
abbbaabbbaabbbbbbaaabaabaabbababbbbababa
aabbaaababbaabaabbabbaaababbaaabbabaaaaaaabbbbbbbabbbbbbabbabbba
abbbaababbababababbabbbabbababaaabbaaaaaaaabbbbb
aababbbaaaaabaababbaabba
abbbbababbbbbbbaabaabbabaaaabababaaaabbbaabaaabb
bbbaabbabbaaaaabbbabbbba
abbbaaaaaabbabbbaaabaaba
abababbbaabbaabababaabbabaaaabbb
abbaaaabbaababbbbaaaaababbabbababbbbababbbabaaababaaaabbabbbaabbabbbbababbaaabaaaabbaabbbbaaabaa
abaaaabaabababababbaaaaa
aabbaaaaaabaaabaaabaaaaa
babbbaaaaaaabbbaabaaaabbbababababaaababbbbbbbaba
abaaaabbaaaaabaabbabbbabbaabbbbabbabbabaaabaabbababbabbabbaaabbaabbbbbaabbbbaaab
bbaabababaabababababbabb
abbbbaabbababababbbbbbbb
aabbaabaaababaababababaabbbaabbabbbababaabaaabbbabaabaaaaabbbbaabaaabbaaabababbb
ababbbbbbbabbababbbbaababbbabbaaaabbabbaaababbaabbabaaba
abbaaaabababaabbbabbbbbbbbbaababbbbaabbbabbbaabababaaaabbaababaaabbabaab
bbbaaaaabbaaabababababaa
babaaabbabbbbbaabbbabbbababaabab
bbbbbbabbbbbbbbababbbababaaaaababbbbbaabaaaaabbbbaabaaaaaaaaaabb
baabbbbaaabbabbbbbabbbaaaabaaabb
aabaababbabbbabaaaabbabbbaabaaaa
aabbaababbbaaabaaaabbaab
babaaaaaaaabbbabbabbaaaaaaaaabbabbbaababbaaabbab
bbabbbbababbbbaaabbbbbabbbabaaaabbbaaababababababaabbbbbbbbaabbaabbbaaaa
bbababbabbbaabababbbbaabbbababbb
ababbbbbabbbabbbabaabbbb
bababaabbbababaabbaaabbaaabbabbabbaaaabb
abbaaaabbbabaaaaabbbaabbaabbaabbabaaaabaaababbbabaaaaababaabaabbaabbabbbabbbabba
baababbabbbbbaabbbbaaabb
bbbabbaaabbabaabaababaaa
baaaaabababbabaaaaabbbabbaababbabbbaabaaabbbbaabbbbabaab
aabbbbbabaaabaabaaabaaaa
abbbabbbaaaaaaababbbaaba
abbbabbaabbbbbbabbabbabb
bbbaaababbaabababababaababaaaabbabbabbbabbabbabbababbaaa
aaaaaaabaabbabaaaabaabaa
babbaabababbaaaaabbaabbbbabbabaaabbbbaabbbbbbaba
bbabbaaabaabbbababbaaabbbaaaaabaababbababbabbaaababaabbbabbbbbabaababbbb
babbbaabaabbabaaaabaabbaabaabbaa
bbababbabababaabaabaabbbaabbabaaaababbaaabbabbba
aaaaabbababaaaaabaaaaabaabaabaababaaaabbbaaabaaa
babaabaabbbbabaabbabaaabaabaaaab
bbbbbbabbaaabbbabbbababa
bbabbaaababbabaaaaabbbba
bbaaabaaaaaabaabaaabaaab
bbaabbabbaababaaabaabaabbbbbbaabbabbbabb
ababaaabbaabbbbabbbbababababbbbbbababaabbababbaaabbaaaba
bbaabbbaaabaaabbbbaaaabb
babbabbbabbbbbbababbbabbabaaabbbbbbaababbbbaabbbaabbaabaaaaaaaaababaaaaa
babaaabbaabbaabaababaaababbabbaaabbababaabbabbabbbbabaabbbbbbaaa
bbbbaaabaababbbaabbaababbbbbabaa
baaabbbaaaaabbbabbbbbaba
aababaababbbbabaaabaabbbbbbaababbabaaaabbbbbbaabaaababaa
bbbbabbaabbbaaaabbabababbbabaabbbbbbababbbbaaabbbbbaaabb
bbbaaaaabbabbabbbbabbabaaabbbaab
baabbbbabbbbbbbaabbabababbbababbababbabb
aabbabbbbbbabbabbaaaabbaaabbbbbbbabbababbbbbbabb
abbbabaaabaaaabaaaaabbab
aabaabbaabaababbaaaaaaababaabaababbaaaba
bbabbabababbabbbbabaabbb
bbaaaaabaabbbaaababbabbababbbbbbbbbabaaa
aabbaaababbbbabaaabbbbbb
aabbaabaaaaabbbbbaaabaaaabbbbbab
aaaabbaaaabbaababaaaaabbbaababbbbbbbbbbb
abaaababbababababaababbababaabbb
aaababbabbbaaabaababbaaa
abbbabbaabbbabaababbbabababbabbababbaabbaabaaababbbaaaabbabaabaabbaabaababbabbba
babbbbababbaaabaabbbbabbbbabaaba
aaaaabaaababaaaabababbbaababaaaaababbbbbbabbbabbbabbbbbb
abbaabbbbbbbaabbaaaabbbaabababaa
babbbbbaabbabababbaabbbbaabbaabb
bbbabbbabbbbaabbabbbaaab
babbbaaabbbabaabbbbaaabb
bbbbbbbaaaaaaaababbabbba
bbbbbbabaaabababbabbbbbabbaabbaabbbabaaa
bbaabbababbaaabbaabaababbaaaababaaabaabb
aaabbbaababbaabbabaaababbbbbbaabbababaaabbbaabbb
bbbabbbabbbaaaaabbaabbbbbabbbaabbabaaaba
abababbbaababbbabaababababbbaabb
bbbbbaabbabbaababbbababa
aaaabbbabbbaaaaaaabaaaba
aaaaaaaabbaabbabaaaabbbaababbaab
aaababbabbbbaabaabaabbbb
abaaabbbbabbbaabababbabababaaaababaaaaababbbababbbbbaabababaababaababbba
baaaabbbbbaabaaababbabab
aabaabbbbbaabbbabaaabbbbbababbabbaabbabaabaaabababbabaaabbabbaaa
baaabaabbabbbbaabbabaaabaabbbbbb
ababbbbbbaabbabbabaababaabbbbbab
baababbbbbbaaaaabbabbabb
babababbaaabbbabaaabababbbbababa
baabbaaaabbabaabbabaabaaaaabbabaababaabbabbababaababaaaabbbabbbb
aabaababaaabaabbbbbabbbbbabaabbb
aaaaabbabbababaaababbabaaabaaabbbabbbbbb
baabbababbbabbbaaabaaabaaaaaabbabaabaabaabaaaaaaabaabaaabbbbabbababaaaaa
babbabbabbbaabaaaaaaaaabaabbaaaa
baababaababbaaababaaabababaababbbbbababa
abbaabaaaabbbaaabbaaaaabbbaaaaabaabbaababbbababb
baabbbabaaaabbbaabbbbbaa
aaabbbabbaabbbbaababbaaa
abbabbbaabbbbabaaabaabbbbaabaabbaabababbbbaabbba
baabbaaabbbabbabbaaabbbbaaaaaabaaaaabbbabaaaaabbaabbabbaaabbbbbaaaabaaaa
baabbbaabbbaaaababbabbbbaaababbabbbbabbbaaaaaabbaaababbaaaaababa
baaabbabaabbabaabbbbbabb
ababbbbbabbbabaabbaaaabb
aaabbaababaababbabbbababbaababbababbbaaabaabbaaabbabbabbbabababa
aaaaaaabaabbabaaababbabaababaabb
baababaabbabbaaababbbaabaabbbabbaaaaabababaababaababaaaa
abaabaabaabbbabbaaaaaabb
bbaabbbbbabaaaabbbbbbbabaabbbaba
baabbbaabbaaaaabbbbabbbbbbaaabbbaabbbbaaaababaaabaababaa
bababababbaaabbabbbbbbbaabbbaaaaababbaaa
abbbbbaabbababbaabababab
bbaaababbaababaabbbabbabbbbabbababbaaabbabaaabba
abbbabbabbaaabbababaaaba
abaabbabababbbbbabbabbaabbbabbbb
aaaabaaaabaabbabbbabbabb
bbbbbbababbaabaaaabbaaaa
babbaaababbbaaabaabbbbbbaabbabaaabbbababbbabbababbbaabaaaaabbaabbbbbbbaa
babaaaabbabaabbaaaaabaaaababbabb
abbbbaabaaabbbabbbaabbbbbbaababaaaaababbaabbaabb
bbbabaaabbbbbbabaabaabbabbbbbabababababaabbabbbaabaaabaaaaababbbabbababaabbbbbaa
baaaabaababbbaababbbbbaaaaaababaaababbbb
bababbaabaaaaaaabbbbbbbbbbbbbbbbabbbbaaa
bbbbaaabaabbabbbbabbaabbaaabbbabbbbaaaaaabbaaaab
abbabababaababababaaaaaabbbbbbaaabbbbbbaaaaabbbbabbaaaabaaaabbabababaaba
baabbbaaabaabbaaabbabbababbaaaaaabababba
abaaabaabbabbbaabbbababbaaabaaba
baabbbbabaababababbaaaab
abbabababbaaabbabbbbaabbaabababa
abbabbbbabbbabaaabbbbbbb
aaabbbbaabbaabaaababbbbabbbbaabbaababbbaababbaaaababbbbbbbbbaaab
abaabababbbaababbabaaaabababababbaaababbaabababb
babbabbaabbbbababababbaaaabbbbaabbabbbbaaabbbbbababbbaaabbbbbaaabbabbabb
abbaaabbababbabaabaaaaaabbaabbbaabaabbabaababbaabaaaabbabbbababaaababbbb
aababaabaaabababbbabaaab
aabbabbabbbaababbbaabaaa
abbbabaaaababbbabaabababbabbbaaabababaaa
abbbbaabbbbaabbaaaaaabbb
aabaababbbabababbaabbbbaabbbaaaabaaabababababbabaaabaaaaabbbaababaaabbbb
aaaabbaabbababaababababaaababbbb
bbaaabaaabbaaabbbbbbbaaa
bbaabbbbbbbbaaabbabbbbbaabbbaaba
abbabaabaaabbaaaaaabbbaa
baababaabbbbbaabbaabbaba
aabaabaaabaaaabaabbbabbabbbabbbaaabaaaabaaababbb
babbbaabaaabbaaaaabaabbababababbaaaaabbbabababaabbabaaab
abababaabbaaabbbaaabbaabaabababa
abaababbbbbabbbabbabbbba
bbbbbbabbbbabbabaaabbbaaababaaaa
aabbbabbaaabbbababbabbba
baababaabaaaaababbaaabaaabbabbbbbabaabab
aaababbabaababbbbbbbababbbbbaaabbaaabbaababbabab
aaabbaaaabaababbaaaabaaababbaababaaabaaa
baabbbaababbabbabbabbbab
abbbabbaabaabababaaabbbb
aaabbaaaabaaaabaaabbbaaaaaabbbaabbbaababaaaababbbaabaabbaabbbbbb
babbabaaabbabbbbbbbbbabbaabbbbbabbaaabbabbaaaabaabbbbbabbaaaabbbbbaabbbbaabbabbaabbabaaa
aaabbaaababaabbaaaaaaabb
abaaaabbabbabaabaaaabbab
bbbbabababbbbabaabaaaaaaaaaabaaaababbabbabbaabbabbbabbbbabbababb
abbabaaaaababbbababbaaaaaaabbbaaaaaaabbb
bbbaabaababaaabbbbbbaaabababaabb
abbbabbabbbabbaaaaababbabaababbaaabaaaab
bbbabbaababaabbaaababbaa
bbbbbbbababbbbbababbaabaaabaaabbaababbaaabbbbbabbabbbabbaababbaa
baabbbaaaababaabaabbbaab
bbaaabaaaaaabbaaabaaabaaaabbbbbabbbabbbb
abbaabaabababaabbabbabaaabbababa
babbbaababbaaabbbaaababb
bbbbaababaaaabaaaaabbbbb
aabbbaaabbababaaaaaaaaabbaaaaaaa
abaababaaaababbabbbabbaabaabbabbababaaabaababaabababaaaa
ababbbaaaaabbbaaabbbabab
bbbabbaabaaabbbabaabaaaa
bbbbababbaaaabbbbababbbbbaabbbaabaaaaabb
abaaababbaababbababababbababababbbbbabbb
babaaaaaaabaaaaaabaabaaa
babbaabbbbbbababbabbbbbb
bbbaabaababababaaaaaaabb

203
src/bin/day19.rs Normal file
View File

@ -0,0 +1,203 @@
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
const INPUT: &str = include_str!("../../data/day19/input");
#[derive(Clone, Debug)]
enum Rule {
Char(char),
Chain(Vec<u32>),
}
impl Rule {
fn parse_part(alt: &str) -> Self {
let alt = alt.trim();
if let Some(alt) = alt.strip_prefix('"') {
let alt = alt.strip_suffix('"').unwrap();
assert_eq!(alt.len(), 1);
Self::Char(alt.chars().next().unwrap())
} else {
Self::Chain(alt.split_whitespace().map(|s| s.parse::<u32>().unwrap()).collect())
}
}
fn parse_line(line: &str) -> (u32, CachedRule) {
let colon = line.find(": ").unwrap();
let id = line[..colon].parse::<u32>().unwrap();
let alts = line[colon+2..].split(" | ").map(Self::parse_part).collect();
(id, CachedRule::Alternatives(alts))
}
}
fn _make_combs(target: &mut HashSet<String>, current: &mut String, list: &[Arc<HashSet<String>>]) {
if list.is_empty() {
target.insert(current.clone());
} else {
let old_len = current.len();
for s in &*list[0] {
current.push_str(s);
_make_combs(target, current, &list[1..]);
current.truncate(old_len);
}
}
}
#[derive(Clone, Debug)]
enum CachedRule {
Alternatives(Vec<Rule>),
CachedStrings(Arc<HashSet<String>>, HashSet<usize>),
}
#[derive(Clone, Debug)]
struct Grammar {
expansions: HashMap<u32, CachedRule>,
}
impl Grammar {
fn parse(rule_lines: &str) -> Self {
let expansions = rule_lines.lines().map(Rule::parse_line).collect();
Self { expansions }
}
fn _build_sets(&mut self, recursive_check: &mut HashSet<u32>, ndx: u32) -> Option<Arc<HashSet<String>>> {
let rules = self.expansions.get(&ndx).unwrap();
let alts = match rules {
CachedRule::Alternatives(alts) => alts,
CachedRule::CachedStrings(cs, _) => return Some(cs.clone()),
};
if recursive_check.contains(&ndx) {
return None;
}
recursive_check.insert(ndx);
let mut result = HashSet::<String>::new();
let mut found_recursion = false;
for rule in alts.clone() {
match rule {
Rule::Char(c) => {
result.insert(c.to_string());
},
Rule::Chain(parts) => {
let mut comb = Vec::new();
for part_ndx in parts {
// abort if nested lookup loops
if let Some(cs) = self._build_sets(recursive_check, part_ndx) {
comb.push(cs);
} else {
found_recursion = true;
}
}
if !found_recursion {
_make_combs(&mut result, &mut String::new(), &comb);
}
},
}
}
if found_recursion {
return None;
}
let lengths: HashSet<usize> = result.iter().map(|s| s.len()).collect();
let result = Arc::new(result);
recursive_check.remove(&ndx);
self.expansions.insert(ndx, CachedRule::CachedStrings(result.clone(), lengths));
Some(result)
}
fn optimize(&mut self) {
let mut recursive_check = HashSet::new();
self._build_sets(&mut recursive_check, 0);
recursive_check.insert(0);
for id in recursive_check.clone() {
if let Some(CachedRule::Alternatives(alts)) = self.expansions.get(&id) {
for alt in alts {
if let Rule::Chain(chain) = alt {
recursive_check.extend(chain);
}
}
}
}
let rule_ids: HashSet<u32> = self.expansions.keys().cloned().collect();
for id in rule_ids.difference(&recursive_check) {
self.expansions.remove(id);
}
}
fn simple_match(&self, data: &str) -> bool {
match self.expansions.get(&0) {
Some(CachedRule::CachedStrings(cs, _)) => cs.contains(data),
_ => panic!("not simple enough"),
}
}
fn _complex_match_chain<'data>(&self, chain: &[u32], data: &'data str) -> Vec<&'data str> {
if chain.is_empty() {
return vec![data];
}
self._complex_match(chain[0], data).into_iter().map(|rem| {
self._complex_match_chain(&chain[1..], rem)
}).flatten().collect()
}
fn _complex_match<'data>(&self, start: u32, data: &'data str) -> Vec<&'data str> {
let cr = self.expansions.get(&start).unwrap();
match cr {
CachedRule::Alternatives(alts) => {
alts.iter().map(|rule| {
let chain = match rule {
Rule::Chain(chain) => chain,
_ => panic!("only chains here"),
};
self._complex_match_chain(&chain, data)
}).flatten().collect()
},
CachedRule::CachedStrings(cs, lens) => {
lens.iter().filter_map(|&len| {
if data.len() >= len && cs.contains(&data[..len]) {
Some(&data[len..])
} else {
None
}
}).collect()
},
}
}
fn complex_match(&self, data: &str) -> bool {
self._complex_match(0, data).into_iter().any(str::is_empty)
}
}
fn main() {
let input_grammar;
let data;
{
let split_pos = INPUT.find("\n\n").unwrap();
input_grammar = Grammar::parse(&INPUT[..split_pos]);
data = INPUT[split_pos+2..].lines().map(str::to_string).collect::<Vec<String>>();
}
{
let mut grammar = input_grammar.clone();
grammar.optimize();
println!("Lines matching simple grammar: {}", data.iter().filter(|line| grammar.simple_match(line)).count());
}
{
let mut grammar = input_grammar.clone();
grammar.expansions.extend(vec![
Rule::parse_line("8: 42 | 42 8"),
Rule::parse_line("11: 42 31 | 42 11 31"),
]);
grammar.optimize();
/*
println!("{:?}", grammar.expansions.keys());
for (rule_id, rule) in grammar.expansions {
match rule {
CachedRule::Alternatives(alt) => println!("{} -> {:?}", rule_id, alt),
CachedRule::CachedStrings(_, lens) => println!("{} -> string with lengths: {:?}", rule_id, lens),
}
}
*/
println!("Lines matching complex grammar: {}", data.iter().filter(|line| grammar.complex_match(line)).count());
}
}