2020 Day 19 & 20 Complete

This commit is contained in:
Brian Buller 2020-12-20 15:57:10 -06:00
parent 069d03004d
commit e9e89e0a42
8 changed files with 2661 additions and 244 deletions

600
2020/day19/input Normal file
View File

@ -0,0 +1,600 @@
126: 116 104 | 107 95
28: 104 | 95
25: 116 95 | 33 104
17: 98 104 | 14 95
69: 120 104 | 86 95
78: 49 95 | 57 104
124: 95 36 | 104 74
61: 104 39 | 95 30
27: 99 95 | 41 104
114: 50 104 | 102 95
76: 83 95 | 116 104
22: 95 133 | 104 53
9: 104 71 | 95 63
72: 65 104 | 90 95
125: 77 95 | 60 104
130: 104 44 | 95 69
106: 33 95
77: 104 20 | 95 101
118: 95 104
99: 95 32 | 104 54
15: 95 116 | 104 116
92: 104 132 | 95 23
120: 66 95 | 37 104
94: 53 104 | 16 95
3: 104 107 | 95 10
40: 95 36 | 104 38
54: 95 104 | 104 95
21: 97 104 | 16 95
12: 104 54 | 95 49
109: 104 16 | 95 33
26: 76 95 | 106 104
105: 49 104 | 133 95
84: 104 131 | 95 72
34: 104 91 | 95 112
23: 126 104 | 15 95
86: 104 81 | 95 113
67: 104 107 | 95 49
20: 95 53 | 104 16
46: 97 95 | 107 104
47: 95 33 | 104 53
134: 104 10 | 95 32
58: 95 32 | 104 116
70: 2 95 | 40 104
60: 95 96 | 104 19
75: 129 104 | 122 95
102: 124 104 | 26 95
123: 104 53 | 95 118
49: 104 95 | 28 104
41: 104 43 | 95 16
43: 95 104 | 104 104
50: 95 119 | 104 64
31: 95 7 | 104 130
29: 62 95 | 79 104
103: 55 95 | 56 104
2: 22 95 | 123 104
91: 85 104 | 13 95
93: 95 30 | 104 134
6: 104 33 | 95 57
96: 53 104 | 97 95
4: 95 27 | 104 75
101: 49 104 | 118 95
90: 56 104 | 100 95
85: 10 28
18: 95 32
81: 104 35 | 95 110
11: 42 31
80: 95 108 | 104 110
10: 104 28 | 95 95
95: "b"
16: 95 95 | 104 104
115: 95 114 | 104 17
0: 8 11
33: 104 104
14: 104 9 | 95 93
30: 104 43
133: 28 28
53: 104 95 | 104 104
63: 116 95 | 116 104
68: 74 95 | 25 104
1: 95 32 | 104 118
110: 95 33 | 104 107
111: 87 95 | 80 104
5: 32 95 | 97 104
79: 45 104 | 4 95
88: 95 54 | 104 118
122: 53 104 | 33 95
32: 104 104 | 95 28
42: 29 104 | 115 95
129: 95 16 | 104 32
7: 84 104 | 24 95
112: 128 104 | 78 95
119: 127 104 | 88 95
82: 33 104 | 32 95
45: 59 104 | 89 95
37: 104 3 | 95 117
100: 16 95 | 54 104
59: 95 82 | 104 18
98: 68 95 | 61 104
132: 104 129 | 95 6
83: 95 28 | 104 95
44: 104 125 | 95 70
62: 104 73 | 95 111
107: 95 95 | 95 104
38: 10 95 | 43 104
8: 42
36: 32 104 | 54 95
39: 95 54
117: 116 104 | 10 95
52: 21 95 | 58 104
56: 97 104 | 49 95
24: 95 34 | 104 92
57: 95 95
87: 104 12 | 95 121
127: 83 104 | 107 95
108: 104 33 | 95 16
97: 104 95 | 95 95
113: 104 129 | 95 105
19: 33 95 | 33 104
73: 95 48 | 104 103
13: 54 104 | 49 95
116: 104 95
64: 46 104 | 13 95
55: 16 95 | 33 104
71: 83 95 | 43 104
65: 47 104 | 110 95
35: 104 118 | 95 53
51: 104 94 | 95 1
128: 95 57 | 104 116
121: 95 54 | 104 16
66: 5 95 | 55 104
131: 51 95 | 52 104
74: 133 28
89: 95 5 | 104 82
104: "a"
48: 67 104 | 109 95
babbaabbbabaaabbababaaaa
babbbbbbaabbbbababaaaaba
aababbabbbaaabaabaaaabba
aaabbabaaaaabbbbabbaaaab
abaaabbbaaaabaaabaababababbabbababbababaaaaaaaba
aaabbaaaaaabbbaaaaababbbbabbbabbbaaaababbbaaababbbbbabbb
baababbbbbbabbabbbabbbaa
aaabaabbbbbbababbabbbbaa
bbbbabbaabaaaaaaabaabaaa
bbbabbbaaaabaabbbbabaaba
baabbabbaabaabaaaaabbaaababaaaabbbbbbbbbabbaaaab
aababbabbbabbbbabbbabbabbbaabbab
baabbababbbaaabbbbbbbaba
abbabbababbaabbaaaabbbabaabbbbaaabbbbabb
aababbababaaaaabbbbbbabb
bbbabaaaaaaabbababaaaaba
aaabbabaabbbaaaaababbbaa
bbbbbaaabababbabbbbaaaaa
aaabbbaaabbaabbaabbbbaaabaaabababbababbb
aabbabaabaabbbababbaabba
aabbabaabbbbbbaaabbbabbb
abbababbbaabbaaaabbaaabbbabbbabbbbbaabbbabbabbba
bbbbabaaabaabbbbbabbbbaa
baababbabbbbaaababaababb
bbbabbaaaababbabbbaababb
babbaaabbbbababbaaabbabb
bbbbaaaabbbbbbbbbbbaabba
aababbaabbbabaaabbbbabbabbbaaabababbaaaaaabaaaab
bbabaaabbabbabbbababbaaabaaaaabaabaaaaabbbbaaababbbaaaabbabaaaab
abaaaaaaabaaaaabbbaaabaaababaabaabababba
abbbbbabaaaaaabbabbbbbaa
aaaabbbbbbbbabaabbababbb
baabaaaababaaabaabbaabbb
baaaaabbbbababababababbb
aababbababbbaababbbabaaabbbabaabaaababaa
baabbabbbbbaaabbabbabbba
baaabbababbaaabbbbaaaababaaaabaababbbabababababaaabbbaab
baaababbbaababbabbabbaaaaabbaababbabbbaaabbbbbbb
abbabbabaaaaaabbaabaabaababaaabbbbbaaaabaaaababb
baabbbaabbaaaababababbbbaabbaaab
bbbaaaabbababbabaabbbabaaabbabbabaabaaab
baabababbabaabaabbbaaabbababbaaaaabbaaab
aabbababaaabbbabaabbabaabbabbaab
abbabababbabbbbbaabaabba
abbbaababaabbabbabbbabaaabaaabab
bbbbbbaaabaaabbbaabbbaaa
bbbabaabbbaaaabaababaabababbbaba
bbabaaabbaababbabbbbaabbbaaabbbb
bbbaaaabbaabababbbabbbab
bbabaaabbbbbbbbbbababbaaabaabaaabbababbb
abaaaabbbbaabbaabbabaaaaabaabbbabbaababa
baabbaaaaaaabbbabbababba
babbabbaaaabaabaababbbabbbbaaabaababbaaaabbabaab
baabbbaabbbbabbaaabaabaaabaaabaaabbaabbaabaababaabaabbbababbabab
babbbabbaaaaabaaabaaaaaabbbabaabaaabbbbbbbaaaababbbbbbbaaababbbaabbbabbbbaaaabba
ababbbbbbbbbbbbbbabbabbaabbbaaab
bbaaabaabaabaabbaaaabababbbbabbb
bbabbabbbbbbbbaabbbaabbb
bbbbabbaaabbaaabaaabaaaa
ababaabbbaabbababaabbbaabbbbbbba
baabaaaabaabbaabbababaab
aabbabaaabaaaaaabbabbbaa
abaaaabbbabaaabbbbaaaababaabbaaabaabbbbaabbbbaba
baaaabaaaabbbbabaababaab
babaabbaaabbaaabbbbabbaaabbaaabbbbaaaabbbbbbabbb
bbaaaabbbbbbabaabbbbabbababbaaaabbabbaab
aaabaabbabbaaabbbabababbbaababababababbabbbbabbb
bbbbbaabbabbbabbbaaaaaab
bababbaababbaaababaaaaabbbabbabbbbbbbbbbaaabbbbabbaabaabaabbbbbb
abbabbabababbababbaaaaab
bbbbbbaaaaaaabbabbabaaabbbaabbababbaabab
bbaaaababbaaabbabbbababbaabbababbbbbabababaaaabaabbaabaaabaababb
aaabaabaaabbbbbababbbabbbabbbbba
bbbbaaabaabbbbbaabababbb
babaaababaaaabaaaaaaabbabababaababababab
bbaaabbabbbbbaaaaabaaaaa
bbbabbaabbaaaaaaabaabaaaaaaaabbbbbbabbbbaaaaabbbbababaab
aababbbbbbaaaabaaaabbaaaaaababbbababaabaabbabaaabaaabababbabbbaa
baaababbbaabbaaaababbbabbbbabbaabbabaaab
aabbbbbabbbbaabbbaaaabbaabababbbbbabbaabaababbbabbaabbbabaaabbbb
baaabaaaabbabbbaabbbaabaabbaabbabbaabbbaaabaabababbbbbab
aababbbbabaabbabbababaab
abbaabbaaaaabbbbbaaabaaa
abaabbbbbbaaaabbbbaaababbbabbabbbabbbaaaabaaaabaaabbabbbabbabaaa
aaaabbabbaaababbabaabbabbbbabaaabaaaaaba
bababaaabbbbbbbbaaabbabb
babaababbbaaabababbbaabbaaabbaab
bbabaaabaaabaabbbbaaabab
abbbabaabbbabbabbabaababbaaabbabbabaabaabbbbabbaabaabaabbabbbaba
bbabbbbabbabbabbabbabbba
aabaabaabbabaaaaabbabaab
ababaaabbabaaaabbbaabbbb
ababbbabbaaababbaaaabbbbabababaa
bbbababbababbabaababbaab
bababbbaaabbababbabbabab
babbabbbaaaabababbbaaaabaaabaabbbbaaaaaaaababababbabababbabaaabbababbbbaaabbbbbbabbababb
bababbaaaabababbabaabbababbaabbb
aaaabbbbabbaaabbbabbabaa
babaababaaabaabaaaabaaab
bbbbaaaabaabbabaaabbbaaa
babbbabbbbbaaabbabbbbbaa
bbabaaaababaababbabaaabbbbbbaaaaabbaabbb
aabbbbbababaaabbaaaabbaabaaaabab
babbbaabbbabbbbaabbaaabbbbabaaba
aabababbababaaabbababaaabbbbaaaabaababbbaabbaaaabbabbbabbbbbbbabbbbabbbb
aabbbbbaababbbbbaaaabbbaabababaaabbbbbba
ababaaabaaabbbbbaaababbbabaababbbbaaabab
aababababbaaabbabbaabaaa
ababbbbaabbababbabbabbbb
bbbaaabbbbbbaaababbaabbababbaaabbaaabbbb
aaaaaabbbaabababbababaab
abbbbaaababababbaabbaaabaabbbaabaaabaaaa
bbbbbbaabaabbbabaaabbabb
baabbbaaaaabbbababaaaaba
abbbaaaababaababbbababba
babbaababbabbabaabbbbaabaaaaaaab
abbbbbabbabaaaabaaabbbbbbaaaaaaaaabbaaaa
aabababaabbbaaaaabbabaab
babbabbabbbaaabaabbaaabaabbabaaa
baabaabaaababbbbaabaabbb
aabbbbabbbbbabbabaabbbbb
abbabbabaaabbbababbbabba
bbaaabbaaabbbbbaaababbabaabbbbbabbabaabbbababaabbbabbbab
babaaabbbbaaaabbaaaabababbbbbbbaaaaabbaaaaabaaabbabbabba
bbababababaaabbbbabaabbb
bbbbaabbbbbbbaaaabbbbaab
baaabbbababaaabaaaabaabbabbabababaabbaababbaabab
bbaabbbaaabbabbabaabbbaaabbaaaababbabbbaabababba
abaabbbbbaabaabbbbbaabab
bbbabbaabbbbabbaabaabbabbaababaa
abaaaaabaaaaabaaabbabbbb
abbbaaaaabaaabbbbbabbabbbaaaaaba
baaabbabbbbabaaabbbaabbb
baabbabbaabbabaaabbbbbba
abaaabbbbbbbbbaabaabbbaabbbbaabbbabaababbbaabbbabbaabaabaaababaa
bbbbabaabbbbabaaabbaaaab
ababbbbbabaaaababbbaabbbbabababaaabaaabaabbabaab
abbaaabbababaaabbbbabbabbabbbaaabbbabbbb
bbbabbbabbbbbaababaabaaa
baaabbbabbbbababababaaababababaabaaaabab
bbbaaaabbaabbabaaaaaabbabbaabbba
babaabaababbbaabbaaabbaa
bbbaabbbaabaabababababba
bbbabaaaabbbbbababbbbaba
bbabbbbbbbbbaaaaabababaa
aaaaababaaabbbaabbbbaaabaabbbbabbabbbbbaaabbaabb
abbababbaababbbbbbaabbba
bbaaaabaaababbabbaababbabbbbabbb
abbbaabababbbabbbaaabbbabbaabbbabbaaabab
bababbbaabaaabbaabbabbababbbbabb
babaabbabbabababbbaabbba
aaaabbbabaaabbabbabbabbabbbbaabbabaabbaa
abaaababbbaaaabbbbababaabbbabbaababbbbbbabbbaaababaabbbbbbbabbaaaaabbaab
bbbabbabbaababbaabaababa
ababbabbabaaabaabaaaabba
abbabbababbaaaaabaaaaaab
baaabbbababaabaaabbaaabbbabbbbbbabbababbabbbbabbbababababaaabababaaabbbb
abbaaaaaaaabbaaaaaaaababbbabbbbababbbbabbabbbbaabbaabaaa
bababbbabbbbaaaaababbabbabaababbabbbbbba
aaaabbbaaababbbbabaaaaba
bbbabbbabbaaaabbabbabbabbbbabaaaaaaaaabb
bbbbabbabbaaaabbaaabaaaa
abbbaaaaababaabababbbaba
ababbbabaaaaabaaaaaaaabbbababbbbbabbaabbbbaaaaab
bbbaabbabababaabaabbaabaaaabaaabbaaabbabbabaaaababbbbbbaababbaaa
aabaabaaababbababbaaaaab
baabbbaabaaabbbabbbbabbaaabbaaababbbabab
bbbaaaabaabbabaaabbbabba
bbbaaabaababbabababbbaaa
baabbaababbababbabbaabbb
bbaaabaabaabaabaabbaabab
aaabbbabbbbaaababbbbbbbbbbaabaaa
abaaabbaaabababababaaabaabbaaabbabbbbaab
abaabbabaabababbbbbbabaabababbaabaabbabababaabaabaaaabbb
aabbababbababaaaabbbaaaabaaaaaab
abaabbababaaaaaabbbaabab
bbbbaabbbbabaaaababaababaaabbbbbaabaabaabaaabbbbbbabaabb
aaabbbbbbbbabbbabbbbabaabbbbbaaaabbbbbabbbbbbbab
aababbaababbabbbbbbbbbab
abbaaaaaaabaaabbbbbbaabababbbababbbaabababbaabbb
aaabbbbbababaabaababbaaabbaaababaaabaaab
abbbababaabbbbbaababaabbbbababbbaaaababaababaaaaabbbababababbabbababaabb
bababaaaabbaaaaaabbbaabb
bbbabbabaaabaabbbaababbababaaababbabaababaaabbbb
bbbbababaabbabaabbbabbababaaaabaaaaaaaba
abaaabaabaabaaaabbaaabaababbaaba
bbbbbaabaababbaaabbbbbbb
bbbabaaaabbaaabbbabaababababbabbbbaabaab
bbbababbbaaaaaaaaabbbaaa
aababbaabbbbbabaabbaabbb
bbbbababbaabaaaababbaabbbaababaa
babbbaabbabaababaaaabbbbbbaaabab
aababaabaaaabaaaabbbabab
baababbbbbabaaaaabbbabab
bbabbbbbbaabbbababbabaaa
aaaaababbaabbabaabbbabaaabaaaabbabbbaaab
aaabbbaabbbbaabbabbbbaba
baabababababaaabbabbbbbbaabaaaababbbabba
bbabaaababbbbbabbbbabaabbabbbabaaabaabab
aabbaabababababbbbbbbabb
bbabbbbabbaaabaaabbabbba
aabbbbabbaabbaaaabaababa
abaabbabbbbbaabbbbbabaabaaaaaaaa
baababbbbaababaabbbababbbabbbaaabababaaabbbbbabbabaabbbababaabbbbabababaabaaabbbabbaaababbababab
abaaaaabbababbababbbbbbb
baabbaabbabbbbbbaabaabbbaabbabba
babaababbbbaaabbabbaaaaaabaaabbbbbabbaaabbaabbbb
aaaabbbaaabbbbbaabaaaaaaaaabaabbbaaaabbaabbaabbbbaaaabbb
bbbaaabbabbabbabbbbbabaaabababbabbbaabab
bbabababbababbaabaaabbbb
ababbbabbbaabbaabaababbbbbbbbbbbabaaaababbaabbbabbbaabba
bbbbabbaababaabababaabaabbbabaabababbbabbbaabbbabbbaabaaaabaaaab
abbaabaababbbaabbabaabbabbbaabaabbabababbbaaaaaabaaaaabaabaababbbbbbaabbbbbaaaab
bababbaaaaaabbbbbaaabbbb
bbbaaabababaaaabbabababababaabaaabaaabababababba
bbbabbbabbbbbaabbaababbbaabbaabb
baaababbaabbaaabbaaaabbb
baabbaabbbbbaabbababbbbaaaaababbabbbaabb
bbbbaaababbbaaaaaaabaaaa
baaabbabaaaaabaaaaababba
bbbaaabbaabaabaaabbbabbb
aababaabbbaaabaaababbaab
ababbbabbbabbbbabaaabbbaaabaabbbaabaaaab
baabbaaabaabbababbaaaaab
aaabbbaaaababaababbaabbb
bbbababbaaaabbbbbbbbabbb
aaabbababaabababbbbabbbaaaaabbbaaaabaaaa
abbbbbabbabaabbaabaabbabaabaabaaaabaabba
bbbaaabbaaaabbabbbaabbab
bbaabbaaaababbbbaababbababbabbabaaaaababbaaabaab
bbbaaababbabbaaababbbbba
babaaabaabaaabbbbbbbbbbaaaababbbbabbabbb
bbbabbbabaabbababababaaabaaaababaabbbbaa
aaaabaaaaaaabbbbaababababaabaabbbbbaabbaabbabbaabbaaabab
abbbaaaaaababbabbaababaa
baababbbbabaaabaaabaabab
bbbbabbabaabbbababbaaababbaabaaaabbbbaab
babbabbababbbabbbabbbbaa
aabbaaababaaaaaabaaaabbb
baaabbabbbbababbabaaaaba
abaaaaababaaabbbabbabbababbaaaaaabbbabaaaabbbaabbbaabbabbbaaababbabbbaaa
bbbabbabbabababbbbbabbabbaaaaabbababaabbbbaabbab
abaaaaaaaaabaabaaaaabbabaaaaaaba
aaaababaaabbaaabababaaababaabaaa
abbbbbabaabababaabbbaaab
bbbbabbaaaaabbabbbaababa
baababbaaaaabaaaaaaaaabbababbbaaabbaabaa
abbbabaaaabaabaabaaabaab
aaaabbabbababbabaabbbbabaababbabaabaaaaa
aaaababababbbaabaaabaaaa
abbabbababaaabaabbabbaaaabbabbbaabaababb
babbabbabbbbbaabbbabaabb
aababbabaaaaaabbbabbbbbbabbaabaabbbaabbb
bbaaabbabababbbbaaaababaaabbbbbb
abababbbbbbbbbbaababbbbbaabaaabaababbbbbbaabbaababaababaaaabaaaaababbabb
aaaabaaabaaaaaaabbbbaabbaabaaaba
abbbabaababaabaaaaaaaaab
bbbababbbabbaabbaaabbaaaaaabbabaababbaabbbaababa
baaaaabbababbabaabaababbaaaaaaabbababababbaabbaaabbbaaaa
bbbababbbbbbabababbbabab
abaaaaabbabababbaabbabbb
bbbbbaababbbbaaaabaabbba
bbbbbaabababbbbaabaaaabbaabbaaababbabbabababaaaa
baabbaabbababaaaababaabbaaababaa
abbbbbababaaaabaabbabbabbabbbbabaaabaabaaaabaaababaaabaababaababbbbbabba
aaaabbabababaababaaabbbb
baabaaaabbabbaaabbbaaaabaaabbbba
baaaaaaaaaaabbaabababaab
baabaababaababbaaabbabba
aabababaabbbbbabbababbaabababaaaabbbbbaa
ababbabbababaabbbbbabaab
aababbabaabbababbaaabbbb
bbbabaabaaaaabaaaabbaababbbbaaabbaaababaaabaaaba
aaaabbbabbbbaaababaaabab
bbbbbaaababbaabbababbbaa
aaabbbabbababbbbabaaaaba
bbabbbbbaabaabaabbbaabab
baaaaaaabbbbbaabaabbaaaa
baabaaaabaabbabbabbabaab
aaaabababaabaaaabbbbbbba
bbaaaabbbaaaaabaaabbaaabbaaabbabbbbbabbbababaabababaaabbbbbaaaaa
baabbaabbababbabaabbbbaa
aabbbbababbaaaaaaabbabbabbabbaabbabaabababaaabbbbabababaababaaabbaabbbaa
bbabababbaaabbabbabaabbabbbbaaaaaabbabbbaaabbabb
babaababbaabababaaababaa
babbaabbbbbbabaabbabbaba
babbbabbbaaaabaaabbaaaaabbaaabbb
ababbbabaababbabbbbaaaaa
abbaaabbbabababbbbbbbbba
bbbaaaabbabaabababbaaabaabbabbbbabbabbaa
bababbbabbbbaabbabbbabbb
bbabbbbbaaaabbbbabbabaab
aaabaabbababbababaabbaaababababbaababbababaaababbabaabbbabbaababbbbaabbababbabab
baaaabaababaabaabbbbabaabaaabbbbbbbaabaa
bababbbbababbbabbaabbabaaaaaaaba
aababbbbbabaaababbaababa
aaabbbaaababbabbaabbabaababbabbaaabbbaaa
bbbababbaaabbbbbbbabbabbaababbabbababbbaaabaaaab
abbabbababaaaaabaaaaaabbabbabaaa
aaabbbaaaabababbababaaabbbbaaabbbbbbbaabbbbaaabbababbbaabbabbbaababababaabaabaabaaabbaab
babaaaababaaabaabbbbbaba
bbbabbabababaabaabaababa
bbbbaaabbbbaaababbaababa
bbbabbbabaababbaaaabbbbbaaaaaaab
aabbaabababaabababaaaaba
aaabbbbbaaabbbbbbabbabaa
baabaabababaabababbababaabbbaabbbbbababa
bbbbabaabbaabbaaaabbaabb
babbbaabbabbbabbbaabbbba
abbabababbbbaaabaaabbbabaabababaabbabbba
baabababbaaababbbbbbbbba
aabbbbabbaabaabaababbaab
abbaabbabaabaabaabaababa
baaabaaabbbaaababbbababbabbaaabbbbabbaaa
abbbbbabbbbabbbabbbbabababbbbaba
aababbbbbbabaaaaaaaababb
ababbabbabbabaaaaabbaaabaabaabababaaabbbaaaabbbaaabbbababbababbb
ababbabbbbabbaaaaababbba
abbbabbababaaaabababaaabaaabaaaabbbbbabbabbbabbbbaaaaababbbbaababbbabbabaaabbbaa
aabababababaabbaaabbabba
aabbaaabbbabbbbbbbbababbbaaabbabaabaaaab
babbbabbbbaaabbaaaabbaaaabaababa
bbaaaababbabbabaabaababb
aabababbaaaabbaaaababbba
babbaabbaaaabbabaaababaa
babaabaabababbbbabbaababaaababaaabbaabbb
aababbaaabaaabaababbbbab
bbabbbbabababbabbbabbabbabbaaaaabaaaaaab
abbbabaaabbaaababaaabaaa
bbababbbbbabaaaabbaabbbababbabbbbbbababbaaabaaaa
baaaabaabbaabbaababbbbbbabaabbbbbbbaaaaaaabbbbbb
baaabbabbabaababbbbbbaaaababbabaaabaabaaaaabbbaabaababaaaabbabbabaaabbbbaabbbbbb
aabbaaabaaabbabaabbababbaaaaaaab
ababaabababaababbbbabbabbbbabbaa
baabbbaaabbaaabbaaababaa
bbbbabbaaaaaaabbbaaabaab
aabbbababbbbbabbabababaababbaabbbabaababbabbbabbbaaaaaabababbbab
abaaaaaababbbbbbbaaababa
baabbbaaabbabbaabbbbabbabaababbbbbabbbaaabbabbababbbbababbabbababbabbbaaabaababa
bababaaaabbbaabababaaabbabbaaaab
abbaaaaaaaaabbbbbabbaaabbbbbababbbabaaabaaaabbbbbbbabbbb
aaaabbaabaababbbaaababbbaaaaababaababbbaaabaabbaabaabbbbaaaababbbaaabaab
babbababbaaaaaabaabbabbb
aabbaaababaaaaaaabbbbbba
bbbabaaaabbaaabaaabaaabb
bbabbaaababbbaabbbabababbbabaaabbaaabbaaaabaabbb
aaabbaaaabbababbaabababbabbbbbabaaaaabaaaabaababaabbbbaa
abaaaaaaaababbabbabababbbbabbbbaaabbababaabbaabbaababaaa
abbabaaaaabaaabaabbbbaabbabaaababaabababbbaababaaaaabbaabbbbbbba
bbaaaabbbbabbaaaabbbbaaa
babababbbaababbaaaaaabbb
aabababaaaabbbaababaaabbbaaaaaaaaaabaaaa
baababbaaaabbbabaaaaabaabaaaaaaabbbaabababababba
ababbbbbabbaaababbbbbabb
baabaaaabaababaaababbbab
bababaaaabaaaabbabbbbbba
aaaabbaaaababbabaababbabbabbbbaa
bbbbaaabbabaaaabbabbbabbaabbababaabbbaaa
bbabaaabbaaaabaaababbabbababbaaaaaaaaaaabbbbbabb
babababbaabbaaababbabaab
babbabbbbabbbbbbbabbababbababbbbaabbbaabaababbab
babaabaaabaaaabbbbbbbbab
aaaabbaabaabbaaaaabababaabbabbabaabbbabaababbaab
abaaaabbbaabbababaaaaaaaaaabbbaaabababaaabbbabba
abaaabaababbbbbbaabbabbbbaaabbbb
aaaabbbaaabaabaaabbaabab
bbbbabaaaaaaabaaaabbbbaa
abaaabaaaaababbbabaaabab
ababbbbbbbabbabbaababaabaaaabaaabbaaabab
aaabbabaababbbbaaaaaabbb
aaaaabbabbbbbbaabbababbb
bbbbaaaaabbbaaaaaabbaababaaaabaaaaabaabaababbbababbabbbbbbaababaaaababba
bbaaabbaaabbbbabaaabbaab
abbbaababaaabbbabaabbbaabbababbbabaabaaa
baabaabbbbbaaababbabababbbaabbababbbbbbb
bbbaaaabbbaabbaabbaaaaab
ababbbbaaabbabaaaababaaa
bbaaabaabbbbaaaaababbabbaabaabbbbaaabbbb
aaabbbabaababababbaabbbb
baabbbaabaaabbbabbbbbbaaababbbabbabbbbbabaaaabba
bbabaaabababaabbaaaaabbaabaaaaaaabbababbbbbbbbbaabbbbbbbaabbbaaa
aaabbbabaaaabbbbbabaabbb
abbbaabababaabbaaababababbaababa
aabbbbabaabaaaababbaabbbaabaaababaaabbababababaabbbaaaabaaaabaaaabbabbbaabaabbabaababaabbbabaabb
aaabbbabbabbabbaaaabbabaabbbabbaabbaabab
bbabbbbbaabbbbabbaaaaaba
bbabaaabbbbbbaabaabbaaaa
abbbaabababbbaababbbbbba
babaabbaabbaaaaaabbbbbbb
abaaabaaaaabaabbaabbbaab
baabaaaaababaabaabaabbbbbbaabaaa
aabbbbbaaabbaabaaababbba
babaaabaaaaaabbabbbaaababbaabbba
aaaabbbababababbabaaabbbbbbbbabaababababaababaaa
ababbbbbbbbabaaaaaababaa
bbaaabbaabbaaabbabbbaaab
bbbbbaaababbbaabbabbaaba
aabbbbabababbabbbaaaaabbabaaaabbbbababbb
baaaaabbaabbbbbabbaabaaa
baababbabbabbbbaaaaaaaaa
bababaaabbaaaabaabbbaabaabbaaaab
aaaababaaabbbbabaaabaabaabbabbbbbbbbbbab
babaaabbaaaaaabbbbababaaabbbbbbbaabbabaabbababbabbbbaaabbaabbaaa
baabaaaabbbababbaaababab
bbaaabbabbbababbaabbabbb
aabababbbabaabaabbaabaaa
bbabaaabbababaaaababbaaabaabababbaaabaabbabbbbab
abbbbbabaaabbabaaaababba
baaabbabbabaaababaaababa
baaaabaaaabbabaababbbbab
babaabbabbbbabbaabaababb
abbbabaaabbbaababaababbabbbabbbb
bbaaabaababbaaabaabaabaaaaaaabbabbaaabbaaaababbbbababaabbbbbbbba
abaaabbbbabaababaaaaababbbbaabaa
abaabbabbaaababbaabbbaab
bbbabbbaaababbabbaabaabbbbbabbababaaaabbbaabaaabbbbaabbbbbbaababbabbbbba
ababbabaabaaaaaabbabbbab
ababbaaaabbaaabbbaabbbaabbbabbbabbbbababbaabaaab
abbbbabbbbaabbbaabaaaaaabaaaabaaabaabbaaabababbabaaaabbbaaabaaab
babbabbaaaaaabbabbaaaaababaababbbbabbbabaabbbbbbaaaaaaba
baabaaababbbbbaabbbaababaaaaaaab
bbbbbbaabaabbabaabaababb
bbbabaabbbbbbabaabbaabbaaabbaabababbbbaababbabaaabaabbba
baabbbabbabaaaababaaaabbabbbaabaabbaaaaaabbaabaaabaabaababababab
abbaaabaaababbbababbaaaabbbbaaabbbbbabbbabbbbbaaaaaaaabbbbaababbaaabbabbababbbabababbabb
aaaaaabbabbaaabbaaaababb
aaabbbababaabbbbbababbaabbaaaababaaabbbabbbbbbbbabaababa
bbbababbaababbaabaaaabbb
bbaaaabbbbabbbbbaabbaabb
aaaabbbaaaabbaaabaaabaab
aaabaabbababbabbabababba
aabbabaaabbababbbaaaaaaabbbbabababbbaabbbbbaaaaa
abaabbabbabbbabbbbababba
abbaaaaaaababbabaaaabbaabaaaabbaabababab
aaabbbbbabbabbabbbabaaababaababb
babbbaabbabbbaabaaaaabaabababbbbbababbbbabbbbabb
bbabbabbaaaaabababaabbababbababbaaaabbbbabbbabbbababbbba
baabaababaabbabaaaaabbbababbbbbbbbabbabbbbbbaabaaaaabaab
aababababaaababbbbababba
baabbaaaaabbbbababaababb
ababaaabbaabbaaaabbabbbb
aaaababaaaabbaaaaabbaaaa
baabbbaaabaaabbaabbbaaaaaaaaaaaa
babababbaaaaaabbbaaababbaaaabbbaabbbbbababbbbbaaaabaabab
babbbababbbbaaabaabbbabbbaaababbabbabaabbabaaabbabbaaabababbbabaababbbba
bbbabbababaaaaaababaaaabbabbabbaaaabbbba
bbabbaaaabaaaaaabbabababbbbbbabaabbabbbbaabaaaaabbaaaaab
babbbbbbabaaaabbabababab
baaababbbbbababbbabbabbb
aaaabbbbabaabbbbabbaabaa
bbbabbbabbbbaaabaaaabbaabbbbaaba
bbbabbaaaaaabbbaababaababbbabbbb
bababbaabbabbabbababaaababaabaaaabbaababbaaaaaaaaabbabbb
bbabaaabbaabaababbaaabab
aababbbbababaaabaabbbaaa
abbbabaabaaababbbbabaaabbbbbababababaaaaaaaababb
aaabbbbbbaabababbbbaabbb
aaabbbaabaababbbbbbaabba
baaabbbaabaaaaaabbbabbabaabaabbabaababaa
abbabbabaaabbbbbabbbbbba
bbbabbbabbbabaabbabbaaba
bbabbbbaabbaabbabbbabaabababbabbbabbabbb
bbbababbaabbbbabbaabbbabbbaaaaabaabaabab
aaaaababaabaaabbbbbabbbbbbabaaab

View File

@ -2,7 +2,7 @@ package main
import (
"fmt"
"os"
"regexp"
"strings"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
@ -16,10 +16,6 @@ func main() {
solve(inp, h.Atoi(part))
}
var loopingTokens []int
var allTokens map[int]*Token
var totalRules int
/*
8: 42 | 42 8
11: 42 31 | 42 11 31
@ -32,7 +28,6 @@ affect things as they repeat
*/
func solve(inp []string, part int) {
allTokens = make(map[int]*Token)
var section int
var rules []string
var messages []string
@ -48,241 +43,130 @@ func solve(inp []string, part int) {
messages = append(messages, v)
}
}
totalRules = len(rules)
last := -1
for RulesSolved() < totalRules && last != RulesSolved() {
last = RulesSolved()
for _, v := range rules {
fmt.Println("Restarting Rules Parsing")
pts := strings.Split(v, ": ")
num := h.Atoi(pts[0])
if part == 2 {
if num == 8 {
pts[1] = "42 | 42 8"
} else if num == 11 {
pts[1] = "42 31 | 42 11 31"
}
}
if _, ok := allTokens[num]; !ok {
GenerateToken(num, pts[1])
}
}
}
if RulesSolved() < totalRules {
fmt.Println("Unable to solve all rules")
os.Exit(1)
}
fmt.Println("Calculating Answer")
var matches int
for _, v := range messages {
if allTokens[0].Matches(v) {
matches++
}
}
fmt.Printf("## Part 1\nAnswer: %d\n", matches)
}
// RulesSolved TODO
func RulesSolved() int {
var ret int
for k := range allTokens {
if k >= 0 {
ret++
}
}
return ret
}
// Token Kinds
const (
LEAF = iota
STICK
BRANCH
)
// Token TODO
type Token struct {
kind int
num int
value string
raw string
PartNums []int
Parts []*Token
CachedValues []string
Loops bool
}
// GenerateToken TODO
func GenerateToken(num int, raw string) *Token {
if v, ok := allTokens[num]; ok {
return v
}
t := Token{num: num, raw: raw}
if raw[0] == '"' {
t.value = strings.ReplaceAll(raw, "\"", "")
t.kind = LEAF
if part == 1 {
solveOne(rules, messages)
} else {
if !strings.Contains(raw, "|") {
t.kind = STICK
var partTokens []*Token
pts := strings.Split(raw, " ")
for k := range pts {
if pts[k] == "|" {
continue
}
t.PartNums = append(t.PartNums, h.Atoi(pts[k]))
solveTwo(rules, messages)
}
}
func solveOne(rules, messages []string) {
reg := regexp.MustCompile(rulesToRegex(rules))
var answer int
for _, msg := range messages {
if reg.MatchString(msg) {
answer++
}
}
fmt.Printf("## Part 1\nAnswer: %d\n", answer)
}
func solveTwo(rules, messages []string) {
// Figure out how many levels deep we have to go to stabilize
var answer int
var last []int
for i := 0; i < 1000; i++ {
answer = 0
rules = unwrapLoops(rules, i)
reg := regexp.MustCompile(rulesToRegex(rules))
for _, msg := range messages {
if reg.MatchString(msg) {
answer++
}
solved := true
for k := range t.PartNums {
if v, ok := allTokens[t.PartNums[k]]; ok || h.IntSliceContains(loopingTokens, t.PartNums[k]) {
partTokens = append(partTokens, v)
} else {
solved = false
break
}
if isStable(last, 10) {
break
}
last = append(last, answer)
}
fmt.Printf("## Part 2\nAnswer: %d\n", answer)
}
func isStable(history []int, confidence int) bool {
if len(history) < confidence {
return false
}
last := h.MAX_INT
for k := len(history) - 1; k > len(history)-confidence; k-- {
if last == h.MAX_INT {
last = history[k]
continue
}
if history[k] != last {
return false
}
}
return true
}
func unwrapLoops(rules []string, depth int) []string {
for i := range rules {
wrk := rules[i]
if strings.HasPrefix(wrk, "8:") {
wrk = "8: 42 +"
} else if strings.HasPrefix(wrk, "11:") {
rule := "42 31"
for k := 2; k < depth; k++ {
rule += " | "
for j := 0; j < k; j++ {
rule += " 42 "
}
for j := 0; j < k; j++ {
rule += " 31 "
}
}
if solved {
t.Parts = partTokens
wrk = "11: " + rule
}
rules[i] = wrk
}
return rules
}
func rulesToRegex(rules []string) string {
cache := make(map[int]string)
for {
if _, ok := cache[0]; ok {
// We've cached 0, so we're all done
break
}
loop:
for _, rule := range rules {
tokens := strings.Fields(rule)
var num int
fmt.Sscanf(tokens[0], "%d:", &num)
if _, ok := cache[num]; ok {
continue
}
} else {
t.kind = BRANCH
pts := strings.Split(raw, " ")
for k := range pts {
if pts[k] == "|" {
continue
}
n := h.Atoi(pts[k])
if n == num {
if !h.IntSliceContains(loopingTokens, t.num) {
fmt.Println(num, "IS A LOOPING TOKEN")
loopingTokens = append(loopingTokens, t.num)
t.Loops = true
tokens = tokens[1:]
// A 'leaf'
if len(tokens) == 1 && tokens[0][0] == '"' {
cache[num] = string(tokens[0][1])
continue
}
// All other rules
ruleReg := "(?:"
for _, tkn := range tokens {
c := tkn[0]
switch {
case '0' <= c && c <= '9':
tknN := h.Atoi(tkn)
subRuleReg, ok := cache[tknN]
if !ok {
continue loop
}
ruleReg += subRuleReg
case c == '|':
ruleReg += "|"
case c == '+':
ruleReg += "+"
default:
panic("Error building RegEx:" + tkn)
}
}
branches := strings.Split(raw, " | ")
var partTokens []*Token
for k, branch := range branches {
branchID := -(num*1000 + k)
t.PartNums = append(t.PartNums, branchID)
p := GenerateToken(branchID, branch)
if p.Solved() {
allTokens[branchID] = p
partTokens = append(partTokens, p)
} else {
continue
}
}
solved := true
for _, bid := range t.PartNums {
if _, ok := allTokens[bid]; !ok {
solved = false
break
}
}
if solved {
t.Parts = partTokens
}
ruleReg += ")"
cache[num] = ruleReg
}
}
if t.Solved() {
allTokens[num] = &t
} else {
fmt.Println("> Couldn't Solve", num)
}
return &t
}
// Solved TODO
func (t *Token) Solved() bool {
return len(t.Values()) > 0
}
// Values TODO
func (t *Token) Values() []string {
switch t.kind {
case LEAF:
return t.LeafValue()
case STICK:
return t.StickValue()
case BRANCH:
return t.BranchValue()
default:
return []string{}
}
}
// LeafValue TODO
func (t *Token) LeafValue() []string {
return []string{t.value}
}
// StickValue TODO
func (t *Token) StickValue() []string {
if len(t.Parts) < len(t.PartNums) {
return []string{}
}
if len(t.CachedValues) > 0 {
return t.CachedValues
}
var ret []string
for k := range t.Parts {
if len(ret) == 0 {
ret = t.Parts[k].Values()
} else {
var newRet []string
for rk := range ret {
newRet = append(newRet, h.AppendStrings(ret[rk], t.Parts[k].Values())...)
}
ret = newRet
}
}
t.CachedValues = ret
return ret
}
// BranchValue TODO
func (t *Token) BranchValue() []string {
if len(t.Parts) < len(t.PartNums) {
return []string{}
}
if len(t.CachedValues) > 0 {
return t.CachedValues
}
var ret []string
for k := range t.Parts {
ret = append(ret, t.Parts[k].Values()...)
}
t.CachedValues = ret
return ret
}
// Matches actually tests a message against this token
func (t *Token) Matches(msg string) bool {
for _, v := range t.Values() {
if msg == v {
return true
}
}
return false
}
func (t Token) String() string {
return fmt.Sprintf("{num:%d, kind:%s, partNums:%v, value:%v}", t.num, KindToString(t.kind), t.PartNums, t.Values())
}
// KindToString TODO
func KindToString(kind int) string {
switch kind {
case LEAF:
return "LEAF"
case STICK:
return "STICK"
case BRANCH:
return "BRANCH"
default:
return "UNKNOWN"
}
// We should be done now, we just want an exact match on rule 0
return "^" + cache[0] + "$"
}

47
2020/day19/testinput Normal file
View File

@ -0,0 +1,47 @@
42: 9 14 | 10 1
9: 14 27 | 1 26
10: 23 14 | 28 1
1: "a"
11: 42 31
5: 1 14 | 15 1
19: 14 1 | 14 14
12: 24 14 | 19 1
16: 15 1 | 14 14
31: 14 17 | 1 13
6: 14 14 | 1 14
2: 1 24 | 14 4
0: 8 11
13: 14 3 | 1 12
15: 1 | 14
17: 14 2 | 1 7
23: 25 1 | 22 14
28: 16 1
4: 1 1
20: 14 14 | 1 15
3: 5 14 | 16 1
27: 1 6 | 14 18
14: "b"
21: 14 1 | 1 14
25: 1 1 | 1 14
22: 14 14
8: 42
26: 14 22 | 1 20
18: 15 15
7: 14 5 | 1 21
24: 14 1
abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa
bbabbbbaabaabba
babbbbaabbbbbabbbbbbaabaaabaaa
aaabbbbbbaaaabaababaabababbabaaabbababababaaa
bbbbbbbaaaabbbbaaabbabaaa
bbbababbbbaaaaaaaabbababaaababaabab
ababaaaaaabaaab
ababaaaaabbbaba
baabbaaaabbaaaababbaababb
abbbbabbbbaaaababbbbbbaaaababb
aaaaabbaabaaaaababaa
aaaabbaaaabbaaa
aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
babaaabbbaaabaababbaabababaaab
aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba

1728
2020/day20/input Normal file

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,9 @@ func init() {
}
for y := range monster {
for x := range monster[y] {
SeaMonster[h.Coordinate{X: x, Y: y}] = monster[y][x] == '#'
if monster[y][x] == '#' {
SeaMonster[h.Coordinate{X: x, Y: y}] = true
}
}
}
}
@ -58,12 +60,8 @@ func solve(inp []string, part int) {
for x := range image[y] {
if image[y][x] {
waves++
fmt.Print("#")
} else {
fmt.Print(" ")
}
}
fmt.Println()
}
fmt.Println("## Part2\nAnswer:", waves)
}
@ -200,11 +198,6 @@ func buildMapFromTiles(tiles map[int]*Tile) [][]bool {
func monsterSlayer(inp [][]bool) [][]bool {
var found bool
for r := 0; r < 8; r++ {
if r == 6 {
// This is the correct orientation
fmt.Println("Rotation:", r)
PrintMap(inp)
}
for y := range inp {
for x := range inp[y] {
match := true
@ -232,7 +225,6 @@ func monsterSlayer(inp [][]bool) [][]bool {
}
}
if found {
fmt.Println("Found, breaking")
break
}
if r&1 == 0 {
@ -284,3 +276,39 @@ func PrintMap(inp [][]bool) {
fmt.Println()
}
}
func PrintCoordMap(m map[h.Coordinate]bool) {
minX := h.MAX_INT
maxX := h.MIN_INT
minY := h.MAX_INT
maxY := h.MIN_INT
for k := range m {
if k.X < minX {
minX = k.X
}
if k.X > maxX {
maxX = k.X
}
if k.Y < minY {
minY = k.Y
}
if k.Y > maxY {
maxY = k.Y
}
}
for y := minY; y <= maxY; y++ {
for x := minX; x <= maxX; x++ {
if v, ok := m[h.Coordinate{X: x, Y: y}]; ok {
if v {
fmt.Print("#")
} else {
fmt.Print(".")
}
} else {
fmt.Print(".")
}
}
fmt.Println()
}
}

107
2020/day20/testinput Normal file
View File

@ -0,0 +1,107 @@
Tile 2311:
..##.#..#.
##..#.....
#...##..#.
####.#...#
##.##.###.
##...#.###
.#.#.#..##
..#....#..
###...#.#.
..###..###
Tile 1951:
#.##...##.
#.####...#
.....#..##
#...######
.##.#....#
.###.#####
###.##.##.
.###....#.
..#.#..#.#
#...##.#..
Tile 1171:
####...##.
#..##.#..#
##.#..#.#.
.###.####.
..###.####
.##....##.
.#...####.
#.##.####.
####..#...
.....##...
Tile 1427:
###.##.#..
.#..#.##..
.#.##.#..#
#.#.#.##.#
....#...##
...##..##.
...#.#####
.#.####.#.
..#..###.#
..##.#..#.
Tile 1489:
##.#.#....
..##...#..
.##..##...
..#...#...
#####...#.
#..#.#.#.#
...#.#.#..
##.#...##.
..##.##.##
###.##.#..
Tile 2473:
#....####.
#..#.##...
#.##..#...
######.#.#
.#...#.#.#
.#########
.###.#..#.
########.#
##...##.#.
..###.#.#.
Tile 2971:
..#.#....#
#...###...
#.#.###...
##.##..#..
.#####..##
.#..####.#
#..#.#..#.
..####.###
..#.#.###.
...#.#.#.#
Tile 2729:
...#.#.#.#
####.#....
..#.#.....
....#..#.#
.##..##.#.
.#.####...
####.#.#..
##.####...
##..#.##..
#.##...##.
Tile 3079:
#.#.#####.
.#..######
..#.......
######....
####.#..#.
.#...#.##.
#.#####.##
..#.###...
..#.......
..#.###...

View File

@ -14,6 +14,10 @@ func NewCoordinate(x, y int) *Coordinate {
return &Coordinate{x, y}
}
func (c Coordinate) Relative(t Coordinate) Coordinate {
return Coordinate{X: c.X + t.X, Y: c.Y + t.Y}
}
func (c *Coordinate) North() Coordinate {
return Coordinate{X: c.X, Y: c.Y - 1}
}

View File

@ -263,6 +263,25 @@ func StringSliceContains(h []string, n string) bool {
return false
}
// IntSliceContains takes an int slice and an int and return true
// if the int is in the slice
func IntSliceContains(h []int, n int) bool {
for _, v := range h {
if v == n {
return true
}
}
return false
}
// AppendString returns a slice of strings that are base+group[...]
func AppendStrings(base string, group []string) []string {
for k, v := range group {
group[k] = base + v
}
return group
}
// IsPrime takes a number and return true if that number is prime
func IsPrime(value int) bool {
for i := 2; i <= int(math.Floor(float64(value)/2)); i++ {