1
0

Compare commits

...

10 Commits

24 changed files with 4246 additions and 0 deletions

372
18/input.txt Normal file
View File

@ -0,0 +1,372 @@
6 + (3 + 6 + 5 * 4) * (4 + 3) * 8 + 6 + 6
7 + 6 + (9 + 4 * (8 + 7 * 8 + 2 * 7 * 9) * 9 + 5 + 3) + 6 + (7 + 5 + 7 * 9 + 9) * ((4 + 9 * 3 * 4 * 3) + 6 * 8)
3 + (6 + 4 * (8 + 4 * 3 + 8) * 7 + 5 + 4) * 3 * 2 + 5 + 4
2 * 4 + 4 + (5 * 9 + 3 + 9) * 6 * 2
3 * 7 + 4 + 6 * ((8 * 9 * 2 * 9) + (9 + 3 * 6) + (3 + 4 * 8 + 2) * 2) * 2
(9 * 2 * 7 * 5) * (6 + 3 * 3 * 3) + 5 + 9
(7 * 2) + ((7 * 3 * 7 + 2) * 3)
2 + ((4 * 8) + 6 * (3 + 5) * 4 * (6 * 7) * 4) * 8 + (7 * 5 * (8 * 3 * 8) * 5) + 6 * 2
(2 * 4 + (4 * 2 * 2 + 3 + 8 * 5)) * (3 * 4 + 6 + 7 * 5) * 5 * 5 + 6 * 7
4 * 8
5 * (5 + (3 + 2 + 7 * 6)) + 4
(8 * 2) * 8 * 9 * 7 + (9 * 6 * 6 + 4) + 2
2 * (3 * 8 + (3 + 5) + 4) * 7 + 8 + 3
6 * 2 * 5 * 9 * 4
(5 + 5 + 5 * 2 + 3 + 8) * 5 * 2 + 9 + (8 + 8)
5 + 6 + 3 * (2 * (4 + 9 + 7 * 8) * 9 + 4 + 8) * (5 * 7 * 9 * 5 * (3 + 2 * 6 * 4))
3 + (2 * 4) + 8 * (3 + 5) + 9 * 8
((4 * 7 + 5 * 2 * 3 + 9) + 4 + 6 * 9 + 6 + (6 + 9)) * 4
2 + (2 + (2 * 6 * 3 + 2 * 6)) * 9 * 7 + (7 + 7 + 2) + 5
7 + 4 * 4 * 4 * 8 * 7
6 * (5 * (8 * 8 + 7) * (6 + 5 + 6 * 3 * 2) + 4) * 9 * 2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5 * 5) + (8 + 4 * 5) * 8 + 4 + 2)
((4 * 6 + 2 * 5 + 8) * 9 * 3) + 3 + 5 + 3
5 * 5 + (2 * 9 * 9 * 6) + 3 * 8
3 + 7 * 2
9 * (5 + 6 + 2 + (8 * 8 + 9 + 8 + 4 * 6))
(9 + 2 * 7 * 2 + 5) + (4 + 6 * 3) + ((6 * 4 + 4 * 2 + 5) + 8 + 6 * 6)
3 + (7 * (2 + 5 * 5 * 4 * 4 + 7) * 4 * 4)
8 + 3 * ((3 * 7 * 3 + 4 * 5) * (6 + 8 + 9 * 7 + 6) * 9 + 5 * (5 + 4 + 4 + 4))

106
18/main.py Normal file
View File

@ -0,0 +1,106 @@
import re
def getExpressions(filename):
with open(filename, "r") as f:
return f.read().splitlines()
def findMatchingPosition(line: str, pos: int) -> int:
depth = 1
end_pos = pos
while depth > 0:
end_pos += 1
if line[end_pos] == "(":
depth += 1
elif line[end_pos] == ")":
depth -= 1
return end_pos
def findMatchingParenthesis(line: str) -> list[tuple[int, int]]:
parens = []
for match in re.finditer(r"\(", line):
paren_start = match.start()
parent_end = findMatchingPosition(line, paren_start)
parens.append((paren_start, parent_end))
return parens
def determineTopParenthesis(parens: list[tuple[int, int]]) -> list[tuple[int, int]]:
top_parens = []
for i in range(len(parens)):
is_top_paren = True
for j in range(len(parens)):
if i != j and parens[i][0] > parens[j][0] and parens[i][1] < parens[j][1]:
is_top_paren = False
break
if is_top_paren:
top_parens.append(parens[i])
return top_parens
def evaluateExpression(expression: str):
parens = findMatchingParenthesis(expression)
top_parens = determineTopParenthesis(parens)
top_parens.sort(key=lambda p: p[0])
offset = 0
for paren in top_parens:
paren_start = paren[0] - offset
paren_end = paren[1] - offset
sub_value = evaluateExpression(expression[paren_start+1:paren_end])
expression = expression[:paren_start] + str(sub_value) + expression[paren_end+1:]
offset += (paren[1] - paren[0] - len(str(sub_value)) + 1)
parts = re.findall(r"(\d+|[\*\+])", expression)
result = int(parts[0])
for i in range(1, len(parts), 2):
if parts[i] == "*":
result *= int(parts[i+1])
elif parts[i] == "+":
result += int(parts[i+1])
return result
def evaluateAdvancedExpression(expression: str) -> int:
parens = findMatchingParenthesis(expression)
top_parens = determineTopParenthesis(parens)
top_parens.sort(key=lambda p: p[0])
offset = 0
for paren in top_parens:
paren_start = paren[0] - offset
paren_end = paren[1] - offset
sub_value = evaluateAdvancedExpression(expression[paren_start+1:paren_end])
expression = expression[:paren_start] + str(sub_value) + expression[paren_end+1:]
offset += (paren[1] - paren[0] - len(str(sub_value)) + 1)
parts = re.findall(r"(\d+|[\*\+])", expression)
i = 1
while i < len(parts):
if parts[i] == "+":
a = parts[i-1]
b = parts[i+1]
parts = parts[:i-1] + [int(a) + int(b)] + parts[i+2:]
i = -1
i += 2
result = int(parts[0])
for i in range(2, len(parts), 2):
result *= int(parts[i])
return result
def part1(filename: str) -> int:
total = 0
for expression in getExpressions(filename):
total += evaluateExpression(expression)
return total
def part2(filename: str) -> int:
total = 0
for expression in getExpressions(filename):
total += evaluateAdvancedExpression(expression)
return total
if __name__ == "__main__":
print("Part 1: ", part1("input.txt"))
print("Part 2: ", part2("input.txt"))

1
18/test.txt Normal file
View File

@ -0,0 +1 @@
(9 + (5 + 2 + 2 * 4) * (7 + 7 * 5 * 3) + 7) + 2 + 4 * 2 + 3 * (8 + 5)

605
19/input.txt Normal file
View File

@ -0,0 +1,605 @@
25: 6 54 | 28 122
52: 27 54 | 25 122
44: 118 122 | 30 54
37: 122 97 | 54 98
38: 122 22 | 54 3
77: 54 34 | 122 7
17: 122 124 | 54 47
1: 54 79 | 122 119
13: 122 121 | 54 15
29: 122 3 | 54 97
24: 54 97 | 122 62
80: 122 1 | 54 21
62: 54 54 | 122 54
5: 54 61 | 122 119
28: 54 57 | 122 36
101: 122 48 | 54 44
81: 120 54 | 14 122
14: 54 96 | 122 38
18: 40 122 | 76 54
27: 122 93 | 54 103
4: 123 122 | 90 54
65: 122 87 | 54 22
113: 54 | 122
23: 122 127 | 54 62
117: 71 54 | 119 122
53: 35 54 | 126 122
26: 122 52 | 54 108
125: 54 33 | 122 4
10: 74 122 | 53 54
84: 54 19 | 122 109
123: 122 114 | 54 115
42: 70 122 | 26 54
16: 122 39 | 54 98
63: 98 54 | 51 122
39: 54 122
76: 122 83 | 54 101
61: 122 3 | 54 39
50: 122 85 | 54 95
78: 22 122 | 3 54
114: 122 122
64: 122 122 | 122 54
40: 122 81 | 54 55
92: 127 122 | 97 54
119: 122 51
57: 98 54 | 114 122
3: 113 122 | 54 54
97: 122 113 | 54 122
7: 122 37 | 54 59
74: 54 46 | 122 56
2: 122 67 | 54 50
48: 43 122 | 65 54
124: 54 94 | 122 36
82: 54 98 | 122 64
93: 59 122 | 116 54
96: 115 122 | 97 54
98: 54 54
60: 51 54 | 22 122
72: 122 98 | 54 3
106: 39 54 | 39 122
41: 51 54 | 97 122
31: 18 54 | 69 122
91: 122 62 | 54 127
120: 105 122 | 19 54
56: 60 122 | 78 54
47: 16 122 | 91 54
88: 97 113
30: 22 122 | 115 54
71: 51 54 | 39 122
87: 122 122 | 54 122
21: 122 102 | 54 73
43: 122 22 | 54 127
35: 54 23 | 122 90
51: 113 113
90: 122 62 | 54 87
32: 54 127 | 122 97
115: 122 54 | 54 113
55: 54 84 | 122 89
73: 122 51 | 54 39
36: 22 54 | 114 122
68: 122 87 | 54 98
34: 118 54 | 32 122
95: 54 87
83: 122 117 | 54 20
33: 99 54 | 29 122
19: 122 127 | 54 98
46: 54 112 | 122 79
89: 54 72 | 122 66
110: 54 51 | 122 98
109: 64 54 | 22 122
9: 54 107 | 122 5
12: 54 80 | 122 45
104: 54 100 | 122 32
15: 75 122 | 63 54
69: 122 49 | 54 12
8: 42
75: 97 54 | 3 122
108: 122 77 | 54 125
103: 122 88 | 54 24
111: 3 54 | 39 122
70: 122 58 | 54 10
20: 122 105 | 54 68
0: 8 11
122: "a"
79: 62 54 | 22 122
102: 87 122 | 97 54
105: 98 54 | 98 122
49: 13 54 | 2 122
112: 54 39 | 122 62
58: 9 122 | 17 54
11: 42 31
107: 66 122 | 110 54
86: 54 106 | 122 82
99: 127 122 | 39 54
22: 54 122 | 122 54
118: 54 3 | 122 64
67: 122 59 | 54 111
126: 78 54 | 92 122
121: 54 41 | 122 38
66: 22 113
94: 54 39
6: 88 122 | 29 54
127: 122 54
116: 54 39 | 122 87
59: 54 51
85: 64 122 | 97 54
100: 98 122 | 62 54
54: "b"
45: 86 122 | 104 54
baaabbaabababaaababaaaaababbbabaabbbabba
baabbbbbaababbabaaabbabb
abbabbaabbabbbaabbabaaaaaabaabbbabbabbaa
bababbaababaabbaaabbabbb
baaabbaababbbbaabbbaaaba
bababbaababbbbbbaabbbbbb
ababababbabbaababbaabbbabbaabababaaababbaabaaaabbbbbaaaa
bbabbabaaaaabaaabbaabbab
abbbaabbababaabbbaabaaab
bababaaaabbbbbaaaabbbbbb
bbabaabbbbabbaabbabaabbaabbbbbaa
babaabaaabaaabbbbbbabbababaaabbbaaaaababbaabaabb
abaaaaaabaaabbbabbbaaabaababaabaaabababaaabaabba
aabbbaaaababbaaaaababbbb
babaabbaaaaabaaabaabbbabbababbbb
aabbabbbbbabaaaabbaabbab
abbabaaaaaaaaaaaabaabbbbaaabbbabaaabbabb
aaababbbaabbabbbaaabaaba
babbaabbbabaaaaaaabbbbabbabaabbababbbbabaababbba
abababbbabbabbaabaaabbbbababbabb
aaaaabbbbbbbaaaabbbaaabb
baababaaababaaabbaabaaabaabbabbabbaaaabb
babaabbbababaabaaababbbb
babaabaababbbbbbaabbaaba
babaabbbbabaaaabbbabbbaaaabaaaba
bbbabbbabbbbbaabbbbaabba
aaaaaababbabbbaaaaabbabb
bbabbbaaaababaaaababaaab
baabaababbbbbbbaaaaababb
abaababbaaaabbbaaabbabababaababbbbaabaab
abbbbbaaaababaabbbbababa
aabbabababbbbbaabbaaabba
abbaaababaabbbaaaabbaaaabbbabbabbababababaaaaaaabaabaabaaaaabaabbaabaaabaababbbbbbaabbaa
abbabaaaaaaaababbbbaabba
bbabbbaaaaabaababbbbbaaabbaaaabababbbabaabbabaababaaababbaabbbbbaababbbb
abbabaabbbbbaababbabbbbaabbaaaab
baaaabababaabbabbbbbbaabbaaaaabbbabbbbba
abbbabbbbbabaabbaaabaabb
aaaaababbbbabbaabaababba
baabbbbaaaaabbababababba
bbbabbaaabbaaaaaabaabbaa
babbaabbbabbaabbaaababababaaabab
ababaabbbaaabaaabaaaababbbaababaaababaabbbbbabbaaabbaaaa
aabbbabaaaaaabaaaaabbbaa
aabaaabbbbbbbbbaaabababa
abbaabababbbaabbbabbbbaaaaaaabbaaaababababaabbbabbbababa
aabbbabbabbaaaaabbbaaabb
bbbabbbabbaabbbbbbbaaaba
bbabababaababbaaababbaab
abbabbbabbbbbaaaabbabaaabbabaabaababbaaaaaabbabb
abbbbaabbabaaababbabaaab
aabbbbabaaaabbbaabbaabbbbbaabaaaaaaaaabaaaabbbaabaabaaab
abaaabababbbbaabbbbbaaba
bbbbbabbbabbbaaabbaababaaaabbabbaaaaaaabaaaaaaaaabbabaaaabbabbaabbbbaaabaaaabbba
baabaabaabbbabbbbbaabaaaaaabbbaa
bbbaaaaabbbbbbaabbaabaabbbbbbbbbabbababaaabbbbbb
bababaabbabaabbabbbbbabababaaabb
abaabbabaabaaabbbbaaabba
babbaababbabbaababbbbaaa
aabaababbabaababaababbbb
aaababbaabbaaaaababaaabaaabbbabbbaaabababbbabbbb
aaaaaabaabaabbbaabaaabaa
babaabababbabaaaaaaababb
bbabaabbabaabbbaaaaaaabb
abbabbbbbaaabbaaaaabaaab
ababaaaabbabbbaabababaaaaababaabbbaabbaaaababbbb
babaaaaaababbbbaaabbbaaaabbbbbabbbababba
bbbbabbbaababbabaabaabba
babbabbbbaaaaabbbabbbaaaabaabaaa
aabaaabbaabbbbabbbbababa
babbabbaaaababbbaabbaaaa
aabaababbaaabbbbbbbaabbb
babaaaabbabaabbaabaaabababbaabbbbaaaabbb
bbaabbbbbbabbbababbbabba
bbbabaabbaabaabababbbaaa
bbabaabbbaababbaaaabbbababbaaabaaaaabababaaaabbabbbaaabb
ababaabababaabbbbbababaa
abbabbaabbbbabababbababb
baabbbbaaababbabaaabbaaa
ababaabaababababaaabbabb
babbbbaaabaabbbababbaaaa
aaaabbabbabaaabbbbbaabbb
babbababaabbbababbabababbababbba
aabbbabbbaaabbaabbbabaaa
aaaabbabbbbabbaaaaabbbba
aaabbaabaaaaabaababaabbaababaaaababaabababbbaaaababbabaa
babbabbabbaabbaaaaabbbbb
bbababbbaaaabaaaabbaababbbaabaabaababbbabbbbbbaabbbaababbbbbbaabaaaaabbbaabbbbabaabbbbba
aabbbabaaaaaabbbbbaabbaababbaaabaabaabbbaabaabbb
bababaababbbbbaaabbaabab
baaaaaababaaaaabbabbbbba
aaababbabaaaababbbabbbaabbbbaabb
bbabbbaabaaaababbaaaaaba
abbbbbaaaabbbbababbbaaba
bbbababbabbbaabbbbbbabaa
abbbbabaabababbbbabaabaabbbaabba
bbbbbbbaabbaabaabbbbaaaa
bbbbbaaabaabaaaabaababbb
abaaababbbbbbaaaaabbbaab
abaaaaabbbbaaaabaababbaa
baaaababbbabaabbaaabaaab
aaababbbaaabbaababaaaaaabbaaaabaaaaabbaa
bbabbaabbaaaababbbaababaaabbabba
abaaaaabbbbaaaabbaaabaab
ababbbaaabbabbabbabbaaab
baaabbbbaaabbaababaabbabababbabb
abbabbbbbbaaabbbbbaaaabb
baabbbaaabbbabbbbababbaabbbbbbbbabbaaaabbbaababbbaaaaabbbabaabbaaababbbbbabaaaba
aababbaabbbbbababbbbabbabbababbaabbaabbaaaaaaaab
bbbbaaabaaabababbbabbababbbaabab
bbaabababbaaabbbaaaababb
abbbaabbbaabbaabbaababba
aabababbbabbbbaabaaaaaabbbaabbabbabbabbb
babbbbbabbbbbbbaaaaaabaaababbbbaaaabbaaa
babaabbaaabbabababbbbbbb
bbbaabaaabaaaaabbabaaabbaabaabaa
babbababaabaababababaabaababaaab
bbaaaaababbabbabbbbbaabb
babbbabbabaaaabbabaabaaa
babbababbaabbaabbbaabaab
abbabaabbaaabaaaaabbbabbbbabbabaaababbbbbabaabba
bababbaabaabbbabbbabbbbb
babbbbbbbaaaaabbbbababaa
baaaaaababbabaabbaaaaaba
aabababbbbaababaabbaabaaaaaabaaabaababba
abaaababbaabbabbaaaaababaabbaabbabbaaaabbbbaababababaaba
bbbabbbababbbabbbbbaabaaaababbaababaaaaabaababaaabbaabababbaabab
aaababbbbbabaabaababbaab
bbbbaaabbbbabbbabbbbaaaa
bbbabbababaaababaaaababb
baabbbbbbbabaababababaabaabbaaaaaabbabaa
abbabbaaaaaabbbaababbbbb
bbaabbbbbaaabbbbbbbaabba
bbbaaaababbabbabbaababab
baaabbaababaabaaabbbabab
ababaaaaaabaaabbabaabbaa
aababaabbababbaababbababbbaabababaabbabababbabaaaaababaaaabbbaabaabaabaa
bbaababababbabbaababaaab
aaabababababbbbabbbaabab
aabaaaaabaaaaabbaaaaababaaabbaabbaabbbabbaababab
bbaaabaaaaabaabbabaaaaba
babbbbabbabbbbaaabbaaaaaabbaabbababababb
abbbbaabaaababbbbabbabbabbaabaaabbbbbbbbbaaaabaabbaaabab
abbaaaaaabbbbabbabaabbbbaaaabababbbbaaba
bababaaaababbbbaaaababbaababbaaababaaababababbbbaaabbbba
baaabbbbabaaaaabbbbbbbbb
bbbbbabbaaaabaabababbbbb
ababaaaaaaababbabaaaabba
abbbbaabbbaabbbabaaababa
abaaababbabababaaabaabaa
baaaababaaabaaabbaabaaab
abbbbabababbabbaaabbbabbaabaaabaaabababaabbbabab
babaaabaaabaabababbaaaab
bbabbabbbabbaabbaaaaaabababababbbaabababaaabaababbaabbab
abbaabbbbabaabaaaaababaa
bbaabbaaaaababbaabbbaabbbbabbabaaabbbababbaabbaaaabbbbaa
bbbbababbbbababbbbbabbaaaaaabaabbbbbaabb
babbabbbabbabbaaabbbbbaa
abababbbbbabbabbabbaaabb
bbaabbbabbbbababbbabbaaa
baabbabbbbbabbabbbabbbba
aabaababbabbbabbbababbbb
babbababbbabaababbbaabba
aaaabbababbbbaabbbabbabbbabaaabbbaababaabaababbb
abbbaabbabbbbbaababababb
abbaabaabbbabbaaababbabb
baabbabbbaabaaaaaaaaabba
bbaabababaaaaaabababaabaabaaaaabaabbbbbbabbbbaaa
babaabababbaaaababaababababbbaab
aaaaabbbbbabaabbbaababab
bbbbbaababbbbaabaaabbaba
abbabbaaababaabbbbbaabaabbababab
bbbabaabababbbabaaaababa
baaabbbababbaababbbbabba
aaaabbaabbaabbbabbbbaaaa
aabaaabbaabbaabbabbbbbab
bbbababbbababbaaabaaabba
abbbbbaaabbaaaaaabbaabba
babaaaababbbbababaaaabbb
baaabbbaaaababbabbbaaaaa
bbbababbababbaabbbabbbbb
aabbbbababaabbbaabaaaaaa
abaababbaaaaabaababbababababbbaaabaaaababbbaabbb
babaaaababbaabaabbbbaaaa
baabbabbabbbabbbaabaababbabaaaaa
babbbbbbabbbabbbaaabbabbaabababaaabaaaba
abbabbbaabbaabaabbaaaaaa
bbbabbaababbbbaabaaababb
abaabbabaababbaabbaaaabb
baabbabbbabbbabbabbbaaab
abbbbaabbababbaababaaaaaaababbaabbababaa
ababababbbbbabababaaaaaa
bbbaaaabbabbaabbbabbbabbbbababaa
bbbbbbbaabbabbbbbbbabbbb
baaaaaababbabbbabbbbbbbaaaaaaabbbaaababb
bbabbbababbaaabaaabbabaaabbabbbabbabbbaaababbbab
bbabbaabbbaaabbbabaaabbbabaabbaabbaaabba
abaaaaabbbaababbababbbabbbbabaabaabbaabbbbababbbababbaaaabaaabaabbaaabaa
bbabaabbaabbaabbaabaabbb
baabbaaabbabababbaababab
bbaababaaabbbaaababbbaba
babaaabaabaabaabaaabbaabbaaabbaabaabaaba
babaabbabaababaabbbaaaaa
bababbaaabababababaaaaba
aaaabbabbabbaababbaabbab
abbabababaaabbbaaaabaabbbbaabaabbababbbbbbbbaaabbaaababbabbbbaaabbaaabab
bababaabaaaabaaaabababbbabbaaaba
aabbbbabaabbaabbbbbabaabbaababbabbaaabababbbbbba
baabbabaaabbbbabbbaaabaa
bbbbbababababaabaaababaa
aabaabbaabaaaaabbbbbabababbababb
baabbabbaabbbbabbaaababa
aababbaabbaabababbaabaab
baababaabbbabbbaabaabaab
aaaaabaaaaaaaabaaabaaaab
abbabbabaabbabbbabaabbbabaababaababbbbbbaaabbaaaabaaabaa
aabbbbabbbaabababaababbb
aabaababbababaaaabbaabba
aabbaabbbabaabaabbabbbbb
bababaaaabbbbbaabbbaabbb
babbbaaababbbaaaaaaabbbb
aabbbabaabbbabaabbbaabbb
aaaabbaabbbbabbbbbabaabaabaaabaa
abbabbaaabbabbbaabbbaaba
ababaabbbbabababaaabbaaa
aaabababaaaaabaaaaaaabbbbbbbabababbaaabaabbbaaab
baaaababbaababaaabababaa
aaaabbaaabbbabbbbaaaabba
abaabbbbbaaaaaabaababbaaababbaabaabababa
abbabbbbababbbaabaabbaaabbbbbbaabbbbabaa
bbabbabbbbabaabbabbbaaab
aabbbababbbaaaabaabaabbb
bbbabaabbaaabbbbbaabaabb
ababaabaaaaaababaaabbaaa
baaaaaabbabbabbaabbbaaab
bbabaabaababaaaaabbabaaaabababba
aabbbaaaaaabbaabbbabbaabbaabaaaa
abaaabbbbbaaabbbbaaabbab
bbabbabbabaaabbbbabbbbbbabbbbbbaababaaaaabbbbbabaaababbabbbabaababaabbbbabbabbab
babaabaababababaaaabbbba
bbaabaaababbbbbbbaabaabb
baabbbabababaaaaaabbbbaabbbaabab
abbbaaaababaabbabaabbbabbabbaaabaaabbaababbbbaaa
abbbabaabaababaaabbaaaab
ababababaabbbbabbbbbbbabbbbabbbaaaaaaabbbaabbabaabaaaabb
abaaabbbabaabbababbaabaaaaaabbbaaaabbbba
baaaaabbababababbaaabbab
babaaabaaabbbaaabaaabbaa
babbbabbbabaabaabbbbbbbb
aabbbabbabaaababaaabbabb
bbaabbaaaaababbaaabbbaab
aabbbbabbbbabbbaaabaaaab
abaabbbaababababbabaaabbbabbbaba
abbaaaaabbabbbabbbaaabba
aabaababbaabbabbabbaabba
bbabbabbbabbbbaabaababba
bbabaabbbbabaabbbbbbaaaa
abbbbabaabbbaabbaaababbaabbbabbaaaaababb
bbaaabbbbabaabbaabbbbbbb
abaaaabababbaaababbbbbbaababbaab
abaabbbbababaaaabbbaaabb
aaabaabbaababbbbbbbaaaaaabbbaaba
aaaaababbaabbaabbabbabbb
aaaaaaabaabababbbbbaaaaa
bbbbbaaaababaaaaaaabbaba
ababbaaababbbaaaaaabbbba
babaabbbbbabababbaabaaab
aabbbababbbabaabaabbaaab
abbbabaaabbbaabbabbaabba
baabbaababaabbabaabaaaab
baabbabbaabaababbaababbb
bbbaaaabaabbbaaaaaaaaaaabaaabbbaabbaaaaaabbbaababaabababababbaabaaabbbab
baabbabaaaaabbaaabbbabba
babaaabbabbbaabbabbababa
bbabbabbaaababbbbbbaaabb
aaaaababbabababaaaaababa
babaabbbbbbbbbbababbbbbbbbbaaaabaababaaa
aaabababaababbaabaaababa
ababaabbbabaabaabbaaaaaa
aaaabaaaabbabaaababaabaabababaabbaabbbbbaabbbbba
baaaaaabbabaabaabbaababb
aaabababaaabababaabaabba
abbabaaaabbabbbbbbbbbabbaaaaabab
bababaaaaababbabbbbbbbbb
ababbaaabbbbababbaaaaaba
ababaaaabbbaabaabbaaabaa
baaabbaabbbaababbaabaaabaaaaabababaabaaabababaaa
aaabbaabbaabbabbbbbababbabaaaababaaabaab
bbbbbaaabbaabbaababababb
aabbbbabaaaaabbbbaabaabb
abbabbaaaabbaabaaaaababbabbabbbaabbbbbbaabbabaaababbaabaaabbabab
abbabbababbbbababbbaabaabbbaaababbbaaabb
bababbaaabaabbabababaaaaabbbabbbaaaaabbb
babbaabaaabbaabbbbaaabaa
ababbaaababababaabababbbbbaababaabbbbbbb
aababaabbbabbaabababababbbbabbbaaaabaaabaaabbabb
baabaaaabababaaaababbbbb
bbbbabbbabaaabbbbbbababa
bbabbbaaaabbbaaabaababbb
bbbabbabbaabbabbbaababbb
baabaabaaaaaababaabaaaab
aabaabbaabaabbbbaaaabaaabbaababbbbbababbbabbbababaaabaabbaabbaabababaaab
babbababbbbababbabbbbbaaaaabbbaa
bbaabbbaaabaaabbbaababba
bbabbbabbbbabbbabbbbaaababbabaaaababbaabaaabaabbabaaabaa
abbaabbbabbbbabbbaaabbaaaabaabba
baaaaabbbabaaabababaaabbbabababaaababaaabaaaabbaabbaaababababbbaabbbbaaa
babbbaaabaaabbbbbbababba
aabbbbabbaabaaaababbabbb
baabbbbababbbbbbbbbbaaba
baabbbabbbaabaaababbaabbabbbababbbabaaab
bbabbbababbabbbbababbaaabababbbbabaabbaa
aaabababbbbbababaabababbbbbabbbbbabbbaba
bbbbabbbbaabbbabbababaaabbbaaabaabbababb
ababbbbaababbbabbbababba
abbaaaaabaabaaaabbbbaaba
aaababababaabbabbbbbbaaaaaaababa
bbbabbbabaaabbbbbbabbaabbbbabaaa
bababaabbabbbabbaaabbbaa
abbbbabbaaaaabbbbababababbbbabbbaaaaabaaaabbaaaa
bbabbbaaaabaaabbaaaabbaabbabaaab
abbabaaaaaaaaaaaaaabbabb
babbbabbbbabaabaabaaaaba
babbaabaabaaabbbbbbbbbaa
ababbbbabbbbabbbbababaaaabbaaabbbbbaabba
aabaababababaabbbbbaaaaa
abbbbbaaabbbbabbaaaababa
aaabaaabaabbbaabaabababaaaabaaba
babbbabbbbaabaaabababbbbbabbababbaabaabb
babaabbbbbbabbabaaaabbbaabaaabaaaabaabba
bababaabbabaababbabbbabbbbbbababbabbaaaaaabbabaa
babaaaabaababaabbbbaabba
bbaabbbbbaaabbbaaabbbbabbbaaaaabbabbabbababbabaabaaabababbabbbba
baabbaabbbabbababbbabaaa
aaaaaaaaababbbababababbbbbabaaaabaaaaababaabbbbb
aaaabaaabaabbbbbbbabbbabbabbabaabbbbaaabaaaabbbbbabaabaa
aabaabababbbaabbbbabaabbbbaabababbabbabaaaabaabb
aabaababbbabaabababbbbab
bbaabbbabbbabbbabbabbbba
bbaaaaabaaaabbaaaaaaabba
bbaaaaabaababbaababbbabbabbabbaa
aaabaabbbabaabaaaaabbbabaabbbbbabbbaabaa
aaabbbaabbbbaaabababbbbbabbbbbbbbbbabbbaabbabbbbaaaaaababbbbabbaabbabbaaaababbbb
aababaabaabbababbababbba
babaaaaaaaaaaaabaabaabba
aaabbaabbabbaabbbaabbbbbaabbaaba
aaababbabbabbabbababbbbb
abaaabbbbbaabaaaabbaaaba
bbaababaababbbabaabbbaab
abbbaabbbaaabbbabaabbbbbaaaaaaabbaaaaabbbbbbabaaabbaaaba
babaaaabbabaaaaababbabaa
bbbbaaababbbbaabababbbbb
abbababbaabaababbbaaaaabaabaabbbbabbabaababababaaaaaabbababbabbbbabbaaaabbbbabaa
babaaababbabaaaabbaaaaba
bbabbabaabbbbababbbaaabb
bbaababaaaaabbbaaaabbaaa
babaaaaaaabaababbabbabbaabababbbaaabbbaaaabbbbbabbbbaaaa
babaabbababaaabbbaaaabbb
aabaababbabbbabababbbbaabaaabaaaaaabbababbbabaaaabaaaaabaaaababaaabbbaaabbaaabbb
abbbabaabbbaaaabaaabaabb
bbbbbbbaaaabababaabbbbbb
ababaaaabbababababbaaabb
abbabbabbabbaabbbaaaaabbaabababa
bbabbabaababbbabaaaababb
babbabbababaaabbabbaaaba
aabbaaababbaaabbbbaabaabbbbabbbaaabbbbababbbabbaaabaaaabaaaabaabaabbbaab
bbbbbbbaaabbbabbbbaaaabb
bbabbaabbbbaabaabbbaaaaa
bbbabaabbaabbaaabaaabaaabbbbbbbb
aaabababbaabbbbaaababbbb
abbbbbbbabaaaaaaabbbbababbababaa
bbbaaaabaabaaaaabbaabbab
bbbbabbbaaaababbaabaaaab
bbaaabbbababbbabbbbbabaa
aaaabbaaabaababbbbabbabbbbbbbaaaabbbbbba
aabbbabbaaaaabbbbaaabaab
abbabbbbbaaaaaabaaabbaaa
baaaabababbbbaabaababaaaabaaabbbbbbaaaababbababa
bbbbabbbbbbbabbbbabbabbb
abbabaaaaabbaabbabaaaaaa
abbabbaaaababbaaababaababbbaabbbabbaaaab
abbaabaaaaaaabaaaaabbbaa
bbbaaaabbaabaabaaabababa
bbbaababbbbabaaabbbabaabaabababa
baabaababbabababbbbaaaaa
baaaabababbaabbbbaabbbabbbbaabab
baabbbbaababbaaaabbaabbb
babbbbbbabbbbabbabbabbabaabaaabbaaabbbab
ababaabbbabbaabbabaababbbbbbbaba
baabbabbaaabababbaabaabb
ababababbbabbbabbbababaa
abbaababaabbbbbabbaaabbabbabaaab
babbbbaaababbbabbbababba
abababbbabaaababaabbbbbbbbabbbbbbaaaabbbaabaaababababbba
aabbaabbbabaabbbbabbbbab
baabbbbabbbbabbbbaaababa
aaababbbbbbabbaabbbaaabb
bbbaaababaabaaabaababbbabaaaaabaaaabbbaa
baaabaabbabbaaabbaaababa
bbabaabbaababaaaababbbbb
ababbbbababbabbababaabaaaaaaaaababababbbaabbbaab
bbbbbabaabbbaabbaaaaabba
aaabababbbabbaabbbaabaab
bbabbabbbabaabbabaababbb
aaaaaaababbabbabbabbabaa
abbabaaaaaaaaaaaababbbbb
babaababbaabbabbabbabbaabababbbaabaabbaa
aabbbbaaaababbbbabababbabbbababa
bbbabbaabbabaaaaaaabaaaa
bbabbabaabbaaaabbbaaaaaa
bbaabaaabbabaaaabbbbaabb
bbabbaababbabbaaabbbabbbababbaab
bbbbababbabbaabbaabbaaab
aaaabbababbabaaababbbbbbbbbbbababbbababbabbbaabaaaabbaba
abbbaaaababbbbbaaaabababababbaabaabbbbaabaabaabbbabababa
bbbbabbbbbbbabbbbbbbbbab
bbabababbbabaaaababababb
abbabaaaaaaabbbaaaabbbbb
baababaaabababbbbabbaaaa
bbabbabbbabbabbaabaaabba
aaabababbabaabbaaaabbbbb
abaaababbaabbbbaaaaabbaaaaaabaaabbabbbabbbabbbbb
bbaaabbbbbbababbabababba
bbbbaaabbbabbbabbabaaabbbabaabaaaaaaababbabababbbbbbabaababbabbb
babbbabbbaaabbabbbabaaabababbaba
bbbabbbbbbabbabbaababbbb
baaabaaabbaabbaabaaabbabbababbab
bbabaaaaabbabbaaabbabaab
abbaabaabaaaaabbbbbaabba
aabbbbbaaaabbbbaabaaabbbbbaaabbaaababbbaaabbbaababababbaaabbbaabbbabaaab
bbbabbbaabbbbababaaabbabaabaabbbbababbaaaaaaabbbaaabbbabaababbaabbaaabaaabababba
aaaaababbbbbbaaaabaababbabbbbabaaaabbaabaabaabbabbabbbbbaaaaabba
babbabbabaabbbababaaabaa
aabaaaaabbbbaaabababbaab
babaaabbbabaabbbaaabaaba
bababaaabbaabababbbbaabb
aabbbababbaabbbaabbababb
babaabaabbbbaabbaaaaabababaaababaababbabbabbabbaabbbbbaababbaabbaaaabaaa
aabbbbabaaababbabbaaaaaa
ababaabbabaababbbbbaaaaa
aaababbbbaabbbabbbabaabbaabbbabaabbaababaaabbaaa
bbbbaaabbbaabababaababbb
ababababaabababbbbababaa
baaabaaaabaaabbbabbbbbaababaaabaabaaaabaaabaabaaaaabaaaa
abaabbbabaaabaaaababbbababbbbbaaaabaabaa
bbaabaaabbbbbbbbbaaabaaababbbbbabababbaabaaaaaba
babbababaabaaaaaaabaabba
bbbabaaaabbaabbbaabaabbbaaabababaaababaabbbabaaabbbbaababaaaaaabbabbbaba
aabaaaaaaabbabbbaabbbbba
abbbbababbabaaaaaaaaaaaaaabbbaaababbabbabbbbabaa
aaababbabababaaaabbaabba
bbbbabababbabbbaabbbabab
aaababbbbaabaaaabbbaabbb
bbbaaaabaabaaabbbbaaabab
ababbbaabaabaabababbbbab
babaabababbabbbbbbbbabba
abbbabbbabaaabbaaaaaabbbabababbabaaaaaab
baaabbbbbababaababbbbbbb
aabbbaaaaabaaaaaabbababb
aaaaabaaabababababbbbaaa
ababaabbaaaabbababaaaaaa
bbbaaaabaaaabbaabaaabaab
baaabbbbbbbabbaaabbaaaaababbabbbbbbaabbbbbbabbbabbbaaaab
bbbbbaabaaaabbabaaaaaaaabbbabbbb
bbbaabaaaabbabbbabbaabaaaaabbbbbabbababbaabbbababbababab
bbabbabbbaabbaaaabbabbaaabbbabaababbabbaaaabbbab
baaabbbababbbabbaabaabbb
aaaabbaababababaaabbbbbb
abbbbbaabbbabaabbababbba
bbbbbbbababbaabbabaaabba
abbbaabbbabaababbbaaaaabaabbbbaa
babbaabaabbbbababaaabbab
baaabbbabaabbbbabbbbaaabaaabbabb
aabbbabbabbbbabbababaabababaabaabbaaabaabbbbbbbbaabababa
bbbaabaaababaaaabbaabbaaaabbbabaabababaa
bababbaababbababaabbabaa

73
19/main.py Normal file
View File

@ -0,0 +1,73 @@
Rule = list[list[int]]|str
RulesDict = dict[int, Rule]
def parse_rule(rule_str: str) -> Rule:
if "\"" in rule_str:
return rule_str[1]
else:
rule = []
for sequence in rule_str.split(" | "):
rule.append(list(int(n) for n in sequence.split(" ")))
return rule
def parse_rules(rules_str: str) -> RulesDict:
rules = {}
for line in rules_str.splitlines():
id_sep = line.find(":")
id = int(line[:id_sep])
rules[id] = parse_rule(line[id_sep+2:])
return rules
def parse_input(filename: str) -> tuple[RulesDict, list[str]]:
content = None
with open(filename, "r") as f:
content = f.read()
rules_part, messages_part = content.split("\n\n")
rules = parse_rules(rules_part)
messages = messages_part.splitlines()
return rules, messages
def find_match(message: str, rule_id, all_rules: RulesDict) -> list[int]:
rule = all_rules[rule_id]
if isinstance(rule, str):
if message.startswith(rule):
return [1]
else:
return []
result = []
for sequence in rule:
branch = [0]
for id in sequence:
new_branch = []
for last_pos in branch:
match = find_match(message[last_pos:], id, all_rules)
for pos in match:
new_branch.append(pos + last_pos)
branch = new_branch
result += branch
return result
def matches_zero_rule(message, rules: RulesDict):
return len(message) in find_match(message, 0, rules)
def part1(rules: RulesDict, messages):
count = 0
for message in messages:
if matches_zero_rule(message, rules):
count += 1
return count
def part2(rules: RulesDict, messages):
# 8: 42 | 42 8
# 11: 42 31 | 42 11 31
rules[8] = [[42], [42, 8]]
rules[11] = [[42, 31], [42, 11, 31]]
return part1(rules, messages)
if __name__ == "__main__":
rules, messages = parse_input("input.txt")
print("part1: ", part1(rules, messages))
print("part2: ", part2(rules, messages))

47
19/test.txt 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

1727
20/input.txt Normal file

File diff suppressed because it is too large Load Diff

238
20/main.py Normal file
View File

@ -0,0 +1,238 @@
from dataclasses import dataclass
from typing import Iterator, Optional
from math import floor
@dataclass
class Tile:
top: str
left: str
right: str
bottom: str
inner: list[str]
def __repr__(self) -> str:
return "Tile"
TilesData = dict[int, Tile]
TileGrid = list[list[Optional[tuple[int, Tile]]]]
def parse_tile(tile_data: str) -> tuple[int, Tile]:
lines = tile_data.splitlines()
id = int(lines[0][4:-1])
top_edge = lines[1]
right_edge = "".join(line[-1] for line in lines[1:])
left_edge = "".join(line[0] for line in lines[1:])
bottom_edge = lines[-1]
raw_inner = list(line[1:-1] for line in lines[2:-1])
return id, Tile(top_edge, left_edge, right_edge, bottom_edge, raw_inner)
def parse_input(filename: str) -> TilesData:
tiles = {}
with open(filename, "r") as f:
content = f.read()
for block in content.split("\n\n"):
id, tile = parse_tile(block)
tiles[id] = tile
return tiles
def flip_image(image: list[str]):
return image[::-1]
def rotate_image(image: list[str]):
return ["".join(col[::-1]) for col in zip(*image)]
def rotate_tile(tile) -> Tile:
return Tile(
top = tile.left[::-1],
right = tile.top,
bottom = tile.right[::-1],
left = tile.bottom,
inner=rotate_image(tile.inner)
)
def flip_tile(tile) -> Tile:
return Tile(
top = tile.bottom,
right = tile.right[::-1],
bottom = tile.top,
left = tile.left[::-1],
inner=tile.inner[::-1]
)
def get_grid_size(tiles: TilesData) -> int:
return floor(len(tiles)**0.5)
def get_rotated_tiles(tile: Tile) -> Iterator[Tile]:
yield tile
tile = rotate_tile(tile)
yield tile
tile = rotate_tile(tile)
yield tile
tile = rotate_tile(tile)
yield tile
def get_tile_variants(tile: Tile) -> Iterator[Tile]:
for t in get_rotated_tiles(tile):
yield t
tile = flip_tile(tile)
for t in get_rotated_tiles(tile):
yield t
def get_image_variants(image: list[str]) -> Iterator[list[str]]:
yield image
image = rotate_image(image)
yield image
image = rotate_image(image)
yield image
image = rotate_image(image)
yield image
image = rotate_image(image)
image = flip_image(image)
yield image
image = rotate_image(image)
yield image
image = rotate_image(image)
yield image
image = rotate_image(image)
yield image
def is_tile_possible(grid: TileGrid, x: int, y: int, tile: Tile) -> bool:
if x > 0:
other_tile = grid[y][x-1]
if other_tile and other_tile[1].right != tile.left:
return False
if x < len(grid[0])-1:
other_tile = grid[y][x+1]
if other_tile and other_tile[1].left != tile.right:
return False
if y > 0:
other_tile = grid[y-1][x]
if other_tile and other_tile[1].bottom != tile.top:
return False
if y < len(grid)-1:
other_tile = grid[y+1][x]
if other_tile and other_tile[1].top != tile.bottom:
return False
return True
def get_possible_tiles(
tiles_data: TilesData,
used_tiles: list[int],
grid: TileGrid,
x: int,
y: int
) -> Iterator[tuple[int, Tile]]:
for id in tiles_data.keys():
if id not in used_tiles:
for variant in get_tile_variants(tiles_data[id]):
if is_tile_possible(grid, x, y, variant):
yield id, variant
def solve(tiles_data: TilesData, grid: TileGrid, used_tiles: list[int] = []) -> bool:
for y in range(len(grid)):
for x in range(len(grid[0])):
if grid[y][x] == None:
for id, tile in get_possible_tiles(tiles_data, used_tiles, grid, x, y):
grid[y][x] = (id, tile)
used_tiles.append(id)
if solve(tiles_data, grid):
return True
used_tiles.pop()
grid[y][x] = None
return False
return True
def multiply_corners(grid: TileGrid) -> int:
w = len(grid[0])
h = len(grid)
top_left = grid[0][0]
top_right = grid[0][w-1]
bottom_left = grid[h-1][0]
bottom_right = grid[h-1][w-1]
assert top_left
assert top_right
assert bottom_left
assert bottom_right
return top_left[0] * top_right[0] * bottom_right[0] * bottom_left[0]
def solve_grid(tiles_data: TilesData) -> TileGrid:
width = get_grid_size(tiles_data)
grid: TileGrid = []
for _ in range(width):
grid.append([None]*width)
solve(tiles, grid)
return grid
def get_full_image(grid: TileGrid) -> list[str]:
rows = []
for y in range(len(grid)):
row = []
for x in range(len(grid[0])):
cell = grid[y][x]
assert cell
inner = cell[1].inner
if x == 0:
row = inner.copy()
else:
for i in range(len(inner)):
row[i] += inner[i]
rows.extend(row)
return rows
def is_sea_monster(image: list[str], sea_monster: list[str], x: int, y: int) -> bool:
for oy in range(len(sea_monster)):
for ox in range(len(sea_monster[0])):
if sea_monster[oy][ox] == "#" and image[y+oy][x+ox] != "#":
return False
return True
def count_symbol(image: list[str], symbol: str) -> int:
return sum(sum(c == symbol for c in row) for row in image)
def count_sea_monsters(image: list[str], sea_monster: list[str]) -> int:
monsters = 0
for y in range(len(image)-len(sea_monster)+1):
for x in range(len(image[0])-len(sea_monster[0])+1):
if is_sea_monster(image, sea_monster, x, y):
monsters += 1
return monsters
def part2(grid: TileGrid) -> int:
image = get_full_image(grid)
sea_monster = [
" # ",
"# ## ## ###",
" # # # # # # "
]
max_monsters = 0
for variant in get_image_variants(sea_monster):
monsters = count_sea_monsters(image, variant)
max_monsters = max(max_monsters, monsters)
return count_symbol(image, "#") - count_symbol(sea_monster, "#") * max_monsters
if __name__ == "__main__":
tiles = parse_input("input.txt")
grid = solve_grid(tiles)
print("part1: ", multiply_corners(grid))
print("part2: ", part2(grid))

107
20/test.txt 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:
#.#.#####.
.#..######
..#.......
######....
####.#..#.
.#...#.##.
#.#####.##
..#.###...
..#.......
..#.###...

34
21/input.txt Normal file
View File

@ -0,0 +1,34 @@
rzfcn jcpnmh sjxxzrd qpngxk vpchddj ccjjp klcl dk bltzkxx ttzd fkszg rhjbx cnnd shptr mhvtp zlcbnx tplp vgh bltrbvz qbrr bhgpk ffmgfz tgfcl kjfnqg rpf sncl jvjmd jgblz ngzp dvrhz zphlmnb spql crsp hqnnsm hvlc pxldx pflk rblzjb bclc dzqlq zll ndmz lgccp mpbsn lzxgf njdfc zjdkj mfnc rznmz nzhtc xbdh kqth plmpl bkqzk krh jsphx sbtz qlhqg pqhd cjf xrjzvh lgm szh nrbl dtvsk srhcd vgzjp mqmq szcgft rpjcjd bbgz ggqsr hgcb (contains fish, eggs)
xbdh rpf zlcbnx mhvtp bxcgf jsphx dpls jrvxh zvtvzc bthckj vkjd tk mccpbg zdvcnx cjf bclc cmlh spcqmzfg lhslfpx kcmmj mkhbznt klcl bqcjvv qpngxk srhcd vrgk bmnqp sjxxzrd mkt mcgx ffgs cnnd zbhmgm nbrh ztv dzqlq bltzkxx nrbl dk bscmf jqrq fkszg sncl hgcb xrjzvh spql ggqsr pflk tfn jcpnmh (contains dairy, nuts, sesame)
pflk dpls jvjmd sbtz hlk rbxnc mkpc hrmdt mkhbznt pxldx bltrbvz krh fxsrc qpzcmf cqzqvj nhsx blvlch ffgs ghvj pqhd bltzkxx nbrh dzqlq lhslfpx rgnz njdfc rtxfsp vxmfmjjh fpc pmht cftgsk jqrq frnz spql dpmcrh bhgpk hvlc vgh rpf bvskjzc zpcscz hpdn plmpl xdjhhj dsbj bthckj lzxgf ljsmz kjfnqg rghrrt xhlkscn rhjbx lgm bbhvzz nrbl qlhqg cdhfzl ttzd zxftz xbdh mflngx gtgkt rpjcjd ztv (contains eggs, fish, peanuts)
bscmf rmngx bchbc kqth pqhd bbhvzz njdfc bltzkxx bnnqz fkszg rhjbx shkkk shptr nbrh cjf bltrbvz xbdh spcqmzfg zdznn tfn bhgpk vkjd bsql zxftz jqrq pflk qtxgzpx fpc zphlmnb dzqlq rtjk vpchddj smktk sbtz hhppz rtxfsp qmbxq zgfl tprdg zll lgccp mhlv cnnd jsphx bthckj kcmmj hlk tgfcl jrvxh qfkgx spql dk qpngxk ljsmz (contains wheat, dairy, peanuts)
jpvrvr nbrh lvrp crsp xbdh shkkk jrvxh bqcjvv bvskjzc mpbsn pxldx bbgz txs rbxnc vrgk cnnd bltrbvz rghrrt lgm xrjzvh rznmz zpcscz srhcd hffzvrj spcqmzfg ngzp qpzcmf dsrxrt rpjcjd spql vdm lhslfpx bltzkxx pflk dpmcrh krh rrngl dpls tgfcl dzqlq xhlkscn ztrgb (contains wheat, sesame)
bscmf dzqlq ggqsr czs bltrbvz bhgpk dk xrjzvh xbdh jgblz rtxfsp fzkxc cftgsk zdznn blvlch bltzkxx btpdk nqsdkrh ttzd spcqmzfg fpc qbrr kbzmtz sbtz mxpn bxxs dsrxrt pflk sncl hffzvrj mfqvks mfnc hzfd xdjhhj mhlv hpdn nrbl vdm zbhmgm qtxgzpx rtjk vpchddj vkjd lvrp spql zgfl mpbsn cjf ftkqfrv mccpbg qlv zvtvzc tprdg (contains shellfish, wheat)
smktk xcq fpfdkl hcnmld qpngxk bxcgf hzfd pflk frnz zdvcnx zdznn dsbj tplp lgccp vgzjp mpbsn qpzcmf bltzkxx pqhd txs spql ksbr vkjd vdjjl njdfc fpc qgkhxq ccjjp dfk bxxs vdm rtjk qtxgzpx bltrbvz rblzjb tpvb xbdh lgm hvlc mqmq djp rbxnc cqzqvj rghrrt pxldx hhppz rpf cxhplp srhcd gbsvjgg pmht cfl dtvsk bclc hgcb dzqlq rbprd fzkxc xzzl bthckj dvrhz mcgx tfn mxpn ftkqfrv rhjbx shptr ztv dk krh jqrq ztrgb mcvjsk bnkgs nbrh nrbl cftgsk zjdkj zbhmgm hflzrt qlhqg tprdg (contains wheat)
tk sbtz fpfdkl bnnqz tprdg btpdk xbdh jvjmd szcgft rzfcn ndmz bqrpdxt vrgk dsrxrt kqth sncl czs cftgsk lgm hrmdt rgnz mhsr hcnmld bxxs crsp dpmcrh lvrp zpkl bclc ftkqfrv rlcv hzr njdfc ttzd zgfl bltrbvz tplp hgcb rtjk ztv blvlch mfnc ffmgfz zpcscz zxftz srhcd pxldx kcmmj dvrhz bbgz rpf zphlmnb pflk hqnnsm ljsmrl ngx bxcgf mfqvks spql djp zjdkj cdhfzl vpchddj spcqmzfg sjxxzrd qbrr xrjzvh hhgqp bltzkxx (contains sesame, nuts)
czstl bclc bltrbvz jqrq ztv cxhplp mpbsn bchbc dpmcrh rpf rhjbx hpdn ttzd hvlc rmngx bqcjvv tfn rbprd bkqzk cfl vzfg mkt bltzkxx xzzl zdvcnx pflk ztrgb krsl dzqlq zvtvzc nqsdkrh kcmmj bsql mflngx hzfd qlhqg krh mfnc sncl btpdk cdhfzl ftkqfrv hflzrt tplp xrjzvh sbtz ljsmz spcqmzfg xcq hffzvrj qpngxk mxpn gbsvjgg plmpl spql cjf rgnz hlk lhslfpx mfqvks ljsmrl rzfcn kjfnqg rlcv ffgs bnkgs (contains nuts, peanuts)
hzfd ccjjp frnz dsrxrt krsl bltzkxx txs krh hgcb vgzjp qpngxk rpf bvskjzc jvjmd qlv sncl sbtz jrvxh bsql crscm bscmf rbxnc hqff djp srhcd vdm nbrh dzqlq lgccp bnnqz btpdk jsphx tplp nrbl qfkgx zdvcnx qbrr cftgsk pflk rmngx rblzjb mpbsn xbdh shkkk ksbr spql zjdkj xrjzvh nqsdkrh hlk bltrbvz rpjcjd rznmz vkjd jcpnmh bqrpdxt zxftz nhsx (contains sesame, eggs)
rbprd frnz jpvrvr sbtz hcnmld spql rhjbx jzcrblh zphlmnb lgccp szcgft dvrhz dsbj qlhqg gbsvjgg dzqlq bltzkxx shptr bsql qpzcmf bbhvzz csdbg hvlc zgfl qbrr djp qpngxk pmht dfk spcqmzfg cftgsk nhsx lhslfpx kjfnqg zpcscz pflk zpkl bqrpdxt xbdh cdhfzl bhgpk lgm pxldx bscmf ztv jsphx lzxgf bxcgf dtvsk kcmmj gtgkt cjf tpvb rpf mflngx cfl nbrh btpdk czstl fzkxc (contains shellfish, wheat)
spql rtjk xdjhhj fkszg dtvsk qpzcmf spcqmzfg cmlh pxldx hlk mhlv ffgs tgfcl jcpnmh hrmdt pqhd rpf vrgk bnnqz bvskjzc dzqlq mflngx bltrbvz zvtvzc xbdh ttzd klcl kcmmj hflzrt nrbl bscmf jgblz lvrp hzr mccpbg dsrxrt hcnmld vdjjl bmnqp jsphx hffzvrj vxmfmjjh nbrh pflk vkjd ndmz (contains shellfish, peanuts)
mqmq fxsrc shkkk pflk rghrrt klcl gbsvjgg rpf ffgs rrngl bscmf nrbl ttzd pqhd tk rzfcn sbtz krh cjf bltzkxx rmngx szcgft mcvjsk cftgsk vzfg mccpbg vgzjp bqcjvv xbdh vdm zdznn hvlc dvrhz zlcbnx mhlv ggqsr rbxnc cdhfzl spql tplp ztv djp fzkxc hzr dzqlq sncl bgvng kjfnqg tvndt hqff ghvj xrjzvh dsbj fpc jcpnmh dsrxrt mkpc szh rblzjb bchbc jpvrvr bclc hhgqp tfn cnnd vrgk xcq hlk sjxxzrd dk spcqmzfg ljsmrl bhgpk qpngxk lhslfpx ccjjp fpfdkl cxhplp tgfcl (contains wheat, nuts)
bkqzk dzqlq rpjcjd spcqmzfg kcmmj ngzp hpdn bthckj shptr qmbxq spql xzzl bbgz zphlmnb vdjjl czs cxhplp fzkxc sjxxzrd smktk zlcbnx mfnc nrbl vdm qlv crsp qbrr mkt srhcd mxpn qpngxk xbdh dpls dvrhz xrjzvh bltzkxx csdbg bmnqp mqmq zvtvzc gtgkt bltrbvz szh hhppz bxcgf pflk dsbj klcl mkhbznt vgh lzxgf ljsmz rlcv btpdk pqhd qfkgx mkpc hrmdt ccjjp tplp (contains fish, wheat, nuts)
szcgft dfk ksbr zpkl ffmgfz mhvtp dzqlq rpf hgcb rgnz pmht ccjjp nb zgfl kjfnqg bltzkxx qmbxq bxxs mhlv rmngx spcqmzfg vkjd spql rtjk bthckj tplp zll nqsdkrh cfl xhlkscn pflk bgvng gbsvjgg vzfg krh hpdn xbdh bclc ljsmz pxldx lzxgf fpfdkl kcmmj zphlmnb crscm btpdk jrvxh ndmz mpbsn jcpnmh (contains fish)
plmpl crscm bltzkxx rbprd nzhtc mcgx xdjhhj lgccp vrgk zphlmnb czs lhslfpx nqsdkrh ghvj shptr spcqmzfg mhlv bltrbvz jcpnmh rpf kjfnqg spql vgh sjxxzrd qlhqg qtxgzpx fxsrc mhvtp qbrr njdfc zgfl dpmcrh vxmfmjjh nrbl dzqlq xcq krh lgm dsbj cnnd jsphx mkhbznt mkpc vpchddj mcvjsk rzfcn zvtvzc cqzqvj bthckj gtgkt mxpn hhppz rghrrt nb xbdh mhsr cxhplp ffgs dpls qgkhxq qlv qfkgx vxkkgd ttzd szcgft tplp jgblz (contains shellfish, dairy)
zbhmgm bgvng jcpnmh btpdk ksbr rpf txs nhsx dfk qmbxq zll bltzkxx rbxnc qlv ggqsr kbzmtz hzr czstl nbrh dvrhz pflk srhcd zdvcnx spcqmzfg shkkk hvlc cqzqvj rlcv crsp bthckj ztrgb fzkxc xhlkscn rtxfsp rznmz bnkgs tgfcl blvlch cmlh bltrbvz hcnmld vdjjl jpvrvr qpngxk xdjhhj ffmgfz xrjzvh cdhfzl ngzp shptr gtgkt njdfc mqmq cxhplp spql vrgk rghrrt dsbj krsl bbhvzz rgnz vgh ffgs ghvj mhsr tplp sncl ngx dzqlq cftgsk mcvjsk bbgz bvskjzc qtxgzpx hhppz mkhbznt cnnd (contains nuts, dairy, wheat)
bclc djp jgblz shptr smktk tpvb mflngx bltzkxx jpvrvr hcnmld krsl bbgz rblzjb tk dzqlq qfkgx lgm tgfcl spql vxmfmjjh kjfnqg hhppz hpdn bnnqz xbdh jcpnmh ghvj jrvxh zdvcnx pqhd hqnnsm bltrbvz mcvjsk krh qlhqg cftgsk rmngx kbzmtz hlk rzfcn bxcgf fkszg gtgkt bsql hzfd ndmz bqrpdxt mxpn nzhtc bscmf ffmgfz nhsx spcqmzfg shkkk pflk nb rhjbx qgkhxq rznmz ftkqfrv kqth vzfg hzr txs gbsvjgg rtjk rbprd ngx ljsmrl zlcbnx xhlkscn zpkl qbrr (contains fish, wheat)
mflngx rpf rblzjb qpngxk vgh hpdn mkhbznt ljsmrl jqrq qlhqg cnnd spcqmzfg zlcbnx lzxgf jrvxh gtgkt mhvtp mhlv jvjmd rrngl bnkgs zgfl ljsmz spql bqrpdxt xbdh qpzcmf tprdg ghvj pxldx xhlkscn pflk jgblz ztv pmht nzhtc mkpc ztrgb ngx tplp tgfcl zpcscz lvrp dtvsk bltrbvz mkt xrjzvh mccpbg bxxs hflzrt zxftz tpvb nb bbgz bxcgf jcpnmh ffmgfz bltzkxx hhgqp (contains peanuts, shellfish)
mhlv qpngxk vkjd bnkgs rghrrt mxpn vpchddj gtgkt jzcrblh dsrxrt jgblz xbdh bltzkxx vdm bbgz mcvjsk gbsvjgg spql fxsrc zpcscz tpvb nbrh mfqvks hvlc zlcbnx nzhtc dpmcrh dvrhz shkkk rpf pflk bqcjvv cqzqvj shptr smktk mkpc crsp nrbl zpkl fkszg rpjcjd dzqlq hcnmld hflzrt mhvtp qbrr zgfl dk xdjhhj pmht szh ttzd mqmq rgnz bbhvzz dpls ffmgfz btpdk jcpnmh bltrbvz vzfg vxmfmjjh dtvsk zll cnnd qtxgzpx ndmz sncl ngzp dfk vxkkgd bthckj czs czstl (contains eggs)
tvndt rpf spql vzfg nbrh zpcscz hrmdt bltzkxx spcqmzfg qtxgzpx mcgx dsbj rpjcjd bnnqz hzr vdm dzqlq kbzmtz zpkl jgblz klcl bltrbvz rznmz rbprd ljsmz njdfc ghvj dk lvrp gtgkt nb xzzl mqmq bscmf jpvrvr krsl rlcv mhvtp bsql ztrgb fzkxc bbhvzz ztv sbtz xbdh bhgpk mccpbg plmpl bkqzk mkpc mhsr xdjhhj fkszg rrngl zbhmgm ftkqfrv (contains fish)
jgblz jsphx rlcv gbsvjgg dzqlq cmlh bqcjvv shkkk dtvsk klcl tplp bxxs qbrr rznmz spcqmzfg czstl zvtvzc rbxnc rpjcjd xbdh hgcb vgh qlhqg ffmgfz crsp ttzd tvndt gtgkt hlk mhvtp bmnqp rmngx mhsr vkjd kjfnqg ksbr zbhmgm mccpbg ztv bltrbvz kbzmtz rgnz bthckj rpf hflzrt qmbxq crscm kqth lgm pmht dsbj bnnqz blvlch spql pflk hzfd (contains sesame, fish)
zphlmnb njdfc ggqsr bqrpdxt ftkqfrv zpkl lgccp ffgs smktk ccjjp spcqmzfg bkqzk hpdn rtjk xbdh sncl xcq zdznn hqff nhsx fpc jpvrvr cjf dfk hflzrt hlk pqhd mccpbg bltrbvz jzcrblh mhlv gtgkt xdjhhj rblzjb rghrrt zpcscz qbrr zvtvzc mkhbznt jvjmd ttzd mhvtp dsbj bltzkxx tgfcl ljsmrl kqth rbprd kcmmj hgcb blvlch pflk ffmgfz rmngx hzfd bbhvzz zgfl hqnnsm tvndt cqzqvj nqsdkrh spql tplp shptr krh tfn ztrgb crsp ghvj hzr rpf rhjbx kjfnqg (contains peanuts, dairy)
blvlch mpbsn spcqmzfg smktk nbrh bchbc bxxs ghvj mfqvks qpzcmf pxldx ndmz qbrr qlv hffzvrj hrmdt ffgs nzhtc frnz vkjd csdbg kjfnqg rzfcn dtvsk jrvxh crsp rbprd krh qlhqg tprdg mkhbznt rhjbx tvndt jsphx nb shptr hzfd rpf dpmcrh mkt jgblz rghrrt zlcbnx bgvng hqnnsm pflk cdhfzl srhcd bltrbvz fpc zdvcnx xbdh dzqlq nrbl vrgk lhslfpx bmnqp bltzkxx hgcb dfk jpvrvr gbsvjgg czstl ffmgfz vzfg (contains wheat)
bsql nzhtc tvndt dfk klcl zbhmgm cxhplp pflk vpchddj vdm tfn pxldx vzfg nhsx nqsdkrh ndmz gtgkt nrbl mqmq srhcd bqcjvv vkjd smktk qpzcmf tk cftgsk jrvxh hhgqp kbzmtz btpdk hrmdt bvskjzc qtxgzpx dvrhz crscm mhlv nb krh zpkl rrngl zlcbnx rpf dpls njdfc dzqlq bltrbvz spcqmzfg ftkqfrv xcq qbrr rbprd rzfcn dk ggqsr rlcv sbtz mcgx qmbxq spql fpfdkl hlk hflzrt xbdh fzkxc zll qgkhxq csdbg mhvtp shkkk szcgft (contains sesame, shellfish)
bhgpk spql jzcrblh bltrbvz vxmfmjjh cnnd lgm spcqmzfg gtgkt pflk mpbsn dk vkjd vrgk bbgz tprdg bclc zvtvzc zpcscz rblzjb krh gbsvjgg bbhvzz qlhqg ksbr mqmq ccjjp bgvng hzr zlcbnx ndmz hqnnsm hrmdt lgccp blvlch rbxnc czs ljsmz qmbxq jvjmd zjdkj kbzmtz sncl nrbl rgnz bmnqp rrngl cfl rpf bxcgf nzhtc dvrhz tplp dzqlq dsrxrt jpvrvr ghvj hvlc vgh klcl zxftz bsql lvrp hzfd ttzd rghrrt qlv bnkgs rmngx dsbj xbdh pmht mkt xrjzvh hhppz shptr btpdk bqcjvv smktk ggqsr hgcb tk ljsmrl hflzrt tvndt bnnqz (contains shellfish, dairy)
txs bqrpdxt fxsrc xdjhhj bnnqz bltrbvz fpc hhppz qpngxk spcqmzfg rbprd qgkhxq jcpnmh szcgft rpf hflzrt csdbg qlv czstl gtgkt zxftz lhslfpx fkszg zpkl ffgs ngx djp ztrgb rmngx bltzkxx spql lgm mfqvks vrgk mflngx tvndt dzqlq jvjmd jpvrvr zgfl smktk mcvjsk bthckj rtjk mpbsn bscmf xbdh qlhqg (contains shellfish, wheat)
jsphx dpmcrh qmbxq jzcrblh bvskjzc zdvcnx fzkxc jrvxh xcq mkhbznt lgccp mkpc rpf dpls ngx dk bbgz gtgkt mccpbg qlhqg zpcscz csdbg sbtz vgh spql dzqlq ndmz jvjmd crscm hgcb qpngxk rbxnc qtxgzpx bhgpk zvtvzc szh djp mflngx vrgk jgblz njdfc hzfd nrbl bchbc sjxxzrd spcqmzfg vdm xbdh bltzkxx fkszg rblzjb rpjcjd hhppz cfl bthckj pmht cftgsk pxldx mcgx mfqvks bltrbvz xhlkscn hzr tfn (contains sesame, shellfish)
vzfg bthckj blvlch rtjk bqrpdxt zvtvzc bvskjzc fpc zphlmnb nbrh zxftz xdjhhj csdbg cfl xbdh zdvcnx frnz zlcbnx mkhbznt xcq czs lzxgf mhsr spcqmzfg szcgft xhlkscn ggqsr tprdg cqzqvj qlv bsql mkpc qlhqg rpf bbhvzz dvrhz jzcrblh gtgkt mflngx bltrbvz nb bxxs klcl mqmq pqhd sncl ftkqfrv tfn hpdn qbrr spql ffmgfz bltzkxx dzqlq lhslfpx zbhmgm (contains eggs, fish)
bbgz xdjhhj bclc vkjd szcgft rrngl mcgx sjxxzrd zpcscz rpjcjd jzcrblh tgfcl zjdkj hhppz dpls tvndt zlcbnx bqcjvv ngzp mhsr qpngxk mpbsn tfn ngx gbsvjgg lgm xcq xbdh cftgsk mkpc ztv njdfc rtjk bqrpdxt jqrq szh ttzd cqzqvj mhvtp dpmcrh qgkhxq klcl pflk spcqmzfg mflngx rmngx frnz cxhplp rzfcn lhslfpx hqnnsm hpdn hzfd hcnmld hffzvrj blvlch nrbl hgcb ztrgb mkt dzqlq fzkxc jgblz ffmgfz rhjbx vrgk xhlkscn rghrrt spql vgh vxmfmjjh jvjmd bltrbvz jcpnmh ggqsr qlv rlcv zdznn zll xzzl vxkkgd qmbxq hrmdt pxldx bkqzk rpf (contains eggs)
nb dzqlq jvjmd bltrbvz sbtz hffzvrj lgm mfqvks vdm txs ffgs mqmq qpngxk hhgqp njdfc hrmdt mcgx qlv nrbl fkszg rzfcn bltzkxx dfk mhlv vgzjp spcqmzfg hqnnsm rpf tplp rpjcjd hhppz xbdh bbgz qgkhxq hflzrt blvlch mfnc bxxs hqff mxpn fzkxc cnnd nzhtc rghrrt kjfnqg qlhqg bbhvzz bnkgs tvndt bxcgf spql bmnqp hvlc xzzl (contains sesame, peanuts, eggs)
ksbr kjfnqg mpbsn qmbxq qbrr qgkhxq gtgkt mcvjsk btpdk mkt dzqlq ggqsr rgnz kbzmtz rpf bsql tk hhppz zjdkj bltrbvz jpvrvr tprdg vgh hzfd szh szcgft hflzrt hlk rrngl bbhvzz gbsvjgg kqth bhgpk vzfg ljsmz jcpnmh mflngx bmnqp dsbj mcgx dsrxrt klcl rblzjb xbdh rpjcjd bqrpdxt mkhbznt frnz krh smktk hgcb jrvxh spcqmzfg dtvsk qlhqg dvrhz fzkxc rlcv txs zpkl cfl zdznn xhlkscn lhslfpx vxmfmjjh nqsdkrh rghrrt bltzkxx qpzcmf jgblz ccjjp pflk bclc mqmq shkkk dk (contains dairy, nuts)
tk bqcjvv pflk mxpn rgnz rmngx vdjjl fpc vrgk ljsmz mfqvks vgh ffgs nhsx bchbc rpf zll dtvsk nqsdkrh vkjd czstl dzqlq hqnnsm zdvcnx bltzkxx hcnmld spcqmzfg srhcd sncl hgcb ngx rzfcn jcpnmh mqmq nbrh bbgz dk mflngx bltrbvz crscm ndmz spql qfkgx bgvng zpkl jrvxh mfnc zphlmnb zbhmgm sjxxzrd dvrhz ffmgfz hrmdt fzkxc jqrq cnnd szh (contains nuts, shellfish)
bchbc zphlmnb frnz fzkxc xbdh zpkl btpdk csdbg zbhmgm nrbl qpzcmf rtjk mxpn cqzqvj hhgqp zpcscz bgvng mpbsn shptr hzfd vdm fkszg lvrp lzxgf bltzkxx dpmcrh nzhtc kbzmtz vxkkgd hflzrt kqth gtgkt ggqsr rghrrt bclc mfqvks dtvsk bltrbvz vgh tprdg zvtvzc txs pxldx bbhvzz sncl mhvtp kjfnqg hcnmld krh hzr blvlch qfkgx spcqmzfg qtxgzpx bqrpdxt krsl rbxnc dzqlq rpf pflk fxsrc zlcbnx bxcgf zdznn jgblz (contains fish)

78
21/main.py Normal file
View File

@ -0,0 +1,78 @@
from dataclasses import dataclass
@dataclass
class Food:
ingredients: list[str]
allergens: list[str]
def parse_food(line: str) -> Food:
delim = line.find(" (contains ")
return Food(
ingredients=line[:delim].split(" "),
allergens=line[delim+11:-2].split(", ")
)
def read_input(filename: str) -> list[Food]:
with open(filename, "r") as f:
return list(parse_food(line) for line in f.readlines())
def count_ingredient_occurences(foods: list[Food]) -> dict[str, int]:
ingredient_counts = {}
for food in foods:
for ingredient in food.ingredients:
ingredient_counts[ingredient] = ingredient_counts.get(ingredient, 0) + 1
return ingredient_counts
def get_allergen_map(foods: list[Food]) -> dict[str, set[str]]:
allergen_map = {}
for food in foods:
for allergen in food.allergens:
if allergen in allergen_map:
allergen_map[allergen] = allergen_map[allergen]&set(food.ingredients)
else:
allergen_map[allergen] = set(food.ingredients)
return allergen_map
def part1(foods: list[Food]) -> int:
allergen_map = get_allergen_map(foods)
allergen_ingredients = set()
for ingredients in allergen_map.values():
allergen_ingredients.update(ingredients)
count = 0
ingredient_counts = count_ingredient_occurences(foods)
for ingredient in ingredient_counts.keys():
if ingredient not in allergen_ingredients:
count += ingredient_counts[ingredient]
return count
def find_with_one_ingredient(allergen_map: dict[str, set[str]]) -> tuple[str, str]|None:
for allergen, ingredients in allergen_map.items():
if len(ingredients) == 1:
# `min` is used just, because you can't use indexing on sets
return (allergen, min(ingredients))
def part2(foods: list[Food]) -> str:
allergen_map = get_allergen_map(foods)
allergens = []
while True:
pair = find_with_one_ingredient(allergen_map)
if pair == None:
break
allergens.append(pair)
allergen, ingredient = pair
del allergen_map[allergen]
for ingredients in allergen_map.values():
if ingredient in ingredients:
ingredients.remove(ingredient)
allergens.sort(key=lambda p: p[0])
return ",".join(a[1] for a in allergens)
if __name__ == "__main__":
foods = read_input("input.txt")
print("part1: ", part1(foods))
print("part2: ", part2(foods))

4
21/test.txt Normal file
View File

@ -0,0 +1,4 @@
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
trh fvjkl sbzzf mxmxvkd (contains dairy)
sqjhc fvjkl (contains soy)
sqjhc mxmxvkd sbzzf (contains fish)

53
22/input.txt Normal file
View File

@ -0,0 +1,53 @@
Player 1:
18
19
16
11
47
38
6
27
9
22
15
42
3
4
21
41
14
8
23
30
40
13
35
46
50
Player 2:
39
1
29
20
45
43
12
2
37
33
49
32
10
26
36
17
34
44
25
28
24
5
48
31
7

68
22/main.py Normal file
View File

@ -0,0 +1,68 @@
def read_input(filename: str) -> tuple[list[int], list[int]]:
with open(filename, "r") as f:
player1, player2 = f.read().split("\n\n")
player1_cards = list(int(l) for l in player1.splitlines()[1:])
player2_cards = list(int(l) for l in player2.splitlines()[1:])
return (player1_cards, player2_cards)
def play_combat(player1: list[int], player2: list[int]) -> list[int]:
while len(player1) > 0 and len(player2) > 0:
card1 = player1.pop(0)
card2 = player2.pop(0)
if card1 > card2:
player1.append(card1)
player1.append(card2)
else:
player2.append(card2)
player2.append(card1)
return max(player1, player2)
def play_recursive_combat(player1: list[int], player2: list[int]) -> tuple[list[int], bool]:
seen_games = set()
while len(player1) > 0 and len(player2) > 0:
seen_game_value = (",".join(map(str, player1)), ",".join(map(str, player2)))
if seen_game_value in seen_games:
return player1, True
seen_games.add(seen_game_value)
card1 = player1.pop(0)
card2 = player2.pop(0)
player1_won = None
if len(player1) >= card1 and len(player2) >= card2:
_, player1_won = play_recursive_combat(player1[:card1], player2[:card2])
else:
player1_won = card1 > card2
if player1_won:
player1.append(card1)
player1.append(card2)
else:
player2.append(card2)
player2.append(card1)
return max(player1, player2), len(player2) == 0
def calculate_score(cards: list[int]) -> int:
score = 0
for i in range(len(cards)):
score += cards[i] * (len(cards)-i)
return score
def part1(player1: list[int], player2: list[int]) -> int:
winning_cards = play_combat(player1.copy(), player2.copy())
return calculate_score(winning_cards)
def part2(player1: list[int], player2: list[int]) -> int:
winning_cards, _ = play_recursive_combat(player1.copy(), player2.copy())
return calculate_score(winning_cards)
if __name__ == "__main__":
player1, player2 = read_input("input.txt")
print("part1: ", part1(player1, player2))
print("part2: ", part2(player1, player2))

13
22/test.txt Normal file
View File

@ -0,0 +1,13 @@
Player 1:
9
2
6
3
1
Player 2:
5
8
4
7
10

1
23/input.txt Normal file
View File

@ -0,0 +1 @@
469217538

102
23/main.py Normal file
View File

@ -0,0 +1,102 @@
def read_input(filename: str) -> list[int]:
with open(filename, "r") as f:
return list(int(c) for c in f.readline()[:-1])
def take_cups(cups: list[int], start: int, length: int) -> list[int]:
taken_cups = []
index = start % len(cups)
for _ in range(length):
taken_cups.append(cups.pop(index))
index = index % len(cups)
return taken_cups
def put_cups(cups: list[int], start: int, target: list[int]):
index = start
for value in target:
cups.insert(index, value)
index = index + 1
def simulate(cups: list[int], moves: int):
max_value = max(cups)
min_value = min(cups)
current_cup_label = cups[0]
for _ in range(moves):
# take 3 cups
taken_cups = take_cups(cups, cups.index(current_cup_label)+1, 3)
# determine destination cup
destination_label = current_cup_label - 1
while destination_label not in cups:
destination_label -= 1
if destination_label < min_value:
destination_label = max_value
destination = cups.index(destination_label)
# put back the 3 taken cups
put_cups(cups, destination + 1, taken_cups)
# move current cup
current_cup_label = cups[(cups.index(current_cup_label) + 1) % len(cups)]
def simulate_lookup(next_cup_lookup: list[int], current_cup: int, moves: int):
max_value = len(next_cup_lookup) - 1
min_value = 1
for _ in range(moves):
# take 3 cups
taken_cup1 = next_cup_lookup[current_cup]
taken_cup2 = next_cup_lookup[taken_cup1]
taken_cup3 = next_cup_lookup[taken_cup2]
# determine destination cup
destination = current_cup
while True:
destination -= 1
if destination < min_value:
destination = max_value
if destination != taken_cup1 and destination != taken_cup2 and destination != taken_cup3:
break
# put back the 3 taken cups
next_cup_lookup[current_cup] = next_cup_lookup[taken_cup3]
after_destination = next_cup_lookup[destination]
next_cup_lookup[taken_cup3] = after_destination
next_cup_lookup[destination] = taken_cup1
# move current cup
current_cup = next_cup_lookup[current_cup]
def part1(cups: list[int]) -> str:
simulate(cups, 100)
num1_index = cups.index(1)
return "".join(map(str, cups[num1_index+1:])) + "".join(map(str, cups[:num1_index]))
def part2(cups: list[int]) -> int:
# create lookup table for the next value
next_cup_lookup: list[int] = [0]*(len(cups)+1)
max_value = max(cups)
cups.append(max_value+1)
for i in range(len(cups)-1):
cup = cups[i]
next_cup = cups[i+1]
next_cup_lookup[cup] = next_cup
for next_cup in range(max_value+2, 1_000_000+1):
next_cup_lookup.append(next_cup)
next_cup_lookup.append(cups[0])
# perform the simulation
simulate_lookup(next_cup_lookup, cups[0], 10_000_000)
# calculate the final result
star1 = next_cup_lookup[1]
star2 = next_cup_lookup[star1]
return star1 * star2
if __name__ == "__main__":
cups = read_input("input.txt")
print("part1: ", part1(cups.copy()))
print("part2: ", part2(cups.copy()))

1
23/test.txt Normal file
View File

@ -0,0 +1 @@
389125467

471
24/input.txt Normal file
View File

@ -0,0 +1,471 @@
neswsesewswswswswswneeswswswswwwnwsw
nenesenenwneenwnwweneswnenenenwnw
wewnesesweswsenwnwnwsww
eeneswneewneseneeeseeweeesenwe
nwnenenenenenewnwnesenwnwnenenenenenwnese
nwwenwswwnwwwenwnwwnwnwwwnwnwsew
nwnwnenwnwnwnwnwnwswnwnenwswnwnwnenenwne
swsesenweseswseseswswnwswswswseesesesw
nweneneswnenenenenwnenwnwswswnwnwwswsenwne
wnwnwenwnwnwnwnwsewnwnenwnwwwsw
senwewwsewswswnwseswsenwswswsewnenww
nenwnesenwnenwnwnwnenwenwswnwnewnwswnw
neneswwsesenwsesewnenenenenenewenwne
weneneeneneneneeene
ewnwsenwwwwnwnewwneswnwsenwwnwsesww
neenwnwnenenenwwnwnwnenenenenwswnwnenwnwe
wwnwswwwnwwnwwwwwwnewnw
neneneneeneneneneneneswnenenenenenenene
nwwnenwnenwnenenenenesenenwnenenwnwnwne
nenenwsenwsesesenwwnwneenesewnenwnene
nenenewneneeneneneneeseneswnenenenwnene
seseenwewseswsese
seseeseseseseswsesesesesesesesenesesese
sewswswnwswswswswwew
wseswnwnwnwnenewnwnwwnwwnwnwnewnwsw
neeeenenwneeeeeeswneneneeneee
swnwnwnwnwnwnenenwnwewnwnwnenenwnwneenwne
swswsweswseeswseswneswwswseswnwsesww
swnewwnewwweewwwwnwsewwwww
eneswswwewwwswswesewwswswnwwe
eswnweeeeeneeeeeeesweeee
wswswnweswwswnewswseswswswswswswswe
nwewnwwwwnwwwwneswswwwwwnew
nwnwnwnwnwwnwnwwenwnwnwnwsenwnwnwswnwnw
swswnewswswswswwswswwwwweseswswswnww
swneewswswswwswnwnwswwnwwsenwswese
nenenenwswnenenwnenenwnwnwnenenwnenenwne
nwnwnwnwwneswswenwenwenwnwnwnww
neneseswnenwneneneneneenesw
nweswswnwsewswnwwseeseneswnwneene
wwwwswwwnwswwwswsewewwswwsw
wewswwewswswswnweswwswswsweswwsw
sesesesesesewseswsesesesesesenesenesesw
wsweeneeeeneeeene
eseeeeeeeeeeeenweseseseee
wesesewswnesewneeswseewsewnwesesw
seweeneneeweeeneneeeneneeseew
wswseswswwenwswwwswwwsw
eweweeewseneswseenweswnweswene
wwswwwwwwwsewnewswwwwswwww
swseewseneeneswswnewneesewsenwese
sewwwwwwwnwwwnwwww
seseneeseseeenwsesweseeeseswsesesese
neenewnwneneeeneseneneeneseeneneene
nwenwwwswnwwwwwnw
nwseswseseswneseeswneswswneswswsewswse
swswswwswwswwswnewwswwswwseswswe
wnwwnwwnwnwsenwnwnwwnww
swswnwseseseswsesesesewenesewenwsese
eseseesenweeseswseseenwee
nenwseseneeeeeenweseenweweee
swsweseswnwswswswswswswseswswswneseswsw
wnewenesenesweswwnwwseesesesee
wsesesesewseneseseesesesesesesesesesese
seeseeseeeseeswsweesesenwneenwnw
nwwnwnwnwsenwnwwswnwnwsenweswnwnwnwnwnee
esenenenenenenenenenewnewnenenenenene
eswswswswswwswswswwnwswswswswswwswsw
nwnenwnwenwesenwsewsenwwsewswnwsenw
nwnwnwwnwnwnwwnewwwnenwsenwnwwnwwsw
weeseswwenwnwwewwwwnwseenesw
wwswswswwswwwnwwwswsewswwsw
ewsewweswwwewwwwwwnwenwnw
eenwnwnewneweneswseenewseswwsesw
neenenenenenenewwneneseneneneeneene
seswnwswswseswswnwnwseseseeswseswswseswsesw
seseneswseewsesweseseseseseswnwsesesese
nwnwnwnwnwwnwnwnwnwnwenwnwwnwnwwnwnw
seswswsenwwseneseseseswswneseswnesesesesese
eseeseeeeeenweenwesweneenee
nwneswnwnwnwnwnwswneeseswenwswnwnwnww
swsesweswseswswnwswswswswswswnweswswsw
neseseesweseeeseeesewneeewsene
neneswnewneneswseswneswnenw
seweeweswwwnenesewwwnwnewsew
swwweswswswwswswwswswnwswswwswswsw
wneneenenesenewsenenwneswnewneenenw
senwnewnwnwnwnwnwnwwnwswwenwsesenwnwne
wwwwwwnwswsewwwwwwwsw
neneweneeeeenenweneeeeeenwsese
swswsweswswswswswswswswnwseseswswseseswsw
swswswswseswswnwswswseswswnwswneswsee
nwewnenwseneneswsenenenewnenwnesenwnenw
eseswnwswswseneswseseswswseeswswswwsw
seseeeseseseweneeseeeesesesesesese
eewnweswswsweeenenwwnwse
wwswwwswwsewwswnwenwnwswswwwesw
wwewwwwwwwswwwnewwwwww
nwenwwnwnwnwnwneseswnwnwnwnwnwnwnene
nwwnewnwnwwnwnwnwwnwnwsenwwwnwnwww
sewswneswseeswseneseswswswsewneseswnw
newneswswwwwsweswswenesesewneswsw
nwnewwwwwnwswwseswwwwnwwseese
wwwwnewwwwwwenewswwwwwsww
eseeeeeewseneswswseweeneesesee
nwnwnwswnenwnewnwenwnwnwsenwenenwnwwnwne
swseswseswsenesewswseseswswswseswsesese
swswsesesesweswnesesesewsese
eeweeeeseseeesee
swnwnwnwnenwnwnwnwnwnwnwnwnwnwwnwsenenw
nwwnwwwnwswwwwwwnwwewwewww
swnenenenenenenenenenenenenenenenenene
swswneswswswswswseswswnwswswswswswewsw
nwneswnwnenwnwnwnenwnenenenenwnwnenwnwenw
nwnwnwnenwnwnwnenwnwnwnwnenwsenwnwnwnwwnw
wnwnwwnwswwwsenwnwnwnwnwwnewseeww
nwenwnwnwenwnwwnwnwwsenwnwswwwnwnwnw
eeweeseseeeseseeseseseseseese
neeenesewswsweeneenweesenenwswesw
nwwnwnwnwewwnwnwnwwnwwnwnwnwewnwnw
wnwneswwwswwwewwwwswwsewwswne
nwnwsesenenwnenwswseswnenwwnwnenwnwnwnene
nenenwnwnewnwswnwnwnenwneneneeneenww
wwnwswnwnwnwnwnwswswsenwnwenwneesee
nenwnwnwnwnenenwnenwnesenenenenenwnwsenw
swseswswseswseseseswneseswswswseswswswsw
swswsweneswnwwsweswswswswswswswnesw
wnwwwwwwwwswwwewnewwnwwwwse
nwnenenenenenwnwnwwnwenwnwwsenesesenwnw
nenwneeeeeswswneeeeeneeeneswnee
nenwnwnwnwnwnwsenwwnwnwnwwnwnwnwsenesenw
nwnwwnwwswwwnwwnwwnwsewwnwnewnw
wnwwwwenwseswnwswewnww
ewwnwwwswwnwwnww
nwnenwnenenenenenenenewnesenene
sesesesweenwsenwenwsenweesenwenwnw
neneeeeswenwneeswsenwenenenenenenee
seeesenwswwesenwsesenwseseswesenesee
nenwnwnenwswnenwnwsenwnesenwnwnwnwnenenw
eeeeeeeeeeesweenwswne
esesweswnwsenweeesesesenweeesww
eseseeseseseseseweeseeeseesee
swnenenenwnwnesenenewnwneeneneneenenesw
neneneenenenenewneneneseneneneneeewse
wnwnwnwnwenwnwwewswwwwwnwsewwwe
neneeneneneneneneneneneswne
seswswseseeswswnwseseneswswseseseseswsese
wswnwswweneweenwwswswneswswwseswne
eswwwswswneswwswwnwwwenwwwswsewsw
wswswswswenwnwnwswswswswswswseswneeswe
wwwwwswswwwenenwnwnwwnenwsesww
wseweeenwnewneneneneseeneneenwswse
senwwnenwnwnewseswwwsewswnewneene
nenwnwnweneneenesesweneneneneneneswsw
swseswswswswwswswswneseswseswsewswswnesesw
enewnenwnenenenwsenenwnwnwnenenwseswene
wwnewwwswwwwwwwwwswsewwww
wsenwnwnewnwnwnwnwnwnwnwnwnwnwnwwnwnw
wenwnwwwwnwwsenwneswsewwsewnwnw
neenewneneeeneeee
neseswnwswswnwnwseseswseewseseneseswseswsw
nenenewwnenenewneeenenenweswsene
seeeeesesesweeenweesenwseeseswe
swesenweseewseeseeswswesenwenenewne
seseseseseseeeswnwswne
wwwwwwwwwwnwnwsewnwwwwsewe
nenwnwneeswnwnwenwswswnwnwnwswnwnwnwnwnwnw
swswswesewswswseswswswseswswseswswsw
neneenenenenenenenenenewnenenenenenene
wneseenenwnwwswseswswwnewnwwwww
nwnwnwwnwnwweseneswwnwseenwnwnwwnwsw
nwnwsenwnwnenwnwnwnwsenwnwnwnwsenwnwnewnwnw
wsewneeneneneneneneeeneswe
nenwnwnweweswneswne
eseeeeeseeeeeeeeeweewee
newnwswnenwneneneneeneweswnenwnee
wwnwwwwwwnwwnwnwnwsewnwwwww
wwnwwnwwnwswwnwwwwnwwwnweww
neseseseseseswsesesesesesesesesesesesesw
nenwnwnwnwswwnwwnwnwwnwswnwnwnwwnwnwe
neenweeeeeeeeeeneeswseeeswe
swswswswwswswnwswswsesweswswnwswwsw
wnwsenwwnwwnwnwnwnwnwnenwnwnwnwnwnwnw
seswnwswenesesewneswnwsewsesesenenesw
eneewnweseswweeenee
neeneswneswsweswwnenweee
eeseesenewneeeneneswenewne
swnwsewnwnwneweswnenwneneseesenwwsesw
wseewswwnenwswswseesweseneswnwswese
seseseseseswsesesewswseseswseseseseswnene
seseswsesesewnenewseneswnesew
wswseswnwwwwewwwwwswwwwswww
nwnwwnwnwnwnwnwnwnwnwwnwnwnwnwnwenwe
nenwsesenenenenenwnwnwnenwsenenwnwnenwnewne
nwnenenwnenwnwswnewnwnwenenwnwnwnwnene
neseswswnwnwnwneswsweneseseswswnwnewesw
swwsewwwewswswnwwswswwnwsw
neweeswneeeneeneneenwswneseewnw
sewswwweseenwneesewwsewswneee
wwwnwnwswwwwwwnenwnwnwnwnwnwwnw
wwwswwwwwwwwnewwwwneswwsew
nwseswswswneswenesewseeswswswswswnenw
enwswseeeseseswesesesesesenesenwseese
nenenwneswnwnwneneenwnwnweswnenwnwnwnwnw
nwswweneeeeeeeeeeneeeswnese
sweseseseseeeswenwneeeeese
seswswseeswsesewesweswswsesesesenwnwsesw
eenwnewesesewseneeswseewsweenwe
seseswnwwwnewwswweswnwwnewwesw
eeeeeeseseseeseweeeeeeseenew
weseeneswenwewe
swswsesenwseswseseswseneesewswsesesesese
seswseseswswswseseswswswneswswswsesesw
swwswwsewswwswnwwsesweswnwsenwnwnee
eneweeneneneeeeeeee
sesesesenesewsesese
nwnwnenwnewnenwnwnwsenenwnenwnwnwnwnwne
swneswseseswswnwseseseseseswwseswswsese
swswsewnewswwswswswswnenwwwneswsewsw
nwswswsweneseseswseneswseseswnweswew
swseswswswseswswswswseseswseswnesesw
nenwnenenwenwnwnwnwnenenwwwenwnenwne
swwnwnwwwwnwewwnwnwnwnwnwwnw
esenwneswnenwneeswwswenwseneseeenw
eeeswsenwweneenenenesenenewsenenesew
wwswsenwwwnewwewwswwswwwwne
wswesweenewswswnwswsweswnwnwswswe
swswseneswswswswsewswsw
wnenenenewneenesenwwseeneneswne
seeseseseeseenweewseseneseseeseese
seseesesewseseseseseesweseneseesese
swnwnwneseswswswswwe
senwnwnwnwnwnwswnwwnwnenenwwnwnwnwwnww
wwwsenwewwswswwnwsewwewswsww
swwswswswneseseseswsewseswswneswswsesw
seseeeseseseeseseseseseesewesesese
seseeeseweeneseewseeeeeseee
nesenwnwnenenenenwnwnwnwnwnwnenenwsenw
seseseeesesesenweseseeswseseseenese
swswswswswswswseswswswswswswswnenwswswswsw
senwwswwswswwswswwswswswneswsweswsw
swesenwswseswnwnwseseswseswswsweseesesw
wwswswwwswwweswwswswwswswwswsw
swewsweswswewnwwnewewwsewnwswww
wnewseseswswnwswwnwnwwnwswseswseeew
swsenwseseswswseneswswseseseswseseseswsw
swswwwewswswswwwweswwwwesww
swswswneeswnwswswswswswweswswswswswnwsw
enweneeseeneneswswsewneneneeeene
wswwswnwwwewwnwswesewswseenwe
sesesesweeeseeewsenwseseeeseeee
swswswswnwswswswswswswswsweswswseswswswsw
seseewseseeseesesesesesesesesenwsese
eweeseweeneeeeneeeeeeeeese
eeeeeeeeeeeeeeenweeeesw
nwswswswwwwwwwswswweswwwswswsw
weswswnwswweswnwnwneswsenesewwenesw
enweeseeseeneseseseewseeseeesesee
nwnwnwnwnenwwnwnwnwnwsesenwnwwwnwnwe
seseseeneseeseseeseeseeseeeweese
sesesweeswseswsenweswseswnwsenwswswsw
sesweseeeeeeenwseswnewse
swwnwwnewwwwwwnwwwwwnwnwww
swswswneswswswswswswwswwwswwswwesw
wnewneneweneeneseswsenewnesweneene
eseeeseeeseenesw
sesenwseneseseseseswswswsesesewsesesesesw
nwneneneneswnenwnwnenenwneenenwnwnenwnene
neneenewnenenenenenenesweeeeeesee
nenwwswnwenwnwnwsesenenww
eenweswsweeeeneeneeweneene
nenewwneseenwnenwnwsenwnenwwnw
wwwnenewwsenesenwnwsewewwswswswnew
seswwswneswswswwnwswwswwswswswwswwsw
ewneneeeeenweesweswenweneneene
sweswsenwswswwswnewnenewswenweenw
sweweseesesesesewsenwseeweenesenwse
swnwnwwwwwwwne
nwnwswswseswswswswwswswswswswswse
seswseseswswseseseeseswnwswsenweswseneswse
eeswnweseeneeeeseewseseseseesesee
swswswswswswseswwswsweswswneswswwnenw
wnwenwwwwnwwwwwnwwnwwww
swwswwswswswswswwswwnwswswswswswswse
nwwwwwswnwwnwwnwwwwnwnwneww
eeneswenwnwswnwsweswswnwswnenenwnwse
swswseswswseswswswswneswswseneswseswswse
neeeeeeeeeeneneweweeeene
nwnwneenwnwnwnwswneswnenesenwswewnww
weswwswswnesewsewswswwneneseeese
wswswswseswswnesesesw
enwneswwnenwnewnenwnweenwnenwneswnesene
eswwswswswswswwswswswwswswswnweswswsw
eswsenweswswnwswswswswsewswwwnwswswsw
nenwnenenenenwnenenewneenenenenwnenene
wnesesenewwwsewwwnwnwwnenwwswnewsw
wwswswwswwswswwswswwnwswseswswswsw
neneneneneswnenwnenenenwnwswnenwswnenee
sesesesenesesenesewsesenewseswsesesese
wneewseswwwnewswswswswenwnewwww
swwnwswswswswnwswswswwsesweswswwesw
seseswseswseseswseswnweseseseseswseswse
swswseseswswswswsesweswnwseeseswnwsese
neswswnwnwsewnwenwwnwwweenwsewnw
ewneeneneenesweneeeneeenenenene
nwnwwnenwnwwnwnwnwsewnw
eeneneeseenweseswneesweneenenenw
neneneneeneneeneswnwnwneswnenenenenenenwne
nwneneswsewswnwsewwnenwewnw
nenwsenenwnenenenwnesenenenenenenenenwse
seeeesesenwseeesesewsewseeseese
nenenenenenenesesewnenwnenenenwnwnwnenw
neeneneeewneeneneneneeneenenenee
wswnwswseewnwnweneewwneww
seseenwseweswnwneenenenenwnwseeneswse
seswsenwswseeseseswswswseswswseswsesenwsw
neseeseswseswsesewswswnwswwseswnenwsesw
nwnenwswnenenwnwnwnwnwsenwnw
nwnwwswnwwenwnwwnewnwnwnwwnwnwsenwnw
seseeswseenwnwseneseeeesesewswsesese
neneswnwenwnenenenenenenwnenwnwnwnwnwnesw
swswswseeswneswswswswswsweswwneswswswnw
swseswswswswswswneeswwswwswswswseswsesw
sesesesewnwseseseseseseseeseseseseswsese
neenenwwenwswnwneswsweenwnw
wwnwwwnwwnwwnwnwnwseenwwnwnwnwnwnw
swneswsesweswswswswswswswswwwswwsw
esweeneeneeeneenesweeee
eeeeeenweesweeeeeeweew
seseswswewseswwseeswenwnwswseswswse
nenesesesweswnenwewseewnwseswewne
eseweseseseseeesesesesesesesesesee
sesenwswseeswswsesesesenwseseseeneseese
swnwswswnwnwsenwneenwwnwnenwwneenwe
nwwwwnwnwnwnwnwwnwnwnwswewwwnwwnw
seseswsewesesewseseseseseseeseswsesese
senwswwnwnenweesewswenenwneneswswwne
eseweneswsesewwnwwseseswswnesenesew
swwswswswswseswswswswsweswswsw
eesenweweseseeeeeeeseeseseese
seeeeneenewweeene
nenwswswseeewsewwnwwnwwwswwsenw
swswswswwwnewwswnwwnewwewewsww
sewwswswneeswwnwswwwswnewswwswswsw
swwewwnwswswswnwnwweswneeeeww
swswwswswseeseswneeweswswnwnwswene
newwnwseesewsesenwsewseewesenwene
wswwwnwwsenwwnewwnwsewwnwwne
swswseseswnweswnwneeswneswsesesenwwswnesw
nwnwnwnwwnwnwnwsenwnwwnwsenwnwnwwnenwnw
nwswwenwswsweswwswswwseswswswnwsesw
nwewwwnwwsenwwwnwesw
wnwnwnwnwnwwnwsenwnwneswnwenwwsenwnw
swnenwnwwnwnenwnenenwnenwnwenwnwenwnwsw
swswnwswsweswwseswnwwswswnwsenwswew
eeeeneeswseeeeeeeeeenenwene
neeeneneneeeneeeeneswneneenenee
nwnwnwwnwnwneenwnwnwnwsenenwnwnwnwnwnw
eeeseeeswseenwenenwseeseeeesw
neeneneeesenweeeene
neneenenenesenenenenenenenenenenenenwne
senwwswswwswswsewneseeseswneswswswswene
neeeeneeeseseeeeseeseeseesesww
eeeneneenewneneseneneneeeeneee
swnwwnwsenenwnenwnwsenwnwnenewnwenwne
neneneneneenenenenwnenenwwsenenenenenenw
wwnewwwseswwnewww
nwenesenwnwnwnwnew
swseseswseswseswswswenwswswseswseneswse
senwswsweseneeeeneeneeswnesewswwnw
eenenwswswnwswewwneenwwwwsewsenw
seeeenenwneneeneeeneeswe
newenweeneswneneswne
swswswseswswsenewwnwwwnwnesweswwww
nwneneeeneswneneneneeneeneeneeene
eeeeeeesweeeeewnweseeenw
swseswswswswswsewneswnwswswsesesesesesese
nwnwsenenenwswnwnenenwwsenenwnenewseswse
wsewswwswwwswwnewseenenenewwwse
nwnewnenenenenenwnenenenenenenwnenwsenw
wnwwwsenewwnwwwwwwwwwwww
nenwnenewseeseeswswenwwsesewsw
enwnenesweneneneneswenenwswneneeenenene
seeeeeenwnweeseeseeswseseeeee
wwnwwnwswwwwnwwnenesww
seswswswneseseseseswseseseswsesesesewswse
wnenwseseeseswswwseseswswswswseswswseswsw
wnwnwnwneenesenwnwnwnwnwnwnw
nenenenwneeneneneneneneswnenwnenenenenwne
sewwswswswwswswwswwswnwseswwswneswsw
eeeneeeswsenwwseseeeeeeeseese
swswswswswswneswswswswswwswswswsw
newswwswwnenwsewwwwwwwwwswsew
sesesesenwseseseseseseeseseswsenwsesese
swswsesweswwseswwswnwswswswswswwnwnw
nenenwneneswnenwsenewnesesewnwnewnee
sesesesesewneseseseneseseseseseseswsesee
nenenenenwwnesesenenenesesenewneenwene
wnwwwwsewnwswneenwwenwswwwwww
swseswswnwswswseswswswnwswswseseeswswswswsw
wnwwnwwnwwwnewwwnwwswwwwwsewe
neeeeneneenenenesewneneeneeenene
seneenweeneeeeeneenweeeeseee
enewnenwsenenwnenenenenesenwnenenwnenenw
neeneneswneneweenwneneeneeenenee
wwwswwswsweswneswswwswsewswswww
swwwswswseswwwswswwsenenwswwwwnw
neenwneneneeseswswewnwswnenwnenenwnenwne
seeseewwweeseweseeseeesesenwe
swneneneneneneneneneneneeneneneneenene
wwswseesweswneenenwnwseesewswnwene
seseseswseswswseswseneseseswswseswsesesew
neeneneseenewenenwswnweeneeswneswne
seswwneswsewnwnewsenwswswenwww
wwsewwwwwwwnewswwewwwwwww
nenenenwnenenenenenwnesenenenenenenenene
eseswswswwnwswneswneseeswswswswswswswww
neeesweenewenenweneneewnenenenene
nwswwwnwwewswwswwwswseswwwwswswsw
wwenwnwewswwwnenwwwnewnwswww
nwneenenwswwwsewewwsesewwsewswnw
seswseneswseeenenwseeseswneswsesesesenw
eeseswweseeseseesesesesenw
neseseseewwwneseseenwseseeseseeee
seswnwsweseseeswseseswnwnwsesesenweseswe
neseseswswswswsesesw
nenenenewnenwnwnesenenenenwnenwwneneenene
sweseseeswsesenweseesesewsesenwenesee
senenenenwwnwwnesenenesenenwnwnwnewnwe
swwnwseneswseseseneseseneseswnwnesewwswse
wnwnwnewnwnwwnwnwnwwsenwswwnwnenwwww
wnewwwnwwwwwsewwwwwwwnwwnw
eeesenwenesenweenwesweneeeeee
wsesenewnenenenenw
eeeeeseneeweneeeeeeeeee
eneseneweneneeeeswneeneeneneww
nwnwnwnwnwnwnwenwnwnwwewnwnw
seseseswswseseseswsesesewseseseseseswne
swwwsweswswswswwswswswswswneww
seeenweseweseesesweeeeeenwe
nweneneeneeeeeeeeneseeeneene
wswnewwwwwwwwswswwwswewwww
swswswseswswswwseseswneswseswseseswswsesw
swswswswseswswswsenwnweswswswseswsewesw
nwswnwwnwswnwnwnenwnwenenwsenwne
nwwnwesenwnwnwnenwwwnwnwewnwnwnwnwswnw
wswswswnwwwwwneswwswwsewwswwsw
nenewneneneeneewnenenenenenenwnenenene
nwseseswswseseseeeseeseneseseseseese
eswseeseseeewnwseeseseeeseseesese
nenwnwnwneneeneneneneneneneneneneneswnw
nwnenwneneneneenwnenenenenenenwnewnene
nwneneenenenwseeseneeneeenenenewnene
wneseswsweswswsenwswswswsweeswnwswnw
swneeswsewswswenweneswnwnesewew
nwnwnwnwnwnenwnwnwnwsenwsenwwnwnwnwnwnwne
neswneswnewneswseseswnwnwswnewseswsee
eenenwseweeneeneneeweneweeene
nenwwwnwnwneenenenwswnwnwswseenwswnwenw
sweswnwswsweeswwswnenw
wsewsewsenwneswnwnwwewswnwweenw
nenwnenwswnwnenwnwnenenwnenwnenwnenenene
swwneswwewwswneswwwswswwswwwse
swsewswwsewwswneswswwseneswswswnesw
seenenwsweesenwseswnweseeeeenwe
swwswwswswswweswnwsweswswswswnenwwwsw
wnwnwwswenwweswenwwwwwnwnwswnw
swswwswwwswwwwsewwwwwswswwnesw
neswswswswswswswwswswswswwswswswwwe
wenwenwwseswwwnewnwseseswwneswneww
nwswswswneswswwwsewwswswswswswsesww

91
24/main.py Normal file
View File

@ -0,0 +1,91 @@
from typing import Iterable
STEP_LOOKUP = {
"e": ( 1, 0),
"w": (-1, 0),
"ne": ( 1, 1),
"sw": (-1, -1),
"nw": ( 0, 1),
"se": ( 0, -1),
}
def read_input(filename: str) -> list[list[str]]:
tiles = []
with open(filename, "r") as f:
for line in f.readlines():
line = line.strip()
steps = []
i = 0
while i < len(line):
if line[i] == "e" or line[i] == "w":
steps.append(line[i])
else:
steps.append(line[i:i+2])
i += 1
i += 1
tiles.append(steps)
return tiles
def get_black_tiles(tiles: list[list[str]]) -> set[tuple[int, int]]:
black_tiles = set()
for steps in tiles:
x = 0
y = 0
for step in steps:
dx, dy = STEP_LOOKUP[step]
x += dx
y += dy
if (x, y) in black_tiles:
black_tiles.remove((x, y))
else:
black_tiles.add((x, y))
return black_tiles
def part1(tiles: list[list[str]]) -> int:
return len(get_black_tiles(tiles))
def get_neighbors(tile: tuple[int, int]) -> Iterable[tuple[int, int]]:
for offset in STEP_LOOKUP.values():
neighbor = (tile[0]+offset[0], tile[1]+offset[1])
yield neighbor
def count_neighbors(tiles: set[tuple[int, int]], tile: tuple[int, int]) -> int:
count = 0
for neighbor in get_neighbors(tile):
if neighbor in tiles:
count += 1
return count
def simulate(black_tiles: set[tuple[int, int]]) -> set[tuple[int, int]]:
white_tiles = set()
for tile in black_tiles:
for neighbor in get_neighbors(tile):
if neighbor not in black_tiles:
white_tiles.add(neighbor)
new_black_tiles = set()
# Any black tile with zero or more than 2 black tiles immediately adjacent to it is flipped to white.
for black_tile in black_tiles:
black_count = count_neighbors(black_tiles, black_tile)
if black_count == 1 or black_count == 2:
new_black_tiles.add(black_tile)
# Any white tile with exactly 2 black tiles immediately adjacent to it is flipped to black.
for white_tile in white_tiles:
if count_neighbors(black_tiles, white_tile) == 2:
new_black_tiles.add(white_tile)
return new_black_tiles
def part2(tiles: list[list[str]]) -> int:
black_tiles = get_black_tiles(tiles)
for _ in range(100):
black_tiles = simulate(black_tiles)
return len(black_tiles)
if __name__ == "__main__":
tiles = read_input("input.txt")
print("part1: ", part1(tiles))
print("part2: ", part2(tiles))

20
24/test.txt Normal file
View File

@ -0,0 +1,20 @@
sesenwnenenewseeswwswswwnenewsewsw
neeenesenwnwwswnenewnwwsewnenwseswesw
seswneswswsenwwnwse
nwnwneseeswswnenewneswwnewseswneseene
swweswneswnenwsewnwneneseenw
eesenwseswswnenwswnwnwsewwnwsene
sewnenenenesenwsewnenwwwse
wenwwweseeeweswwwnwwe
wsweesenenewnwwnwsenewsenwwsesesenwne
neeswseenwwswnwswswnw
nenwswwsewswnenenewsenwsenwnesesenew
enewnwewneswsewnwswenweswnenwsenwsw
sweneswneswneneenwnewenewwneswswnese
swwesenesewenwneswnwwneseswwne
enesenwswwswneneswsenwnewswseenwsese
wnwnesenesenenwwnenwsewesewsesesew
nenewswnwewswnenesenwnesewesw
eneswnwswnwsenenwnwnwwseeswneewsenese
neswnwewnwnwseenwseesewsenwsweewe
wseweeenwnesenwwwswnew

2
25/input.txt Normal file
View File

@ -0,0 +1,2 @@
2069194
16426071

30
25/main.py Normal file
View File

@ -0,0 +1,30 @@
def read_input(filename: str) -> tuple[int, int]:
with open(filename, "r") as f:
cards_pub, doors_pub = f.read().splitlines()
return int(cards_pub), int(doors_pub)
def reverse_loop_size(public_key: int, subject_number: int) -> int:
key = 1
loop_size = 0
while key != public_key:
loop_size += 1
key *= subject_number
key %= 20201227
return loop_size
def transform_key(subject_number: int, loop_size: int) -> int:
key = 1
for _ in range(loop_size):
key *= subject_number
key %= 20201227
return key
def part1(cards_pub: int, doors_pub: int) -> int:
subject_number = 7
card_loop_size = reverse_loop_size(cards_pub, subject_number)
return transform_key(doors_pub, card_loop_size)
if __name__ == "__main__":
cards_pub, doors_pub = read_input("input.txt")
print("part1: ", part1(cards_pub, doors_pub))

2
25/test.txt Normal file
View File

@ -0,0 +1,2 @@
5764801
17807724