Completed day 19 part 1
Part 2 is failing the example and I have no idea why :(
This commit is contained in:
parent
77b0b1901b
commit
2fb9b4ed4a
21
day19/Cargo.lock
generated
Normal file
21
day19/Cargo.lock
generated
Normal file
@ -0,0 +1,21 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68803225a7b13e47191bab76f2687382b60d259e8cf37f6e1893658b84bb9479"
|
||||
|
||||
[[package]]
|
||||
name = "day19"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"maplit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maplit"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
|
11
day19/Cargo.toml
Normal file
11
day19/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "day19"
|
||||
version = "0.1.0"
|
||||
authors = ["Tyler Hallada <tyler@hallada.net>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.36"
|
||||
maplit = "1.0.2"
|
613
day19/input/input.txt
Executable file
613
day19/input/input.txt
Executable file
@ -0,0 +1,613 @@
|
||||
19: 33 53 | 123 7
|
||||
3: 33 82 | 123 45
|
||||
92: 47 123 | 91 33
|
||||
34: 123 60 | 33 63
|
||||
91: 123 9 | 33 7
|
||||
20: 33 46 | 123 79
|
||||
101: 33 27 | 123 56
|
||||
47: 52 33 | 84 123
|
||||
115: 116 33 | 7 123
|
||||
41: 57 33 | 127 123
|
||||
33: "a"
|
||||
109: 123 89 | 33 33
|
||||
106: 33 72 | 123 6
|
||||
8: 42
|
||||
104: 92 123 | 41 33
|
||||
75: 123 22 | 33 100
|
||||
21: 76 123 | 28 33
|
||||
102: 95 33 | 81 123
|
||||
54: 33 44 | 123 2
|
||||
77: 123 13 | 33 116
|
||||
1: 33 26 | 123 34
|
||||
83: 123 90 | 33 66
|
||||
11: 42 31
|
||||
58: 9 33 | 63 123
|
||||
136: 33 74 | 123 109
|
||||
25: 59 123 | 52 33
|
||||
17: 123 91 | 33 136
|
||||
116: 89 89
|
||||
32: 116 33 | 53 123
|
||||
72: 9 123 | 111 33
|
||||
70: 33 9
|
||||
80: 33 20 | 123 1
|
||||
18: 111 33 | 74 123
|
||||
86: 33 122 | 123 55
|
||||
14: 33 108 | 123 37
|
||||
84: 33 33 | 123 123
|
||||
67: 6 123 | 18 33
|
||||
78: 123 58 | 33 96
|
||||
38: 111 123 | 52 33
|
||||
119: 125 33 | 77 123
|
||||
69: 33 32 | 123 64
|
||||
10: 110 123 | 3 33
|
||||
118: 69 33 | 107 123
|
||||
85: 123 62 | 33 17
|
||||
61: 33 117 | 123 93
|
||||
62: 70 123 | 117 33
|
||||
4: 123 52 | 33 7
|
||||
52: 123 33
|
||||
40: 84 123 | 60 33
|
||||
49: 123 47 | 33 65
|
||||
79: 13 33 | 84 123
|
||||
6: 7 33 | 116 123
|
||||
113: 33 133 | 123 115
|
||||
98: 116 89
|
||||
53: 123 123
|
||||
42: 33 35 | 123 21
|
||||
44: 33 15 | 123 55
|
||||
100: 123 67 | 33 121
|
||||
27: 88 33 | 9 123
|
||||
76: 33 23 | 123 85
|
||||
16: 33 24 | 123 73
|
||||
9: 123 33 | 33 123
|
||||
26: 109 123 | 59 33
|
||||
36: 7 33 | 52 123
|
||||
50: 123 88 | 33 63
|
||||
65: 59 33 | 84 123
|
||||
105: 9 123 | 7 33
|
||||
112: 74 33 | 60 123
|
||||
120: 111 123 | 84 33
|
||||
23: 106 33 | 126 123
|
||||
110: 104 123 | 102 33
|
||||
128: 33 12 | 123 5
|
||||
31: 123 114 | 33 10
|
||||
30: 57 123 | 98 33
|
||||
82: 33 51 | 123 128
|
||||
125: 7 123 | 9 33
|
||||
99: 123 120 | 33 93
|
||||
87: 52 123 | 59 33
|
||||
37: 33 101 | 123 16
|
||||
43: 123 7 | 33 88
|
||||
117: 123 63 | 33 7
|
||||
12: 33 88 | 123 53
|
||||
55: 33 111
|
||||
2: 123 132 | 33 38
|
||||
96: 33 116 | 123 7
|
||||
135: 33 109 | 123 111
|
||||
126: 112 123 | 36 33
|
||||
97: 111 33 | 60 123
|
||||
22: 33 113 | 123 48
|
||||
24: 74 33 | 84 123
|
||||
130: 91 33 | 103 123
|
||||
132: 33 109 | 123 53
|
||||
59: 33 89 | 123 123
|
||||
51: 123 40 | 33 50
|
||||
28: 54 123 | 68 33
|
||||
66: 33 111 | 123 52
|
||||
64: 13 33 | 9 123
|
||||
15: 33 13 | 123 111
|
||||
114: 14 123 | 75 33
|
||||
35: 123 131 | 33 39
|
||||
90: 60 123 | 52 33
|
||||
124: 33 32 | 123 71
|
||||
63: 123 123 | 33 123
|
||||
121: 33 97 | 123 19
|
||||
71: 116 123 | 53 33
|
||||
5: 33 53 | 123 63
|
||||
111: 33 33 | 123 33
|
||||
74: 33 123 | 33 33
|
||||
48: 94 123 | 105 33
|
||||
56: 111 33 | 84 123
|
||||
29: 30 33 | 130 123
|
||||
45: 99 123 | 119 33
|
||||
93: 52 33 | 52 123
|
||||
122: 33 9 | 123 7
|
||||
103: 13 33 | 63 123
|
||||
68: 61 33 | 49 123
|
||||
94: 33 88 | 123 129
|
||||
129: 89 33 | 33 123
|
||||
133: 123 59 | 33 129
|
||||
127: 33 74 | 123 59
|
||||
0: 8 11
|
||||
134: 78 123 | 83 33
|
||||
73: 111 33 | 116 123
|
||||
89: 33 | 123
|
||||
123: "b"
|
||||
131: 80 123 | 134 33
|
||||
81: 123 43 | 33 56
|
||||
7: 123 33 | 123 123
|
||||
13: 123 33 | 89 123
|
||||
60: 33 33
|
||||
108: 124 123 | 86 33
|
||||
39: 123 29 | 33 118
|
||||
95: 123 87 | 33 135
|
||||
88: 33 123
|
||||
57: 123 60 | 33 9
|
||||
107: 123 4 | 33 25
|
||||
46: 123 60 | 33 7
|
||||
|
||||
aababbaabaabbaaaaabaaabb
|
||||
aabbabababbabbbabaabbbaa
|
||||
aaaaabbababbbabaaabaabaaaaaaabaabababababaaabaabbbbbaaaa
|
||||
aaaaaababbaabbaaaabbaaab
|
||||
aabbbaababaabaaaabbbbaba
|
||||
bababaaaabaabaaabaababba
|
||||
aaabbabaababbaabaababaabbababababaababbbabaabbababababbb
|
||||
baaaabbabbaabbaabbbbaabb
|
||||
aabaaaaaababbaababaabbbb
|
||||
abaaabbababbabbbbaabbbaa
|
||||
baababbbbbbbbbabbaaabaaa
|
||||
aabbbaaabbbaaabababbaaabababbaabbaababaaabbbbbaa
|
||||
aaababaabbaabbabbaaaaabb
|
||||
abaaabbbabbabbbbbaabaaabbaaabaabaaaababbaaaaaaba
|
||||
abbbabbbabbbaabbbbabbabbbabaababbabbbbba
|
||||
babaaabbbaaabbabaabbbbaabaaababaaaaaabab
|
||||
babbabaabbaabbbbbbaaabab
|
||||
baabaabaaaabbbabbbbbbabb
|
||||
bbabbabbaabaaaaaaabaaabb
|
||||
bbaaaaabbbaaaaabaababbba
|
||||
aabbbbaaabbababbaabbaaab
|
||||
ababbbbababababaababaaba
|
||||
abbaababaabaaaaabaaaaaba
|
||||
abbbaababbbabbbaabbbabab
|
||||
baaaabaababbbbabbaaabaaa
|
||||
aabaabaabbaaaabbbbbbabbb
|
||||
aabababbbaabbabaabbbaaab
|
||||
abbabbbbbbabbaaaababaabbabbaababbabababbbbbaaaaaaababbbaabaabbabbabbbbaaaaababaabbbaabba
|
||||
bbbaabababbbbbbbaabaabbbaaabaabbbbbbbbbb
|
||||
aaabbaaaaaaaabaababaaabbbaaaaabb
|
||||
bbbababbaabbaabbaaaabbaabbabbaba
|
||||
aaababaababbbbabaababababbaabbaabbabbabbbaaaabababbabaaabbbbaaababbabaaa
|
||||
bbbababaababbbbbbbababababbbaabbaabaabbabbbaabab
|
||||
aabbbbaababbbbaabaaaaaaa
|
||||
baabbabababababaabbbaaaabaaaabbbaaaaabab
|
||||
aabbaabbbaaabbabaaabbbba
|
||||
abbaaabbbaaaabaabababbbb
|
||||
baabaaabaabbabaaaababaabbaaababb
|
||||
abbabbbbbbbabbbaabaabaabbabaaaab
|
||||
bbaabbbbbbbbbbabbababbbb
|
||||
bbaaaabbababaabbaaabbbaaaabbaaaaaabaabaaabbabaab
|
||||
aababbababaabaaababaaaab
|
||||
baaababaabbaabaaabbaabbb
|
||||
bbaabbaaaaaabbbaaaaababb
|
||||
abbbbaabbbbababbbababaab
|
||||
baaaaaabbbbabbababaabaaabbbabbbaaaaababb
|
||||
aabbabaaabaaaababbabaaaa
|
||||
aaaabbaabbababbaaababbba
|
||||
aaaabaabaababbabbbbabbba
|
||||
babaaabaabaababaaabaaaaabaabbbab
|
||||
aababaaaaabbaaaaaaabbabb
|
||||
aabbbabbabaaaaaaaabaaaab
|
||||
babaaabbabaabaabbbaabbaabaabbaab
|
||||
aaaaaabbbaabbabaaaaaaaba
|
||||
aabbbbaaabbaabaaaabbabaabbbaaaaabbababbababaabbb
|
||||
aabbaaaaabaabaaabbabababbbbabbbb
|
||||
baabaaabbabbbbabaaaaabbbaababbaabbbabbababaaaabbbbabbaab
|
||||
aababbabaabababaabaabbaa
|
||||
aababbbbaaababbaabbbbbbaaababaaaabaabbbabbaabaaabbbbbaab
|
||||
baabaaabbaaababaaabbaaaabaaabababbaabababaabbabb
|
||||
baaabbbaaaababbbaabbaaab
|
||||
bbaabbaaabbababbaaabbbbb
|
||||
aabbababbaababaabaaaaaabaababbaaaaabaaabaabaaaab
|
||||
aaaaaabbabbabbbbaaabaaaa
|
||||
babbbbabbabbaaabababaaaa
|
||||
abbaaaabbaabbbbbbbbbbbbabaabaaababbbbaababaaaaaabbaababa
|
||||
bbbababaaaababaabbaababa
|
||||
baabababbbaabbabbaaababaaabbbbabbaabbbab
|
||||
abaabaabaaabbababaabbbab
|
||||
baaaabaaabbbaabaaabbbbba
|
||||
aababaaaaabbbbbbababbaabababaaaa
|
||||
bbbabbabaabbbaaabbbabbbb
|
||||
baabbbbbaaaabbabababbaaabaabaabbbaaabaabbaaababbbaaaaaaaabbaabbbabbabaaabbbbaaba
|
||||
abaaaabaaaababbabbbbbbabbababbaa
|
||||
bbabbbabbababaabbaababbaababaababaaabaaaabbabaab
|
||||
aaababbaababbbbaabababaa
|
||||
aabbaabbbbababbabbabbaaa
|
||||
bbbabbbabaababbbbabbbbabbbabbaabbbbbabba
|
||||
abaaaaaabaaabbabaaaabbab
|
||||
bbaabaabbaaabbabbabbbbabbaabbbab
|
||||
baaabbbaaaabbbababbabaaa
|
||||
aabaaaaaababbbbaaaabbaaaaaabbabb
|
||||
baaababababababbaabaabaabaaaaaabababaaaaababbabbbaaaabab
|
||||
babbababbbbaaaaaaababaabaaaabaaababbaabababaabbabababbaa
|
||||
abbbbaabaabbbaaabaabbbbb
|
||||
babbaabbaaababaabbaaaabbbbaabbaaabaababbbaaaaabaaaaababb
|
||||
baababaaaaababaaababbababaababaabbabaabaaabbbaba
|
||||
abbaaabbbaaabbbbabbabbbbababbabaabbabbbababbbbbb
|
||||
babbaabbbbbabababbaababb
|
||||
baaabbaabababababbbabbbaaaabaaababaaaabb
|
||||
bbaaabbaaaabaaabbbaaabaabbabaaabaabbabbaaababbbbbbabbabb
|
||||
aaabbabababbbbaabbabbbbb
|
||||
aabbababaaabbbaaabbbbabb
|
||||
aababaabaaabbbaaaaabaabb
|
||||
ababbbbbbaabbabaaabbabbb
|
||||
baaaabaabbabbabbbbbabababbbababb
|
||||
abbabbbabbbabbbabbbbaabb
|
||||
bbbaaaabaababbbbbababbbb
|
||||
aaabaaabababbbababababbabbbababaabbaaabaaaaaabab
|
||||
bbaaaabaaabbaabaaabaabbbbabbabbbbaabbabaaababaaaaabbaabbbaabaaaabaaabbaabbabaaaa
|
||||
abbbabbaabaabbbbbbabaaab
|
||||
abbbabbbbabaaabaaaabbbbb
|
||||
abaaabbabbbbbbaaabaaabbbbbaababbababbabb
|
||||
ababbbbaaaabbaaaaabbabbb
|
||||
bababaaaabbaaabbbbaaaaba
|
||||
aaabbaaaabaaabbaababaaaa
|
||||
babaaababbbaabbbbbaaaaba
|
||||
aaababbabbabbbbabbbaababbbaaaaba
|
||||
baaaabaabaaababaaaabababaaaaabbbabaaaaaaabababaaabbbabab
|
||||
aaababbbabbbbbbabbbaaababaaaaaba
|
||||
abbabbbbbbbabababbbabaabbabbabaabbaaababaabaaabbabbbabab
|
||||
aaaaabaaaaaabbbababaaabaaabaabaabaaababb
|
||||
bbabababaabbbaabbaabaaaaabbabbaa
|
||||
bbbabababaababbbbbbabbabaabbaaab
|
||||
baabaaaabbababbabbbaabab
|
||||
bbababbabbbbbbbabaabababbbbaaaaabbbbaaaa
|
||||
aaabbabaaaaaaaaabbaabaaa
|
||||
babbababaaababaabbabbbba
|
||||
baababaabbaabaabababbbaa
|
||||
bbaabaabbaaabbaaabaaaabb
|
||||
baaabbaabbbaaabaababaaab
|
||||
bbbaaabaabaabababbaaaabbaaababbaabbbaabaaaaaabba
|
||||
babbabaaaabbaaaabaabbbaa
|
||||
babbaaabbbbaaababaaababaaabbbaaaaababaabaaaabaabbbbbaabbabaaaabbaaaaababbaaaaabb
|
||||
aabbbaaabbabbabbbbbbaaba
|
||||
bbabbbabbaaabbabaaabaabb
|
||||
bbbababaaababbbbaabaabab
|
||||
bbaabbbbbbbababbabbaaaaa
|
||||
aaabababbabbbbbaabbabbaaaaaababa
|
||||
aabaabaaaaaabbbbabbaababaaaaaabbaabbabba
|
||||
bbbaaaaaaababaaaaaabbaaabbaaabbabbbbbaabbabaabaa
|
||||
ababbbabbbbbbbaabbaaaaaa
|
||||
aaaabaabaabbabbbaabbbabaababbabababbbabbababaabbbaaaabbb
|
||||
aabbbbbbaababbbbbabbbabb
|
||||
babbbbaaaabaabbaaaaaaabbbabbbaaabbbbaabb
|
||||
abaaabbabbaabbbbaaaabaabbbbbabbb
|
||||
bbabbbababbaaabbabbabaab
|
||||
aaababaaaabbaabaaaaabbaaabbaababbbaaabab
|
||||
bbaabbbbaabbbbbbaaababbbabbbbbbabbbbaabb
|
||||
aababbabbaabaababbbbbbbabbbbbaaaaaabbaab
|
||||
abbaaabbbbbabaabbabaabaa
|
||||
aaabababbabababbbabbbaabbbaabbabbaababaaabbaaaaa
|
||||
baaabbbbaabbbbbbbbbaabaabbaaaabbaaaaaabbbbbabbaa
|
||||
aabaaaaaaaababababaaaabb
|
||||
bbbbbbaaabbaaabbabbbabba
|
||||
aaaabbbbaaaabbbbaaababba
|
||||
baaabbabbbbbbbabbababbaa
|
||||
aaabbbabbaabbaaabbabbbabbaabaaabaaabaaba
|
||||
baaaabbbabaaaabaabbaaaaa
|
||||
aabbabaaaaabbbaaabaaaabaababbbbaaabaaababbbbaaba
|
||||
bbabaababbbabbababaabbab
|
||||
aababbaabbaaaabbbbabbbba
|
||||
bbababbaaabbbabbbbbabaaabaaaabbbabbbabbbaaaabaababbbbbaa
|
||||
bbbbbbabbbabbbabaaabaabb
|
||||
babababababbbbaabbaaaaabbbbbbaaa
|
||||
baaabbbbbabababaaaaababa
|
||||
bbababbbbbaababbbabaabaa
|
||||
babaaabbabbbaabbbbabaabaaabbbaababbbaaabaabaabbbabaabbaa
|
||||
abaaababaaabbbabababbababbbbaaaa
|
||||
abaaaabaabaababaabaaaababbabababaaaaaaba
|
||||
abbbaaaabbaabaababbbabab
|
||||
abbababaaabbbbbbabbaaaaa
|
||||
baabbaaaaababbbbbbaaabaa
|
||||
baabbaaaaabbababaababbabbbbbbbbabbabbbabbbbbbababbabbbbbbbaaaabaaaaaaaab
|
||||
bbbaabbbababbabaaabbbaaabbbabbbbbbabaaaa
|
||||
aaaaaaaabbbbbbbaabbbbbaa
|
||||
bababababbbaaaaabbbaaaab
|
||||
bbabbabbbbaabbaaaabbabaabbbbbaab
|
||||
bbbaabbbbaaaabbbbbaabbabbbabbbba
|
||||
baabbabaababaabbaaabbaab
|
||||
aabbaababaababbbababbbaaaaaaaabbbbbabababaabbbbaabbabbba
|
||||
bbbaaababbabbbababababba
|
||||
aaaabaaaaababbabbbbbabababababbb
|
||||
babbbaabbbbaaaaabbabbbbb
|
||||
abbbbaabbbbababbbabbaaabaabbabba
|
||||
babbaabbaaababbbababbbabbabbaabbbabababbaababbbabbbbaaab
|
||||
abaaabbbbbbaaaaabaabbaaabbaabaaaabababaa
|
||||
baaaaaababbaababaaaabbbbbbabbbbb
|
||||
bababaaababaababaaababbbbabbababbbaabbaaaaabbbbb
|
||||
bbababbbbbaabbaaabaaaaaaababaaab
|
||||
abaaababaababbababaaaabb
|
||||
abaaaabababbbaabbbababbaaaabbbbaaababbba
|
||||
aaaaaabbbababaaababaaaaa
|
||||
bababaaaaabbababbbaaaabbabaabaabababaabaabbbaaab
|
||||
bbbbababbbbaabaaabababbb
|
||||
abaabababababaaaaabababbbabbaaba
|
||||
abababbbaaaaaabbaababbabaabaababaabbaabbaaabaababbbbbbba
|
||||
baaaaaabbbaabaabbbababbbbaaabaaa
|
||||
ababaabbbbaaaababbbbbaab
|
||||
aababbbbabbaaabbbbbaaaab
|
||||
baaabbbaabaaabbaaaaaabab
|
||||
bbbaabbbbabababbbbabaaaa
|
||||
aaaaabbbabaaabbbababaaab
|
||||
aaaabaabbaabbaaaaaaabbab
|
||||
abbaaabbbbbabbabbabaabba
|
||||
bbbbababaaabbaaaabbbbbab
|
||||
abaabbbaaababbbbababababbaabababbbababba
|
||||
baaaabbabbbbbbbaaabaabaabababaab
|
||||
ababbbabababbababbbbabababbabbbbbbabaaaaabbbbbab
|
||||
baabaaaabbbbbbababbbaaaabbabbbbb
|
||||
bbaabaabababaabbbaaaaabb
|
||||
abbababbbbbabababbbabbbaaaabbabaabbbaababaababaaabbbaaabbbabaaab
|
||||
baababaabbbabbbabbaaabbabaabaaababaabbab
|
||||
bbbababbabaaabbaaabaabaabbbaabaabaabaaababbababbbbbbaaaa
|
||||
baabaaabaabababaabbbaabbbabbaabbbbaabababbabbababbaaaaaa
|
||||
baabaababaabababbbababbbbbaabbaababaaabbaaaabbab
|
||||
bababbabaabaabbaabbaaaabbabaaabbababbbabbaababaabaaaaabaaabbbbabbbbbabaa
|
||||
babbaaabaababaaabaabaabb
|
||||
ababbbbabbbaabaabaaababb
|
||||
abbaaabbbbaabbaaaaaabbbababaaaaa
|
||||
aabbaabaaaaabbaaaaabaaaa
|
||||
babaabababbabbbabbbaaabb
|
||||
bbababbbabbbabbbbbaabbabbbbabbbaabbbbbbaabbbbbaa
|
||||
bbabababbbbabbabbbbabbaa
|
||||
bbbbbbbaabbababbbabbbbba
|
||||
baabaaaababbabaaaaaabbaaaaabbabb
|
||||
abaababaabbbaabaaaabbbaaabaababb
|
||||
baaaabbababbbbabbababbabababbaabbbabaabaabaababb
|
||||
abbaaabbbaababaaaabaaabb
|
||||
babbaaabbbababbaaabbbbab
|
||||
abbaaabbaaababbbabbbbaba
|
||||
baabbbabbaaaabbaaaaaabbaabbbbabbaaabaababbaaaaaababaaaaabbbbbaaa
|
||||
baababbaabbaabbbbbabbbaabbbbaabbbbbbaaaabababbbbaaaababaaaababbbaabbbbbabbbabbaaaabbabaa
|
||||
baabbaaaaaabbababababbabbaabbbab
|
||||
ababaabbbbbaabbbbabababbbabbbaaabbababbabaaababbababaaab
|
||||
bbabababbabbbaaabbabbbba
|
||||
bbaaaaababbababbaaaaaaaaaaabbbba
|
||||
aababaaabbbaaababbaabbabbaaababaabaabaaaaabaaaab
|
||||
babbabaabababbababbbabab
|
||||
aababbaabaabaaaaaabbaaaaabbbbaabbabbbabb
|
||||
bbabaababaaabbabbbbbbabb
|
||||
babaaabbababbababbbaabaaabaabbaa
|
||||
abbbbbbaaaaaaaaababaaaaa
|
||||
aabababaaabaaaaabaabbbaa
|
||||
abbaabaabaabbababbbaaabaaabbbbaabbbaaaaaaabaabaaabbbbababbabaaab
|
||||
abbabbabbbabaabaababaaaa
|
||||
babaababbababbabbbbbaaaa
|
||||
aabaabbaaaaaabaabaabbaaabbaabbbbbabbababaaabbbbaaaaaaabaaabbbababbbbbaaa
|
||||
baabaababbababbbbbbbbabaaabaaaaaaaabbbbbaaabababbbabbbbbbabbabaaabbbbaba
|
||||
abbbaabbabbaaaabbabaabaa
|
||||
aaaabbbbaabababbabbbaabaabbababaabababaaabbbbbababaababb
|
||||
baabaaaaabaabbbabbbabbaa
|
||||
abbbbaabbbbabbbaabbabbabaaaaabbbababaaab
|
||||
aaabababbbababbbbbbbbbbb
|
||||
aabaaaaababbbaababaabbab
|
||||
baaabbbaabbbaabaaabaaaaaabbabababbbaaaabbaabbbaa
|
||||
babbaabbababbaabbbbbaaba
|
||||
abbbbaababbbabbbaabbbabbabbbbbbbbaabbbab
|
||||
aaaabbaaaaaababaabaabbababababaa
|
||||
aabbababbbbabbabbabbbabb
|
||||
bababbabbbbbababaaaababa
|
||||
aaaaabaaaabababbabaabbbaabbaababaabaabbabbbabbaaaabaaaba
|
||||
aabbbabbabaaaababaababba
|
||||
aaaabbaaabbbbaabaaaababb
|
||||
bbababbbbabbababababaabbbaabaaaaaaaaabba
|
||||
aaabbaaaaababbbbbababbabbababbababaabbbaaaaabbab
|
||||
bbabbbabababbbabbaabbbba
|
||||
ababbbbaabbabbbbabbbbabb
|
||||
baaaabbbabaaaaaaabababaa
|
||||
bbababbabababbabbbabaabb
|
||||
aabbaabbabbababaabbaaaba
|
||||
abbbaaaaaaabbbbaababbabb
|
||||
bbbbbbaabbbaaaaabbabbbbb
|
||||
aabbabaaabbbaababbaababa
|
||||
abbbaabaabbaabaaabbbabba
|
||||
bbbabbabaabbbbaaabbbbbabbabbabbabbaaabab
|
||||
aababbaaaaaabbbabbbbbbbb
|
||||
abbabbabababbaabbabbbbbb
|
||||
baaaabbbbaaaaababbbbaaaaaababbba
|
||||
bbbbbbababbababaaabbaaab
|
||||
aabbaaaabababaaaaaababbaabbbbbab
|
||||
aabababaabbaababababbaaaabbaababbbaaaabbbaabbbba
|
||||
bbabababbabbabaaaabbbaabaabbbaababaababb
|
||||
aaaaabbbbbbbbbaaabbbaaab
|
||||
abbbbaabbaaabbaaabababaa
|
||||
babbbbaabbaaaaabbbaaaaba
|
||||
aabbaabababbbaaaaababaaaaababbabbaaabaab
|
||||
baaaabbaaaaabaaaaaabaaba
|
||||
bbaaaabbaabbababababaaaa
|
||||
aaaabbaabaababbbaabbbbba
|
||||
babaaabaababbaabbababbbb
|
||||
abbbaaaaaababaabbabbabaaaaaabaabaaabaababaaaaabb
|
||||
baabaaaabbaaabbaababababbbbaabaabbaaaaaa
|
||||
bbbbbbababbbaababaabbabb
|
||||
aababaababaaaababbbabbaa
|
||||
ababbababbababbbbbaaaabbbaababbabaabbbaa
|
||||
babbbbaababbaaabbbaaaabbaabbbaaabaaabbbabbaababb
|
||||
bbbbaabbaaabbbbbaaaaaaabbabaaaab
|
||||
abbbabbbbaabaabaabbbabaa
|
||||
ababbaaaaabbaababbaabbbbaabbabbaababaaba
|
||||
aababbabaaaabaababaabbaa
|
||||
abbababbabbabbbaaabbbbab
|
||||
babbbbabbaaaababbababbaa
|
||||
aaabbbbaabbbbaaaabbabbaabbabbbbaaaabaabb
|
||||
ababbaaaaabbbabbbbbabbbb
|
||||
abaaaababbbbbbbabababbabaaabbbabbbbaabbbbbaabbba
|
||||
ababbaababbaaabbbbbabbaa
|
||||
baabaabaabaaabbaaaaaababaabaabababbbabbbbbabbbabababbbbabaaaabba
|
||||
baabbaaabaaabbaaababaaaa
|
||||
bbababbaaaaaabaabbbabbaa
|
||||
babbaaabbabaaabbbbabaaab
|
||||
aaaaaaaaabbbaabbabaaaaaaababbaaabbabaaab
|
||||
ababbbbbbababbbaaabaaabb
|
||||
baaabbaaaaabbaaaabbabaab
|
||||
aaaaabbbbabaababaababaabaababaaaaaabbbba
|
||||
abaaababaabaaaaaabbbbbbabbbbaabb
|
||||
abaaabababbababbaababbabbaabbbaa
|
||||
aabbbaabbababababaababba
|
||||
abbbaababbbababbabaabbbbabaabbabbabbaaaabbabbbababbbbbbaaabbbabbbaaaabbb
|
||||
abbabbbabaaabababbaababb
|
||||
aaabababaabaabbabbaababa
|
||||
babaababbbbaabaaaaababbbbababbba
|
||||
babababbababbbbababbaaaa
|
||||
aaaabbbbabbbbbbabbbbabbb
|
||||
abbbaabaaaaaabbbbabbabbb
|
||||
baaabbaaabaaababaabbbabbbaaabbbaaaaaabbb
|
||||
bbbabaaaaaabbaaabbaaabaa
|
||||
abbbaababaabaababaabaaaabbaaabbb
|
||||
babaabababbbaabbbbbababbabbaaabbbbababababbabaaabababbaabbaabaaabbbbbabb
|
||||
bbbbbbbabaabaaabbababbbb
|
||||
aaababbbbaabbababbabbbaa
|
||||
aaabbbabbaaaabaaaaaaabab
|
||||
babaaabaaababbbbbaaaaabb
|
||||
abbaaaababbaabaabaabbbbb
|
||||
aaababbabbaaaabbbaababba
|
||||
aaababbaabaaaababbaaabab
|
||||
aaaaaaaabbabbabbbbbaabba
|
||||
aaabaabbbbabaaababaaaabbbbbbbabbbabaaaaabaabbaaaabaaaabbaaabbbaabbaaabbb
|
||||
aaaabaaabaabbabaabbababaabaabbbbbbbabbaa
|
||||
abaabaaaabbbaaaaabbaabbb
|
||||
aabbbbbbbbbbbbbaaabbaababababaaaababaaab
|
||||
aaababaabbbaabaabaaabababbbbbbababaabbabbbbbbaaa
|
||||
aabbababaaaaaabbbabaaabbbabaaabababbbbba
|
||||
abababbabbbaabbaabbaabbaabaaabbaaabbbaab
|
||||
babbabaaabaaabbaaabbbaaaababbbababbbbabbabbbbaba
|
||||
aaababaabbbbababbabbbaabbbababbabbabbbba
|
||||
aaababbbbaaabbaaaaaababa
|
||||
aaaabbbbaaabbabababbabaabbaaabaa
|
||||
bbabaababbaabaabbaabbabaabbbbbbababbbbbababbabba
|
||||
ababbbabbababbabbabbbbba
|
||||
abbaaaabaabbbbbbbbabaaaa
|
||||
baabbaaaaaaaabaabbaababa
|
||||
bbbabaaaaabababaabbbabbbbaaababababbabaababaaaaababbabba
|
||||
bbbabbbababaabababbbbabb
|
||||
aaabbbabaabaabaabbbbbbba
|
||||
aaaaabaaababbaaabbbaaaab
|
||||
bbaaabbaaaaabbbaaaaaaaab
|
||||
baaabbaaabbabbabbaaaaaaa
|
||||
aaaabbbbbbbababbaababbba
|
||||
aaaaabaaaababbaaaabbbabbbbabbaab
|
||||
aabbababaababbbbbaabaaabbaabbbbb
|
||||
aabbaaaaabbaabababaaaaaaaaabbbaabbbbbabb
|
||||
abaabbbaababbaaabbbbbbaaaaaaabaabbabbaaa
|
||||
aaaabbaabaaaabbbabaabaabaaabbbabababaaaabbbbabbabbbbabaa
|
||||
baaaabbbbaaabbbaabababaa
|
||||
bbbbababbbbabbabbaaaabbaabbbaaaababbbbbbbbababaabaaaabab
|
||||
baaabbbbabaaabbbaaababaaabbabbbaaaaaabba
|
||||
bbabaabaaabbabaabbabbaaa
|
||||
abaaabbaabbaabaababbbbaaaabaabab
|
||||
abaaabbaaaabbbaabababbbb
|
||||
bbabbbabbaabbabaaaabababbbaabbbaaabbbbba
|
||||
babbbaaaabbabababaaabaaa
|
||||
bbbbbbbaaaaaabbbbbbbbaaa
|
||||
aabbaaaabaaaabaabbbaaaaaaabaaaab
|
||||
baababaabaaabbabbababaaaababbabaabbbbaba
|
||||
aabbaaaaabbaabaabaabbbaa
|
||||
abbbaabaababbbabaabbaababababbba
|
||||
abbbbbbabaaabbababbbbaabbbabbaabbbaaabaa
|
||||
aaabbaaaaabbbabbbabaabba
|
||||
aaababbbbaabbaaabaaaabbaaabaabab
|
||||
baababbbababbbabbaabbbab
|
||||
abbbbbbaaaaaaabbaabaaaaaabaaaabb
|
||||
aabaabbaaabbaababbbababbaaabaaab
|
||||
aabababababbbbabaabaabaabaabbaaaabababbaaabbabbbbbaaabaa
|
||||
baaabbbaaaaaaaaabbabaaaa
|
||||
baaaabaaabaaabbaabbabbaa
|
||||
aabbaaaaabbaaabbbabbbbba
|
||||
bbbabbbaaaaaabbbbbbbbaaa
|
||||
aababbaaabaaaaaaaaaabbbababbaaaa
|
||||
ababbbbabbaabbabbbabbbbb
|
||||
babbbaabababababbaabbabb
|
||||
aabbbbaabbbabbbaaaabaabb
|
||||
babaaabaaabaaaaabbaaabab
|
||||
aabbabbabbbbaababbabbbbbbbbbababaaabbaab
|
||||
bbbababbaababaababababbb
|
||||
bbaabbbbbbbbbbbaaabbbbaaabaabbbaaaabaababbaabaaa
|
||||
baaabbbaabbaaabbbabbbbba
|
||||
ababaabbabaaababbbaaaaababbaaabbbaaaabaabaaaaaaa
|
||||
bbabababbbbaaaaaaabbaaaabaaababbbaabbbab
|
||||
ababaabbabaabbbababbbbbb
|
||||
baabaaaabbaabbabbaaabbaaaaaabbbabbaabaaa
|
||||
babaaabbbaaabbbbbaaaabbbbabbbbbb
|
||||
abaababbbbaabbbaaabaabab
|
||||
bbaaabbaaaabababaaaaaaab
|
||||
abaabababaaaabbbbabaaaaa
|
||||
bbababbbabbbbbbaaaaaaabbbababaaabbbbbaba
|
||||
abbbbbbabbaaaaabaabbbaabaaabaaaa
|
||||
abbaabaabbbabababbbbabaa
|
||||
bbabbbabaaaaabbbbaaabaaa
|
||||
ababbbbaaaabbbababbbaaaabbaabbba
|
||||
babbbaabbaaaaaababbbabab
|
||||
baabababaabababbbbabababbabaababbbabbaababbbbaaa
|
||||
bbbaabaabbbbbaabbbabbaabababbabaaabbbbaaaabbbbabbaabbaaaaababbbababaaabb
|
||||
aabbaabaabbbbaabbbaaabaa
|
||||
baaaabaaaabababbbbbabbbabbbabbaa
|
||||
aaaabbbaabbababaaabaaaba
|
||||
babbbbabaabbabaabaaabaaa
|
||||
baaababbbbabbabbabaaaaabbaababbaaabaaaaaaabbaaaa
|
||||
bbababbbbbbaaaaabbbaabbbbbbbababbababaab
|
||||
aababaabababbaaabbbabaaabbabaabaabaaababbabaabbabbababaa
|
||||
aaababbbbbababbaaaabababababbabaaabaaaab
|
||||
bbaaaabbabbaabababbbabbbaababbabbabbbaba
|
||||
bbbabaababaaabbbbabaababbabbaaababbbbaba
|
||||
abbbaababbbabaababbbbbaa
|
||||
ababbbabbaabaaabaaabababaababbba
|
||||
bbabbbabbabaabbbabaaabaaaaaaaaab
|
||||
bbaabbaaaaabbababbaaaaabaabbbbaaabaaabaa
|
||||
aababaaaababbbabbbbabbaa
|
||||
aabbbaaaaabaabaabbaababb
|
||||
abaabababababaaaabbabbbbbabbbbbb
|
||||
bbaaaaabbabaaabbaaabbabaabaaaabbababbabb
|
||||
ababaabbaabbbabbbbbbbaaa
|
||||
abbabbbbabbabbbbabbbabab
|
||||
bbabbabbabbabbbababbabaaabbabbbbaaabaabb
|
||||
ababbababbbaaaaabbaabbaaabaabababaabababbaaaabaabbbabbaa
|
||||
bbabababbbbaabbbbbabbbba
|
||||
abbaabbaabbbbbabbabbababbbbabbbababbbaaaabbbbabbaaabbaabbbbbbaba
|
||||
aaababbabbbaabbbaaaabbab
|
||||
aabbaaaaababbabaabbbabbbaaabbbababbaaaba
|
||||
baaabbbabbbabbababbbaaab
|
||||
aabbabaabbbaaaaababbbbaaabbababbbbabbaaa
|
||||
bababaaaaababbaabbaababb
|
||||
aabbabaababbbaaababbaaaa
|
||||
bbbabaababaaaabababbbaba
|
||||
ababbbbbabbbaaaabbbabbbb
|
||||
babaabaabaabbbbaaaabaabbbaaababaababbaaaaaababaaaaabababaaabaaaa
|
||||
bbbbabababaabaaaaabbbaaabbaaaaabbabbabbabaaaaaaa
|
||||
abbaabaaabaabaabbbaaabbb
|
||||
ababbabaaaabbbabbabaabaa
|
||||
bbbababbaaaaabaabaaaabaabbbbabaaaabbabba
|
||||
bbabaabaaabbaabababbabbb
|
||||
baababababbbaabbbbbbaaabbabbaaba
|
||||
aababababaaabbaabbbabbbabbbbabba
|
||||
aaababaabaabaabababbbbabbababababbabaabb
|
||||
abbaaabbabbbaaaabbbaabaaaababbaabaaaaabb
|
||||
aabbaabbaabaaaaaabababbb
|
||||
ababbbbbbbaabbaabbabaaab
|
||||
bbaaaabbbbabababbaabbaab
|
||||
aabababbaaabbbabbbabaaaa
|
||||
abaabaaaabbabbbaaaaabbbababbbbba
|
||||
baaababaaabbabaaabababba
|
||||
ababaaaabaaabbababaabbaaabbbbbbabbababbaaaaabbbaaaaaaaabaabbbaaabaabbbba
|
||||
aababaabbaaabbbabbaaaaba
|
||||
baababaaabbbaaaaabbbabab
|
||||
ababbbabaaaabaaaaabaabbabbbababaaaaababbbaaababbabaabbbb
|
||||
aabbbabbaaababaaabbbbaaa
|
||||
aaaaaabbaaababbabbbbbaaa
|
||||
aabbaaaabaaaaaabbbaabbba
|
||||
abaabbbabbbaabbbbbabbaab
|
||||
bbabababbaabbaaaabaabbbb
|
||||
ababaabbaaaaaaaaababaabbabbbaabbbababbbbbbabaaaa
|
||||
aaabababaaaabbbaaabbbbaaababbbbabbaabababaaaaabb
|
||||
aaabbbabaaaaaabbbaabbbbb
|
||||
baaabbbababbabaaaabbbbba
|
||||
baaabbbabbabbabbbbbabaabababababbabbbbbaabbaaaba
|
||||
aaaabaaaaababbababbabaab
|
||||
baaaaaabbbbabaaabaababaaabbabaabaaabaabb
|
||||
bbabbbababbbaaaabbbbbabb
|
||||
aaababaabaaaaaababbbabaa
|
||||
bababaaaaabababbbaabbbaa
|
||||
aababaaababaaabbaabbbbab
|
||||
abaababaaaaabbbbabbbbbaa
|
||||
babaababaababbababbbbaaa
|
||||
ababbbabbaaaabaababbbbabbaaaabbababaabaabbbbaaabbbbbabba
|
||||
aabbaabaababaabbaaababaaaaaaaabbaaaaabbbabbabaab
|
12
day19/input/test1.txt
Normal file
12
day19/input/test1.txt
Normal file
@ -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
|
47
day19/input/test2.txt
Normal file
47
day19/input/test2.txt
Normal 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
|
15
day19/input/test3.txt
Normal file
15
day19/input/test3.txt
Normal file
@ -0,0 +1,15 @@
|
||||
0: 1 | 2
|
||||
1: 3 | 3 1
|
||||
2: 3 4 | 3 2 4
|
||||
3: "a"
|
||||
4: "b"
|
||||
|
||||
a
|
||||
aa
|
||||
aaa
|
||||
b
|
||||
ab
|
||||
aabb
|
||||
aaabbb
|
||||
aaaabbb
|
||||
aaabbbb
|
220
day19/src/main.rs
Normal file
220
day19/src/main.rs
Normal file
@ -0,0 +1,220 @@
|
||||
use anyhow::{Context, Error, Result};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::str::FromStr;
|
||||
use std::time::Instant;
|
||||
|
||||
const INPUT: &str = "input/input.txt";
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
enum Rule {
|
||||
Char(char),
|
||||
Seq(Vec<usize>),
|
||||
Or((Vec<usize>, Vec<usize>)),
|
||||
}
|
||||
|
||||
impl FromStr for Rule {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
if s.contains("|") {
|
||||
let mut rule = s.split(" | ");
|
||||
let left = rule.next().context("Failed to parse OR rule left side")?;
|
||||
let left = left
|
||||
.split(" ")
|
||||
.map(|num| Ok(num.parse()?))
|
||||
.collect::<Result<Vec<usize>>>()?;
|
||||
let right = rule.next().context("Failed to parse OR rule right side")?;
|
||||
let right = right
|
||||
.split(" ")
|
||||
.map(|num| Ok(num.parse()?))
|
||||
.collect::<Result<Vec<usize>>>()?;
|
||||
Ok(Rule::Or((left, right)))
|
||||
} else if s.contains("\"") {
|
||||
let c = s
|
||||
.chars()
|
||||
.skip(1)
|
||||
.next()
|
||||
.context("Failed to parse rule char")?;
|
||||
Ok(Rule::Char(c))
|
||||
} else {
|
||||
let nums = s
|
||||
.split(" ")
|
||||
.map(|num| Ok(num.parse()?))
|
||||
.collect::<Result<Vec<usize>>>()?;
|
||||
Ok(Rule::Seq(nums))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_indexed_rule(s: &str) -> Result<(usize, Rule)> {
|
||||
let mut rule = s.split(": ");
|
||||
let index = rule.next().context("Failed to parse rule index")?.parse()?;
|
||||
let rule = rule.next().context("Failed to parse rule")?.parse()?;
|
||||
Ok((index, rule))
|
||||
}
|
||||
|
||||
fn string_matches_rule<'a>(
|
||||
s: &'a str,
|
||||
rules: &HashMap<usize, Rule>,
|
||||
rule: &Rule,
|
||||
ends: bool,
|
||||
) -> (&'a str, bool) {
|
||||
if s.is_empty() {
|
||||
return (s, false);
|
||||
}
|
||||
match rule {
|
||||
Rule::Char(c) => {
|
||||
if s.len() < 1 {
|
||||
(s, false)
|
||||
} else if s.chars().next().expect("non-empty string") == *c {
|
||||
let rest = &s[1..];
|
||||
if !ends || (ends && rest.is_empty()) {
|
||||
(rest, true)
|
||||
} else {
|
||||
(rest, false)
|
||||
}
|
||||
} else {
|
||||
(s, false)
|
||||
}
|
||||
}
|
||||
Rule::Seq(seq) => {
|
||||
let mut rest = s;
|
||||
for (i, rule_index) in seq.iter().enumerate() {
|
||||
let result = string_matches_rule(
|
||||
rest,
|
||||
rules,
|
||||
&rules[rule_index],
|
||||
if i == seq.len() - 1 { ends } else { false },
|
||||
);
|
||||
if !result.1 {
|
||||
return result;
|
||||
}
|
||||
rest = result.0;
|
||||
}
|
||||
(rest, true)
|
||||
}
|
||||
Rule::Or((left, right)) => {
|
||||
let result = string_matches_rule(s, rules, &Rule::Seq(left.to_vec()), ends);
|
||||
if result.1 {
|
||||
return result;
|
||||
}
|
||||
let result = string_matches_rule(s, rules, &Rule::Seq(right.to_vec()), ends);
|
||||
result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn solve_part1(input_path: &str) -> Result<usize> {
|
||||
let file = File::open(input_path)?;
|
||||
let reader = BufReader::new(file);
|
||||
let mut lines = reader.lines();
|
||||
let mut rules: HashMap<usize, Rule> = HashMap::new();
|
||||
loop {
|
||||
let line = lines.next().context("Unexpected end of input")??;
|
||||
if line.is_empty() {
|
||||
break;
|
||||
}
|
||||
let (index, rule) = parse_indexed_rule(&line)?;
|
||||
rules.insert(index, rule);
|
||||
}
|
||||
|
||||
let strings: Vec<String> =
|
||||
lines.collect::<std::result::Result<Vec<String>, std::io::Error>>()?;
|
||||
|
||||
Ok(strings
|
||||
.iter()
|
||||
.filter(|s| {
|
||||
let result = string_matches_rule(&s, &rules, &rules[&0], true);
|
||||
result.1 && result.0.is_empty()
|
||||
})
|
||||
.count())
|
||||
}
|
||||
|
||||
fn solve_part2(input_path: &str) -> Result<usize> {
|
||||
let file = File::open(input_path)?;
|
||||
let reader = BufReader::new(file);
|
||||
let mut lines = reader.lines();
|
||||
let mut rules: HashMap<usize, Rule> = HashMap::new();
|
||||
loop {
|
||||
let line = lines.next().context("Unexpected end of input")??;
|
||||
if line.is_empty() {
|
||||
break;
|
||||
}
|
||||
let (index, rule) = parse_indexed_rule(&line)?;
|
||||
let rule = if index == 8 {
|
||||
Rule::Or((vec![42], vec![42, 8]))
|
||||
} else if index == 11 {
|
||||
Rule::Or((vec![42, 31], vec![42, 11, 31]))
|
||||
} else {
|
||||
rule
|
||||
};
|
||||
rules.insert(index, rule);
|
||||
}
|
||||
|
||||
let strings: Vec<String> =
|
||||
lines.collect::<std::result::Result<Vec<String>, std::io::Error>>()?;
|
||||
Ok(strings
|
||||
.into_iter()
|
||||
.filter(|s| {
|
||||
let result = string_matches_rule(&s, &rules, &rules[&0], true);
|
||||
result.1 && result.0.is_empty()
|
||||
})
|
||||
.count())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut now = Instant::now();
|
||||
println!("Part 1: {}", solve_part1(INPUT).unwrap());
|
||||
println!("(elapsed: {:?})", now.elapsed());
|
||||
now = Instant::now();
|
||||
println!("");
|
||||
println!("Part 2: {}", solve_part2(INPUT).unwrap());
|
||||
println!("(elapsed: {:?})", now.elapsed());
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use maplit::hashmap;
|
||||
|
||||
const TEST_INPUT1: &str = "input/test1.txt";
|
||||
const TEST_INPUT2: &str = "input/test2.txt";
|
||||
const TEST_INPUT3: &str = "input/test3.txt";
|
||||
|
||||
#[test]
|
||||
fn parses_input() {
|
||||
let file = File::open(TEST_INPUT1).unwrap();
|
||||
let reader = BufReader::new(file);
|
||||
let rules: HashMap<usize, Rule> = reader
|
||||
.lines()
|
||||
.take_while(|line| !line.as_ref().map_or(true, |line| line.is_empty()))
|
||||
.map(|line| parse_indexed_rule(&line.unwrap()).unwrap())
|
||||
.collect();
|
||||
|
||||
assert_eq!(
|
||||
rules,
|
||||
hashmap! {
|
||||
0 => Rule::Seq(vec![4, 1, 5]),
|
||||
1 => Rule::Or((vec![2, 3], vec![3, 2])),
|
||||
2 => Rule::Or((vec![4, 4], vec![5, 5])),
|
||||
3 => Rule::Or((vec![4, 5], vec![5, 4])),
|
||||
4 => Rule::Char('a'),
|
||||
5 => Rule::Char('b'),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solves_part1() {
|
||||
assert_eq!(solve_part1(TEST_INPUT1).unwrap(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn solves_part2() {
|
||||
assert_eq!(solve_part1(TEST_INPUT2).unwrap(), 3);
|
||||
assert_eq!(solve_part1(TEST_INPUT3).unwrap(), 6);
|
||||
assert_eq!(solve_part2(TEST_INPUT2).unwrap(), 12);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user