diff --git a/2020/19/example b/2020/19/example new file mode 100644 index 0000000..1500b6f --- /dev/null +++ b/2020/19/example @@ -0,0 +1,12 @@ +0: 4 1 5 +1: 2 3 | 3 2 +2: 4 4 | 5 5 +3: 4 5 | 5 4 +4: "a" +5: "b" + +ababbb +bababa +abbbab +aaabbb +aaaabbb diff --git a/2020/19/example.2 b/2020/19/example.2 new file mode 100644 index 0000000..ef38a56 --- /dev/null +++ b/2020/19/example.2 @@ -0,0 +1,48 @@ +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 + diff --git a/2020/19/input b/2020/19/input new file mode 100644 index 0000000..f3a00a4 --- /dev/null +++ b/2020/19/input @@ -0,0 +1,505 @@ +42: 16 112 | 89 39 +120: 89 40 | 16 109 +30: 40 16 | 26 89 +2: 133 89 | 137 16 +15: 94 16 | 92 89 +8: 42 +134: 40 87 +23: 89 47 | 16 12 +78: 102 89 | 26 16 +119: 115 89 | 5 16 +11: 42 31 +67: 89 63 | 16 18 +82: 16 40 | 89 63 +88: 16 16 | 89 89 +97: 89 110 | 16 78 +85: 60 16 | 55 89 +3: 40 16 | 121 89 +132: 92 16 | 98 89 +77: 16 97 | 89 58 +72: 89 16 | 16 16 +27: 16 99 | 89 48 +50: 108 89 | 132 16 +53: 16 45 | 89 131 +70: 87 87 +36: 89 26 | 16 63 +65: 16 88 | 89 100 +38: 88 16 | 44 89 +25: 16 109 | 89 63 +81: 89 61 | 16 3 +136: 16 100 +104: 92 16 | 100 89 +115: 26 16 | 100 89 +45: 16 70 | 89 121 +63: 16 89 | 89 87 +92: 16 16 | 16 89 +130: 89 72 | 16 102 +105: 118 16 | 23 89 +34: 16 1 | 89 117 +83: 67 89 | 136 16 +26: 89 89 | 16 87 +116: 16 29 | 89 77 +29: 68 16 | 111 89 +10: 89 75 | 16 76 +64: 16 26 | 89 18 +14: 89 62 | 16 113 +80: 89 107 | 16 52 +35: 16 86 | 89 54 +54: 81 16 | 124 89 +32: 66 16 | 95 89 +61: 98 89 | 70 16 +124: 120 16 | 69 89 +59: 100 89 | 94 16 +17: 89 56 | 16 37 +127: 16 20 | 89 126 +111: 16 57 | 89 4 +58: 33 89 | 103 16 +137: 89 100 | 16 109 +69: 88 16 | 121 89 +109: 89 89 | 16 89 +95: 89 10 | 16 53 +73: 16 35 | 89 32 +114: 94 16 | 109 89 +60: 38 16 | 82 89 +79: 63 89 | 102 16 +12: 89 40 | 16 100 +118: 16 114 | 89 59 +55: 16 65 | 89 25 +21: 16 100 | 89 121 +66: 89 50 | 16 41 +18: 16 89 +6: 130 16 | 101 89 +51: 100 16 | 94 89 +56: 135 89 | 79 16 +135: 89 63 | 16 26 +125: 16 64 | 89 15 +139: 13 89 | 17 16 +20: 18 89 | 44 16 +129: 16 128 | 89 49 +16: "b" +62: 89 19 | 16 7 +5: 70 89 | 26 16 +24: 89 127 | 16 80 +107: 89 72 | 16 121 +108: 16 94 | 89 98 +102: 89 89 | 89 16 +1: 94 89 | 109 16 +19: 16 93 | 89 27 +43: 16 71 | 89 36 +117: 16 63 | 89 40 +110: 16 121 | 89 92 +122: 83 16 | 84 89 +37: 30 89 | 21 16 +128: 94 16 | 44 89 +46: 16 26 | 89 94 +7: 119 16 | 28 89 +31: 73 16 | 14 89 +0: 8 11 +44: 89 16 | 16 89 +131: 18 16 | 88 89 +101: 16 100 | 89 100 +133: 89 109 | 16 88 +76: 89 72 | 16 44 +100: 89 89 +93: 16 15 | 89 123 +138: 16 90 | 89 122 +89: "a" +47: 88 16 | 72 89 +96: 89 46 | 16 131 +48: 89 18 | 16 72 +39: 116 89 | 139 16 +103: 109 16 | 100 89 +121: 16 16 | 89 87 +86: 16 96 | 89 125 +123: 88 89 | 100 16 +84: 20 89 | 104 16 +49: 89 44 | 16 26 +4: 26 89 | 109 16 +33: 16 72 | 89 26 +75: 89 88 | 16 94 +28: 126 89 | 76 16 +9: 22 16 | 129 89 +98: 16 16 +68: 16 101 | 89 91 +57: 88 16 | 102 89 +41: 106 16 | 51 89 +87: 16 | 89 +112: 74 89 | 138 16 +52: 72 16 | 40 89 +113: 89 24 | 16 9 +99: 109 89 | 26 16 +90: 2 89 | 43 16 +74: 105 16 | 85 89 +106: 89 18 | 16 40 +94: 89 16 +13: 6 16 | 34 89 +91: 16 26 +71: 44 89 | 26 16 +40: 87 16 | 16 89 +126: 89 94 | 16 92 +22: 89 75 | 16 134 + +aaaaaaaabbbbbbbbababaabb +aaaaababaabbabaabbbabbab +bbbaababbaaaabababbbbaaa +ababbaaababaaaabbabaabab +babbaabaabaabbbbbaaaaaaaaabaaaabbaaabbbbaaabaaba +baaaabbabbbaabaabbabaaaa +babbaabbbaababaababbbbba +bbbbbbbbbabaabaaaabaaaabbaababba +aabbaabbbaaababaaabaaaabbaabaabbbaaaaaabbaababbbabbbbaba +baaababbaabbaabbabaaaabbbbbaaabaaaaababaaaabbaba +bbbbbaaaabbbaabbaabbbbaaababbaaaaaaaaabaaababbab +bbaaaaababbbaaaaaaaabbbbaabbbbaabbbbbbbbbaaababaabbababb +baaabaaabbbaababbbabaaabbbabbaaa +aaabbaaabbabbaaabababbba +abbaaabbaaaaabbbaabaabbbababaabaabaabbaa +bbbaaaabaabaabbbbaaaababbabbbbbb +aaabaabbabbbaabaaaabbbaaaaaabaaaabbaabaaabbbbbba +baabaabbabbaaaaaaababbaa +babbaabaaaaaaaaabbbaabaaaaabbabaabaabaaa +babaaaabbbaaaabbbaaabbab +babaaaabaaababbabaaaaaab +bbbbbbabbabbbbabbbabaabaaabaabbabbabaabb +bbbbaaabaaabaaaabbbaababaabaababbbabaabbbbabbbbb +bbaababbabbbbbaabaaababbaabbaaababababba +aabaabbaaaabbbbbaabbaaabababbaab +aababaaabaaabaaaabaaaabbababaaaaabaaaaaaabbbbbba +babaaaababbababbbaaabbbb +aaabaabbabbabaaabbbabbab +abaaaabbbaabbaabbaabbbab +baabaabbbbaabbaaaababaaaabbbaaab +bababaabababbbababbaaabbaabbabab +aabbaaaaabbbaabaaaabbabb +bbaabababbbaaabababaabab +abaaaaaabaabbbaaaaababbbababaaabbaabbbab +aaaaabbbaabaabbbbaabbaba +bababbabbbbaababbaaababababbbbabababbbaa +aabbabaabbbbbbaabaaabbab +bbaaaaaaaabbaaaabaaabbbbbbabbbbababaababbaabbbbbbbaaaaabbabbabbbbbaabbaaaaaabbaa +bbabbabaabaabbababbbbbab +aaaaaabbabbbaabbabaababb +abaaabbbbbbaabbbabaaabbbbbaaabbbabbbaaaa +baaababbbbbbabbbbbbababbaaababaaaababbaabbabbbbbbbbaaabb +babbbbbbabbbaaababbbbbbababbabab +bbababbbbbbbaabbbabbaaab +aaabaaababaabbbbaaabbabb +abbaaaababbbaaaababaaaba +ababbaabaabbabbbbababbbbaabaaaba +abaabbababaabbbbaabbbbaa +abbbaabbbbabbabbbbbbbbbbbbabaaababbbbbaaaaaaababbabbabbb +bbababbbbbbaabaaabbaaabaababababbabaabab +ababbbababaabaabaabababaabbaaabb +abaaabbbbababaabbbaababbbbbabbbb +baabbbaaaaabaaabbabbbaaa +baaaaabbabbababbababbbaa +babbbbbbbbbabaaaaabababbaaaaaaabbabaaaba +bbbaabbaababbbbabbabbabaaaaaabbbababbaaabbbbbaba +babbbabaababbbbbbbaababbbabaaababaaabbaa +baabbaabbbaaaaaabbbbbbaabbaabababaabbbaabbaaaaba +ababaaabbabaabbbbabaabab +aabbbabbbbaaaaababababbb +baaabababbabaababbbabaab +bbbbababaaaabaaabbbabbaa +abaaababbbbbbaaabaaaaaaaababbaaabaabbaaa +bbaabbbbaaabbbabaabaabaaababbbaa +abbbaabbbbaabababbbbbaababababab +bbaaaaabbbbaabbaabababbb +baabbbbaaaabaaababbbbaaa +baabbaabbabbbbabbbbabaaa +aabbbababaabaabbaaabbbbbaaabaababbaabaaa +babaaaababbabaabbbbaabaabaabbaababbaabbababbabbabaabbabaaababbababbbbbabbaabbabb +aaabbaabbaaababbabbbaaaa +aaaaaaaabbababaabaabbbaaaabbabaaababaabb +bbbaabbbbabaabaabbbbaabbaabababababaabaa +aabbbababbabbabbabababaaaabbaaabbabbbaab +bbaababbaababaabbabaabab +baaaabaaaabbabbbaabaaaaa +babbbbbaabbbabbbbbbbaabaaaabbbba +abaaaabbaababaababbbbabbbaabbaababbaabbaabaaabba +bbbbabbbbbaaaabbbabababa +abaabbbaabbababababbabbb +bbbaabbbbaaaababababbaab +aabbbabbbaaaabaabaababbb +ababbbbbaaaaabababbababa +baaabaaaaaabaaabbbbabbaa +aaaabbaaaaababbbbabababa +aaabbbbbababbaaababbabbb +abaabaababaaaaaabbaabbab +abaabbabbbababaaabbbbaaa +aaaabbaabaabbbaaaabbabba +aababaabbbbbbaaaaaaaaabaaabaabbababbbababaaabbaa +abaaabaabbabbababaaabbbb +bbbbaabbbabbaabbaabbbaaa +abaabbbabaabababbbaabaaa +babaaaaaababbbababaababa +ababbaaaabbbaabbbabbbabb +abaabbababbbbabbbabaabaaaaaaaaababababab +baabaabbbabbaabaabaaabaababaabbbbaaabbab +aaaabbaabbaabbbbabaaabba +ababbbbbbbabbabaabbabaaaaaaabababababaaa +aaaabbaabbbbabbbbabbbabaaabbbbabaabbbaaabaaabbbb +bbbbbbbbbaaaaaaaaaaababa +abbbaabbababbbabbaababaabaaaaaba +bbbbbbbbbbaabababbbbaabbaabbaaaababababa +abbbbbaabaaabababababbababaababbaabbbbaa +aaababaaabaaaaaababbabbb +baaaabaaaabaabbababaabaabbabbbabbabbbabb +bbbbabaaaaaaaabaaabbabaabaaabbabaabbabbb +bbbbbaaaaabaabbaabbbabab +ababaaabbbaaaaaabababbaaaabaabbabaabaaaababbabbabababaaaaabbbaabbabaabba +aababaaaaaaabbbbabbbbbab +aaaabaabaaaaaababaababba +aaabaaabbbbbaabbbbababba +aabababaaaaaabbabbabbbaa +abbbbbaabaaababbbaaabbba +baabaabbbaabaaaaabbababbaabababaaabaaaaa +aaaabaaabaabbbaabbaaaaabbbbbbababbbabbaa +aaaaaaaababbaabaabbabbab +abaaabaaabbaabbbbabaaabb +bbbaababaaababaaaaabbbba +ababbbbaaaaaabbabbbabbba +bbbababaaababababababbaabaabbaabaabbabaaaaaaabaabbbbabbbabbaabba +baaabaaababbaabbabbabbba +bbbbbaabaabbaaabbbaaabbabbbbbbba +babaaaabaabbaabaabaababb +bababaabbbbaabababbbbabbbbbbbaab +bbbbbbbbabbaaabbbababaaa +abbababbbbaaaabbbbaabaaa +bbaaaaaabbabbabbbaabaabaaabbbbabaaaaabababababbb +baaaaabbbbababbbbbaabbbbababbaba +ababbabbaabaabaabbbabbbabbaabbabbaaabaab +bbababaaabaaaaaaababbbababbbabba +aaaabaaaabbaabbbaabbabab +abbabaabababaaaaabbbbbab +babaabbbbaabbbaabaabaaab +bbbaaabaaabbaabababbabba +aabbaaabbbbbaabbbaaabbab +babbbbabaabbabaabaabbbbaaabbaabbabbbbaabbabbabbb +babbaababbaababbbbbabbba +abbaaababaabaabbbbabbaab +abbbabbbbbbbababaaabbbaababaaaaababbababbbbaaababbbbaaaaaababbbabaabababaaabbbba +baabaabaababbbbbbbaabaaa +aaababbbaabbbaaaaabbbbabbbbaaaaababbaabb +baaaaabbbaabbbbaabaabbba +aabbaabbaababaabaaaaaaab +bbbaababbaabbbbbabaabbaabbabbaabaababbbb +abaaababaaabbbaababababa +bbbaabbaaaaabbbbbabababb +abababaabaababaabaaaabababaaababbababbbb +bbbbbbbabaaabbaababbbbbababbbbabbbabbabbbaabbabbaabbbbaaaabbabbbaaabbbaabbabbaaabaaababb +aaaabaabaabbbabbbaababbaabbbabbabbabbbabbaabaaababaaabaabbbaabbbaabaaaaa +aabaabbbbaaaabaaababbbaa +bbaabaaabbbaabbabbbabaababbabbbbbbbbbbbbaabbbaaaaaaababbaaabaabababbababbbbaabbbabaaabaa +abbbabaaabbbbaaaabaaaaba +bbababbbbabaabbbaaaaababbbbaabbabaaaaaab +bbabbababbbbbbaaabaaaabbaabaaaba +baaaababbaababaaaabbbbababbbbabbbaaaababaaabaaba +babbbabaaababbbabaabbabaaabbabbb +aaababbbbaaaaabbbbaaabaa +baaababaabbaaabbbbaabbab +babaaaaabbaaaaaaabaaabaaaababaaabbabbbababbbaaaabbabaaaa +bababbaabbaaaaabbaabbaaa +aabaaabbaabbbabaaaabaaaa +bbaabababbaaaabbbaababababbbbaab +ababbabbabaaaabbbbbaababaaaaababbaababab +bbabbabbaabaabaaaaaaababaabaaaaabbaaabaa +bbabaabbaaabbbaababaaaaaaabbbabaaaabbbab +bbaaababbaaaabbabbaabababbabaaabbbbbaabaaabbabababbabbaabbababbabaaaabbb +aaababbaababbaaabaabbaaa +baababaaababbabbbabbbaab +aabababaaaabaabbbabaabbbbabbabab +bbbbbaaaaaaababbbabbbaab +aabaaabbbbaaabbbbaaabbbbbbbabaababababbbaababbbb +bbbbbbbaabaabbaaabaabbababbababbbbaabbaaabbabbbbababbabbabababbb +abbababaabaaaababaaabbaa +aababababaaaabaabaabaabb +ababaaaaaaaabbbbbbbbabba +babbaabbbababaababaaaaba +baaaaabbbaabaabbbaabbaaaaabbbaaaaabbabbb +aabaabbbabaaaabbbaabaabaaaaabaaababbabaa +aabbbabbabbaabbbababbababbbbbabbabbaaaab +bbaaaaaaaaaabbaaaabbaaaabaabbbaa +baaabaaaaaabbaabaaaaababaaaaabbbbaaabbababbabbabbabbbaaa +aaaaabbbabbababbabbbbbaaababbbababbaaabb +bababbbbaaabbabbbabbbbbbabbabbbaababbaab +baaaabaabaaaaaabbaaaabbbbbbbbbababbbbaabbababababbbabaaa +babbaaaaaabbaaababaabaaa +aaaaabbbbababaababababba +aabaaaabbabaaaaaabbaaaab +aaababbbaaaaabababbbbaba +aaaabaabbabaaaabbababbab +aaaaaabaabbbbbaabbaaabbabbbbbaabbbbaaabaabbbabbb +bbabababbbaaaaabbaaababbbaaabbababaaababbaababbaabaababbbaaaabaabbabbaaabbabbaba +bbbbbabbbbbaabbaabbbaabaaabaaabaaaaabaabbbaaaabaaabbbbaaababaaababbaabbbaaabaabbabbbabaa +bbbbbaaababbaabaaabbbaab +aaababbbabbbbbaababaaaab +aaaabaaaaababbbababbbabb +abbbaabaabbaabbbbbbbabbbbbbaabbabbaababaabbbabbabbbabbab +bbbabbaaabbabbbbbbaaabaa +aabbabaaaabbbababaaaabbb +bbabbabaaabbbabaabbaabbbabababaaaaaaaaaabaaabaab +babaabaaababbaaaaabaaaba +baaaabababaaabbbaabbaaaabaaabbaabbababaaabbaaabb +aaababbbbbbaaaaaababaabb +ababaaaababbbbabbabbabbb +aabbbabbbbaaabababababaaabbbaabbaababbba +aababaabbaaaaababbbaaaabbaaaaaabaabbbaaaabbbbbbbbabbabbaaabbaabbabababbb +babaabaaaaaabaaabaaabaab +baaababaaaaabaabaaaaabaa +babaaaaabbbbbbbbaabaabbaaaaaaabbaabbaaaababbbaaaaaabaabababbbbbaaaabbaaa +abaaabaabababaababbbaaaa +aabaabaabaabababbaabababbabbaababbababababaabbbb +abaaaabbabbaabbbabababbb +aaaabbaabbabaabbaaaaabaa +aaabaaabaabaabbabaaaabaabaaabbaa +bbbaabbbaaaaabbbbabababa +bbbaabbbaaabbbbbbaabaaab +aaaabbaabaabbbbaaabaaabbbaaaababbbbbbaaabaabbbabbaabbbbb +abbabaaaababbaaabbbaabaaabbbbbbabbbabbab +aabbbbbabaabbababbbbbaba +aaabbaabababbaaaaabbaaabababbbabaaabababaaaaaaab +aaabbbabbababbaaaaabbaba +abbaabaabbabbbbaaaaabaaabaaaaabb +bbaababaabbaaabaaaabaaaa +abaabbabbaaaababbbaabaab +abbbbbaabaabbbbaaaaabaaaabaaabbbabaaabaaaaaabbba +bbbbababbbbbbaabaaabbabb +baabaaaabaabaaaabaaababbaaaabbba +abbbaabbbbababaabbbaabbaaaabbabbbbbbaaabbbbbbaababbaaaabaaaababbaaaaabbbbbbbbaabbbaababaabaabaaa +bbbaabbbbabbaaaabaaabababaaabbababbaaabaabaabbababbbabbaabaaaabb +ababbbbaabbbbbaabaaabbba +abaabaabbbbaabbbbabaabab +bbaaaaababbbaabbaabbbabbaaabbbababaababaabbaabba +aabababababababaaaaaaaaabbbabbbabbbbaaabaaaabbbabababbbb +aababaaababbbbababbbbaab +abbaabaaaababbaababbbbbbaaabbabbaabaaaaabaaabbaaaabbaaaaaaababaaabbbbbbb +bababbaababbaaaabababaabbbbaabbbbaaaabbb +aaaaabbbbbaababbabbbbbaababaaaaaabaaabaabaabbaabbaababbbbabaababaabbabbbabaabababaabbaaa +abaabbbbbbabaabbbaabbabb +baaaabababbaaababbaaaaba +abbababbbbabbbbabbbbaaaa +aabbaabbabbbaababbaabbba +bbbbbaabaaaabbaabbaaabaa +baababbbabbbaaabaaaaaaaaaabababbbbabbbbbaababaababbbaababbaababb +abaabaabbbbaababbbbabbbb +ababaaaabaabaaaabababbbb +abbbbaababaababbbabbbabbbbbababaabaaababbbbaabaabbbbabaabbaabbbbabbabbaaababbaba +baabaabaabbabaababbbbabbaabbbabbaababaaabbabaaaabaaabbab +aabaaabbbababbaababbbbbb +bababbbabaabbaaababbaaabbaababbababaabab +babaabababbaababbbbababbbbbbbbbbaababaaababaabaababaabbbaababaaababbbababbbaabaaabbbabaa +abaaabbbbaabbbaaabaabaaa +bbbaaaaabbabbaabbaabbaaaabaababbababaabbbabaaaba +aababaaabaaaabaaabbababbaaaababbbabaabbbaabbbbababaabbba +babbaabaababbbbababbbaab +abbaaabaaabbaaabbbababbbabaaaabbaaabbbbabababbbabbaabaab +abbaaabbbaabaabaabaababb +aabbaabbaabbaaaaabaaaabbbaaabbabbaabbbbb +bbaabbbaabaababbbbabaabbaaabbaaabbbaaaaabbbbbbbabbaabbbbbbaaaaababaabbab +aababaabababbabbbabbbabb +bbbbaabbbabbbabaabbaaabbbaabbbab +bbaabbaaabbababbaabbbabaaaaaaaaabaababaabbbbbabababbbbbabababaaaabbbabbb +baabaabaaababaababbbabba +aaabbaabababaaaaaabbabaabbababba +ababbabaababaaaaabbbabba +aaaaababbabaabbaaabbaabaabaabbbaabaaaaab +baaabaabababababaabaaabababbbbbbabbbbaab +bbbababbbbababaaabbabaaaabababaa +babbaaaaaaabaaababaaaaba +abaaabbbbbabbabbbaaabababaaababaabbabbba +aaaaabbaaaabbaabbaababbb +aabbbabbbbabaabbaaabbabb +bbabbabbbbbbbaaaabaabbaa +aaaabaabbabbaaaabbaaaaabbabbbbabaabbabbbaabbabba +bbbbbbbbabbbbbaaaabaaabbaabaaabbaaabaaba +bbbbbbaabbbaaaababaaababbbaabbbaabbabbbbaabbbbaabbabaaaabaaaabbbabaababbbbabaabb +abbbbbaaaabaaabbbbbbaaba +baaababbbabbaabbbabbbbbb +bbbbaababbaabbabaababbbbbbabbbaa +aaabbbbbabaaaabbbbaaaaabbaaabaaabbabaaaaabbbbaabaabaaaaa +bbabaabababbbbbaabbaabab +abbbaababaaaabbaaaaaaaaaabaabbbbabbaaaab +baabaabbabaabbbbbbabaabaabaaaabbabbaabab +aaababbbabababaaabbaabaababaaabaaaabbaba +baabbbaabaaababaaababbaa +abbbbababababaaaaabbabbaababaabbbbaaabbaabbabababbbbbbbbbabbbabaabbaabbbbbaaabaabbabaabaababbabb +baaaaaaaaaaabbaabaabbbaabbaaaabbbaaabbbb +bbabbbbabbbaabaaaabbaababbaabaabbabbabba +aabaabbbababaabababaaabbaaabbabb +abababaaaaabbaababaaababbbababba +ababbaabbaababaabbbbabbbbbbbbabbaabbbbabbabbaaba +bababbbabaaababaabababbabbbbaabbbabababaabbbaabbbbaaaababbaaabaa +bbbaababbbbaabbabbbabaab +abbbaabaaabaaaabbaabbabb +bbbbbbaaaaaaaaaaaabbabba +aabbbbbabababbababbaabab +aababaabaabbbbbaaabbabba +aaaabaabbbbbbaaabbbbbbab +abbbaababaababaaaaabbbaabbbaabab +aabbaababbababbbbbaabbbbabbabbbb +aabaabaaaaaaababbaabbbab +aabbbbbaaabbbabbbbbbbbbbaabbabaababaaaaaabbaabbaaabbabbbabbababa +bbbbabbbbbbbababbabbbbaa +babbaababaaaabbababaabab +bbbaaaabbabbbababbabaaababbbabab +bbababaaaababaaaabbbaababbabbaaabaabbaaa +bbabaaabaaaabbababbabbab +aaaaaabbbbbabaabbbbabbaabababaab +aaaabaaabaaaababbbbaabaaabaabbba +aabaabbbabbabaaabbbbbabb +bbbaaabaaaaaabbbbaaabaab +bbaaabbabaababaabbbaabbabbaababbbbababaababbbbbb +bbaabbbbaabaaaabaabbabab +babbaaabbaaaaababbbaaabb +bbbaaabaababaabababbabba +bbbaaaabbababbabbaaaababbbaaabaabbabbbbb +babaaaaaabbabaaababbbbbbaabbabbbaaabbabbabaabababbabbbabaaabbbba +bbaaaabbabaaaaaabbbabaaa +aabaabbbaaaaabbaaabaabbbaaaaababababaabbbbbabaab +abbabbaabbbbbabaababaabbbbabbbab +aabaaabbbaabbaabbaabbabb +aabbaaabbaabaababbbabbab +aabbbababaaabababbbbaabbababbbbbaaaabbab +baababbaaabaaababaaaabbbbbabaaaabbbabbba +bbaaaaabbabaabaaaaaabbba +baabbaababaaaabbaaabbaaaaabababaababaabaabbbaabaaabababbbbabbbbbbabbbbaaaaaabbbbbaaaaaaa +abbbabbaaaaabaaabbbbaaaaaabbaaabaabbbababbbbbababbababbbabaaabbaabbaabaabbababbaaabbbbbbaabbaabb +bbbaaaabaabababaabbbbaba +aaabaaababaaabbbaabbabbb +ababaaabbaabaabbbbbaaaaaaaabbaaa +abbbbbaabbaaaaaabbbaaabb +bbaaababbabbaabbaabaabaababbaabaaababbab +abbabaababaabbabbabaabbbaaaabbbbbaabbaababaaabba +bbbbbbabbaaaaababababbba +aaaabaabbbabaabbbbbabaaa +baaaabbbbaaaaaabbabbbbaaabaababbaaaaaaab +aaaaaabbbbbbaaaaaabbabababbbbaabababbbaa +aabbbbbabaabbaabaaaaabbaabbabaaabbababaabbbbbaababbababa +aaaaaabbbaaaabbabbbabbaa +aababaabbbaaaaabbbbbabba +bbaaaaaaaaaaabbbbbbbaaaa +babbbbabaabbaaaabbaabbab +babbaababaabaabbbabbbababaaaabbabbbbaabbbbbbaaaa +bbaabbbbbabaabaabbabaaaa +ababbbbaaaabaabbbbabbabaabbababa +baabaabbabbaabbbbbababba +aabbaabbaabbaababbaabaab +ababaaabbabaaaaaaaaaabaa +baabaabbbbaabbbbbbaaaaba +bbbababbbbbabababbbabaabbabaaababaabbaaabbabbbabbbababab +abbbaaaaaaaaabaabbabbbbb +bbbaabbbabbababbbaababaabaaaabaaaaaaabaa +ababbbbababbbbababbbabba +aaaaababbbaabababbabbbaa +aaaaaabbabaaabaababaabaababaabba +babaaaabababbababbbaaaaaabbaabbbaaaabbab +bbbbaaaababaaabababaabba +abbbaabaaaaabbbbabbababa +bbbbabbbbbaababbbabababb +aaaabbaabbbaabbbabbbaaaa +aabaabbabbbbbbaaaaabbaaa +abbaaabbbaaaababaaababbaaaaabaaaaaaabbab +abbaaaaaaaaabaaaababaaabbbaaabaa +ababaabaaabbabaabbbbaaba +bbbbabbbabbabaabbbbabbba diff --git a/2020/19/solution1.js b/2020/19/solution1.js new file mode 100644 index 0000000..28ee2cd --- /dev/null +++ b/2020/19/solution1.js @@ -0,0 +1,48 @@ +const fs = require("fs"); + +let [rules, messages] = fs + .readFileSync("input", "utf-8") + .trim() + .split("\n\n") + .map((part) => part.split("\n")); + +rules = rules + .map((line) => line.split(": ")) + .map(([num, rule]) => [parseInt(num), rule]) + .sort((a, b) => a[0] - b[0]) + .map(([_, rule]) => rule); + +console.log(rules); + +console.log("="); +// console.log(messages); + +function getRegex(idx) { + const rule = rules[idx]; + if (rule.startsWith('"')) { + return rule.slice(1, rule.length - 1); + } + let regex = ""; + let multiple = false; + for (const symbol of rule.split(" ")) { + if (symbol === "|") { + regex = "(" + regex + "|"; + multiple = true; + } else { + regex = regex + getRegex(parseInt(symbol)); + } + } + regex = multiple ? regex + ")" : regex; + rules[idx] = '"' + regex + '"'; + return regex; +} + +const regex = new RegExp(`^${getRegex(0)}$`); +console.log(rules); +console.log(regex); + +let sum = 0; +for (const message of messages) { + if (regex.test(message)) sum++; +} +console.log(sum); diff --git a/2020/19/solution2.js b/2020/19/solution2.js new file mode 100644 index 0000000..5dabf48 --- /dev/null +++ b/2020/19/solution2.js @@ -0,0 +1,73 @@ +const fs = require("fs"); + +let [rules, messages] = fs + .readFileSync("input", "utf-8") + .trim() + .split("\n\n") + .map((part) => part.split("\n")); + +rules = Object.fromEntries(rules.map((line) => line.split(": "))); + +// unecessary, but might reveal an overlooked loop +rules["8"] = "42 | 42 8"; +rules["11"] = "42 31 | 42 11 31"; + +// console.log(rules); +// console.log(messages); + +function getRegex(idx, visited = []) { + const rule = rules[idx]; + if (rule.startsWith('"')) { + return rule.slice(1, rule.length - 1); + } + let regex = ""; + let multiple = false; + for (const symbol of rule.split(" ")) { + if (symbol === "|") { + regex = "(" + regex + "|"; + multiple = true; + } else { + regex = regex + getRegex(parseInt(symbol), visited.concat(idx)); + } + } + regex = multiple ? regex + ")" : regex; + rules[idx] = '"' + regex + '"'; + return regex; +} + +// Rule 0 is "8 11" +// These rules are the only looping rules through self referencing +// rule 8: 42 | 42 8 +// expects rule 42 one or more times +// rule 11: 42 31 | 42 11 31 +// recursively expects R42 R11 R31 +// translated: +// expects rule 42 one or more times followed by 31 by the same quantity +// combined: +// rule 0: 8 11 +// start of string matches 42 (one or more) +// end of string matches 31 (one or more) +// the quantity of R42 matches has to be more than the quantity of R31 + +const rule42 = getRegex(42); +const rule31 = getRegex(31); +const possibleEndings = []; + +// 10 is a guessed maximum repetition based message length +// if this value is too high the regex wont compile +// for larger messages a recursive approach is necessary +for (let reps = 1; reps <= 10; reps++) { + possibleEndings.push(`((${rule42.repeat(reps)})(${rule31.repeat(reps)}))`); +} +const patternRaw = `^(${rule42})+(${possibleEndings.join("|")})$`; +// console.log("Pattern:", patternRaw); +console.log("Compiling RegExp..."); +const pattern = new RegExp(patternRaw); +console.log("done."); + +console.log("Checking messages..."); +let sum = 0; +for (let message of messages) { + if (pattern.test(message)) sum++; +} +console.log(sum);