Compare commits

...

126 commits

Author SHA1 Message Date
Bruno BELANYI 68bb1132a9 2021: d06: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 022672fcd0 2021: d06: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI de0afa76fd 2021: d06: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 1e274be43f 2021: d06: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 9534e5c929 2021: d05: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI e5ecef7eed 2021: d05: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 614bf9d842 2021: d05: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 7cf9f46040 2021: d05: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI a26d95809d 2021: d04: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI f8ddf5f4fd 2021: d04: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 7ec10eecd1 2021: d04: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 8e96f33b91 2021: d04: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 465f22bbee 2021: d03: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI b78f5b1f40 2021: d03: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 8c90ac89b3 2021: d03: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI f5a30ee2da 2021: d03: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI a6f9104cb4 2021: d02: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 8ebb134cdf 2021: d02: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI f728552afa 2021: d02: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 3761139723 2021: d02: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 0f1bc9cf2a 2021: d01: ex2: add solution 2021-12-01 10:45:14 +01:00
Bruno BELANYI 4ae1abaa2e 2021: d01: ex2: add input 2021-12-01 10:45:14 +01:00
Bruno BELANYI 81e3d484c8 2021: d01: ex1: add solution 2021-12-01 10:45:14 +01:00
Bruno BELANYI 66d3a850c0 2021: d01: ex1: add input 2021-12-01 10:45:14 +01:00
Bruno BELANYI d94c27fbcf git: ignore generated files 2021-12-01 10:45:14 +01:00
Bruno BELANYI 2deb3b3e8f nix: add direnv integration 2021-12-01 10:45:14 +01:00
Bruno BELANYI ce71b21c7d nix: add flake 2021-12-01 10:45:14 +01:00
Bruno BELANYI cb0348d87c 2020: d25: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 55af2695f5 2020: d25: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI a7d74dcae6 2020: d25: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 17f62f1052 2020: d25: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI afec744618 2020: d24: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI a21b197240 2020: d24: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 96db7c6d02 2020: d24: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI caf14a71b6 2020: d24: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 2418405955 2020: d23: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 20ee194643 2020: d23: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI d4c9aa4c5e 2020: d23: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 820794cc80 2020: d23: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 19b48862ce 2020: d22: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI dddd70813a 2020: d22: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 84ac5bbb71 2020: d22: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 7851f1158f 2020: d22: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI be4a02ce44 2020: d21: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI e8a8d36ac9 2020: d21: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 0be38033f4 2020: d21: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI ed18966413 2020: d21: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 20784cb2ca 2020: d20: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 150bebc492 2020: d20: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI cd747e69e6 2020: d20: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 96980ecb19 2020: d20: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI df664d9fca 2020: d19: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI ab15ce121f 2020: d19: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 22e59128fb 2020: d19: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI aee3b2f333 2020: d19: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 1d1936f5e7 2020: d18: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 2d4a21dc9a 2020: d18: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 34d72e9729 2020: d18: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 932e5a40f7 2020: d18: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 8c2a2ed438 2020: d17: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 6dcd2bcf69 2020: d17: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI ef6e30cb6c 2020: d17: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI d36fb3473d 2020: d17: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 80a4297e93 2020: d16: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI a529394eb4 2020: d16: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 6501cb9cf5 2020: d16: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 7e162a4e7a 2020: d16: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 1831dc4b8f 2020: d15: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI ef2957970a 2020: d15: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 832159237f 2020: d15: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI c1aaae7946 2020: d15: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 2de3573cfd 2020: d15: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI a1c2123291 2020: d15: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI f97a35248d 2020: d14: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 78f159598d 2020: d14: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI bf2c65036f 2020: d13: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI bf81ef41f8 2020: d13: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 617a003a51 2020: d13: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 08ce15d6c0 2020: d13: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 52fba3b92f 2020: d12: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 05670f39c0 2020: d12: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 0cd15bb346 2020: d12: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 060ba38597 2020: d12: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 4b71dee7c4 2020: d11: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI e9cab0c0bf 2020: d11: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI acc175e4a6 2020: d11: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI c318b9970c 2020: d11: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI d3abeae02a 2020: d10: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 5fb874f00b 2020: d10: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 9bc536f6ec 2020: d10: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI f67de590ce 2020: d10: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI f3456d2ca9 2020: d09: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI e127a77443 2020: d09: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 5da7942d78 2020: d09: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 074226098f 2020: d09: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI d7e74e60f1 2020: d08: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 5a39d2babe 2020: d08: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 17138bfc8f 2020: d08: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 0ed6d5eb43 2020: d08: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI d3a1040f60 2020: d07: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI acc9ef472c 2020: d07: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 146b3becf9 2020: d07: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 7d268d0d4f 2020: d07: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI a226768e08 2020: d06: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 1c64a8f18b 2020: d06: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 79ad4a26b5 2020: d06: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 032223781d 2020: d06: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 233caf8b11 2020: d05: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 18d95d8665 2020: d05: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 390eb447cc 2020: d05: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI b25f2908d5 2020: d05: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 4cf562410a 2020: d04: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 26e3bd0006 2020: d04: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 005501546f 2020: d04: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI dd8a4569d2 2020: d04: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 4121ef0880 2020: d03: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 9c6b5bf887 2020: d03: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 93dfa3ab8c 2020: d03: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 4125c20fb7 2020: d03: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 878b0a10d3 2019: d19: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI e812fd424a 2019: d19: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI d868e9f5a9 2019: d19: ex1: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 8733c82b46 2019: d19: ex1: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 533fce5d69 2019: d18: ex2: add solution 2021-12-01 10:42:02 +01:00
Bruno BELANYI 5929fd5f07 2019: d18: ex2: add input 2021-12-01 10:42:02 +01:00
Bruno BELANYI 1014d1546b 2019: d18: ex1: add solution 2021-12-01 10:42:02 +01:00
127 changed files with 37773 additions and 0 deletions

7
.envrc Normal file
View file

@ -0,0 +1,7 @@
use_flake() {
watch_file flake.nix
watch_file flake.lock
eval "$(nix print-dev-env)"
}
use flake

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
# Generated by Nix
/.pre-commit-config.yaml

129
2019/d18/ex1/ex1.py Executable file
View file

@ -0,0 +1,129 @@
#!/usr/bin/env python
import heapq
import sys
from collections import defaultdict, deque
from dataclasses import dataclass
from functools import lru_cache
from math import inf
from typing import (DefaultDict, Deque, Dict, FrozenSet, Iterator, List, Tuple,
Union)
RawGrid = List[str]
GraphInfo = List[Tuple[str, int]]
Graph = Dict[str, GraphInfo]
@dataclass(eq=True, frozen=True) # Hash-able
class Position:
x: int
y: int
def neighbours(grid: RawGrid, pos: Position) -> Iterator[Position]:
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
new_pos = Position(pos.x + dx, pos.y + dy)
if not (0 <= new_pos.x < len(grid) and 0 <= new_pos.y < len(grid[0])):
continue
if grid[new_pos.x][new_pos.y] == "#":
continue
yield new_pos
def find_adjacent(grid: RawGrid, pos: Position) -> GraphInfo:
queue: Deque[Tuple[Position, int]] = deque()
visited = {pos}
adjacent: GraphInfo = []
for n in neighbours(grid, pos):
queue.append((n, 1)) # Distance is 1
while queue:
n, d = queue.popleft()
if n in visited:
continue
visited |= {n}
cell = grid[n.x][n.y]
if cell not in "#.@": # We don't care about those
adjacent.append((cell, d))
continue # Do not go through doors and keys
for neighbour in neighbours(grid, n):
queue.append((neighbour, d + 1))
return adjacent
def build_graph(grid: RawGrid) -> Graph:
graph = {}
for x, row in enumerate(grid):
for y, cell in enumerate(row):
if cell not in "#.":
graph[cell] = find_adjacent(grid, Position(x, y))
return graph
def solve(G: Graph, start: str) -> int:
@lru_cache(2 ** 20)
def reachable_keys(src: str, found: FrozenSet[str]) -> List[Tuple[str, int]]:
queue = []
distance: DefaultDict[str, Union[float, int]] = defaultdict(lambda: inf)
reachable: List[Tuple[str, int]] = []
for neighbor, weight in G[src]:
queue.append((weight, neighbor)) # Weight first for heap comparisons
heapq.heapify(queue)
while queue:
dist, node = heapq.heappop(queue)
# Do key, add it to reachable if not found previously
if node.islower() and node not in found:
reachable.append((node, dist))
continue
# Do door, if not opened by a key that was found in the search
if node.lower() not in found:
continue
# If not a key and not a closed door
for neighbor, weight in G[node]:
new_dist = dist + weight
if new_dist < distance[neighbor]:
distance[neighbor] = new_dist
heapq.heappush(queue, (new_dist, neighbor))
return reachable
@lru_cache(2 ** 20)
def min_steps(
src: str, keys_to_find: int, found: FrozenSet[str] = frozenset()
) -> int:
if keys_to_find == 0:
return 0
best = inf
for key, dist in reachable_keys(src, found):
new_keys = found | {key}
dist += min_steps(key, keys_to_find - 1, new_keys)
if dist < best:
best = dist
return int(best) # That way we throw if we kept the infinite float
total_keys = sum(node.islower() for node in G)
return min_steps(start, total_keys)
def main() -> None:
G = build_graph(list(line.strip() for line in sys.stdin.readlines()))
print(solve(G, "@"))
if __name__ == "__main__":
main()

131
2019/d18/ex2/ex2.py Executable file
View file

@ -0,0 +1,131 @@
#!/usr/bin/env python
import heapq
import sys
from collections import defaultdict, deque
from dataclasses import dataclass
from functools import lru_cache
from math import inf
from typing import (DefaultDict, Deque, Dict, FrozenSet, Iterator, List, Tuple,
Union)
RawGrid = List[str]
GraphInfo = List[Tuple[str, int]]
Graph = Dict[str, GraphInfo]
@dataclass(eq=True, frozen=True) # Hash-able
class Position:
x: int
y: int
def neighbours(grid: RawGrid, pos: Position) -> Iterator[Position]:
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
new_pos = Position(pos.x + dx, pos.y + dy)
if not (0 <= new_pos.x < len(grid) and 0 <= new_pos.y < len(grid[0])):
continue
if grid[new_pos.x][new_pos.y] == "#":
continue
yield new_pos
def find_adjacent(grid: RawGrid, pos: Position) -> GraphInfo:
queue: Deque[Tuple[Position, int]] = deque()
visited = {pos}
adjacent: GraphInfo = []
for n in neighbours(grid, pos):
queue.append((n, 1)) # Distance is 1
while queue:
n, d = queue.popleft()
if n in visited:
continue
visited |= {n}
cell = grid[n.x][n.y]
if cell not in "#.1234": # We don't care about those
adjacent.append((cell, d))
continue # Do not go through doors and keys
for neighbour in neighbours(grid, n):
queue.append((neighbour, d + 1))
return adjacent
def build_graph(grid: RawGrid) -> Graph:
graph = {}
for x, row in enumerate(grid):
for y, cell in enumerate(row):
if cell not in "#.":
graph[cell] = find_adjacent(grid, Position(x, y))
return graph
def solve(G: Graph, start: str) -> int:
@lru_cache(2 ** 20)
def reachable_keys(src: str, found: FrozenSet[str]) -> GraphInfo:
queue = []
distance: DefaultDict[str, Union[float, int]] = defaultdict(lambda: inf)
reachable: GraphInfo = []
for neighbor, weight in G[src]:
queue.append((weight, neighbor)) # Weight first for heap comparisons
heapq.heapify(queue)
while queue:
dist, node = heapq.heappop(queue)
# Do key, add it to reachable if not found previously
if node.islower() and node not in found:
reachable.append((node, dist))
continue
# Do door, if not opened by a key that was found in the search
if node.lower() not in found:
continue
# If not a key and not a closed door
for neighbor, weight in G[node]:
new_dist = dist + weight
if new_dist < distance[neighbor]:
distance[neighbor] = new_dist
heapq.heappush(queue, (new_dist, neighbor))
return reachable
@lru_cache(2 ** 20)
def min_steps(
sources: str, keys_to_find: int, found: FrozenSet[str] = frozenset()
) -> Union[float, int]:
if keys_to_find == 0:
return 0
best = inf
for src in sources:
for key, dist in reachable_keys(src, found):
new_keys = found | {key}
new_sources = sources.replace(src, key)
new_dist = dist + min_steps(new_sources, keys_to_find - 1, new_keys)
if new_dist < best:
best = new_dist
return best
total_keys = sum(node.islower() for node in G)
return int(min_steps(start, total_keys)) # Throw if we kept the infinite float
def main() -> None:
G = build_graph(list(line.strip() for line in sys.stdin.readlines()))
print(solve(G, "1234"))
if __name__ == "__main__":
main()

81
2019/d18/ex2/input Normal file
View file

@ -0,0 +1,81 @@
#################################################################################
#.......#...#...#...........#.....#...#.#.....#m......#.......#.....#........u..#
#####.#.#.#.#.#.###.#######.###.#.#.#.#.#.###.###.#####.#.###.###.#.###########.#
#.....#...#...#.....#.#.....#...#...#...#.#....e#.......#...#.....#.....#.......#
#.###################.#.#####.#########.#.#####.###########.###########.#.#######
#.#...#...#...........#.#.....#.......#.#.....#.....#.....#...#.......#.#.#.....#
#.#S#.###.#.#####.#####.#.###.#.###.###.#####.#####.#.###.###.#.#.#####.#.#.###.#
#.#.#...#.#...#.#.......#.#.#.#.#...#...#.D.#.#...#...#.#.#...#.#.#.....#j..#...#
#.#.###.#.###.#.#########.#.#.###.###.###.#.#.#.#.#####.#.#.###.###.#########.###
#.#...#.#...#...#.#.........#...#.#...#.#.#...#.#.....#...#...#...#.#.#.....#...#
#.###.#.###.###.#.#.#########.#.#.#.###.#.#####.#####.#.#####.###.#.#.#.#.#.###.#
#...#.#c..#.....#.......#...#.#.#.#.#...#...#.....#.#.#.#.....#...#.#...#.#...#.#
#.###.###.#.#############.#.###.#.#.#.#.###.#####.#.#.#.#.#####.###.#.###.###.#.#
#.#...#.#.#.........#.....#...#.#.....#.#.#...#.#...#.#...#...#.....#.#...#...K.#
#.#.###.#.#########.#.#######.#.#########.###.#.###.#.#####.#.#.#######.#########
#.......#.#.......#h..#.....#.#.........#...#.#.....#.......#...#.....#.#...#...#
#.#######.#O#####.#######.#.#.#.#######.###.#.#.#######.#######.#.###F#.#.#.#.#.#
#.#....y..#...#...#.....#.#.#.#.#.#.....#...#.#.#.....#.#.....#...#.#.#...#.#.#.#
###.#####.###.#.###.###.#.###.#.#.#.###.#.#.#.###.###.#.#.###.#####.#.#.###.#.#.#
#...#.....#.#.#...#.#.Z.#...#.#.#.#.#...#.#.#.....#.#.#.#.#.#...#.....#...#...#.#
#.###.#####.#.###A#.#.###.#.#.#.#.#.#####.#########.#.#.#.#.###.#.#########.###.#
#.#.#.#.....#.#.#...#.#...#...#...#.....#.#.........#.#.#.#.#...#.#.......#.#...#
#.#.#.#####.#.#.#######.#########.#####.#.#.#####.#.#.#.#.#.#####.#.###.#.###.#.#
#.#.#...#...#.#...#.....#.....#.......#.#.#.#.#...#.#.#.#.#.....#.#.#...#.....#.#
#.#.###.#.#.#.###.#.#######.#.#####.###.#.#.#.#.#####.#.#.#.#.###.###.#########X#
#.#...#...#.#...#.#...#.....#.....#.#...#.....#.#...#.#.#.#.#...#...#.....#.....#
#.#W#.#####.###N#.###.#.#.#######.###.#.#######.#.#.#.###.#.###.###.#####.###.###
#i#.#.....#.#.#.#...#.#.#.#.....#.....#.#..r..#...#.#...#.#.#.....#.#...#...#.#.#
#.#######.#.#.#.#.###.###.#.###########.#.###.#.###.###.#.###.#####.#.#.###.#.#.#
#.......#...#.#.#...#...#.#.............#.#.#.#.#.#...#...#...#.....#.#.....#.#.#
#.#####.#.###.#.#.#.###.#.#.#############.#.#.#.#.###.#####.###.#####.#######.#.#
#.#.#...#.....#.#.#...#..t#...#.#.......#.#.#.#...#.....#.....#...#...#.....#.#.#
#.#.#.#######.#.#.###.#######.#.#.#.#####.#.#.#.###.###.#####.###.###.#.###.#.#.#
#...#.#...#...#.#...#.....#.#.#...#.....#.#.#.#.#...#.........#.#...#...T.#.#...#
###.#.#.#.#.###.###.#.###.#.#.#########.#.#.#.###.###########.#.###.#####.#.###.#
#...#...#.#.#...#...#...#...#.......#...#.#.#...#.#.....#...#...#...#...#.#...#.#
#.#######.###.###.#####.###########.#.###.#.###.#.#.###.#.#.###.#.###.#.#####.###
#.#...#v#...#.#.#.....#.........#...#...#.#.......#...#..l#...#.#.....#.....#.P.#
#.#.#.#.###.#.#.#####.#########.#.#####.#.###########.#######.#############.###.#
#...#.....#...#...............#........1#2..................#....b..............#
########################################@.#######################################
#...#.#.........#.....#...........#....3#4....#...#.....#.......#...#.....Q.#...#
#.#.#.#.#####.###.#.#.#.#####.###.#.###.#.###.#.#.#.###.#.#####.#.#.#.#.###.###.#
#.#.#.#.#...#.....#.#.#.#.#...#...#...#.#.#.....#.#...#...#.....#.#.#.#...#.#...#
#.#.#.#.#.#.#######.###.#.#.#####.###.#.#.#######.###.#####.#####.#.#.###.#.#.#.#
#.#...#.#.#.....#.#.#.B...#.....#.#...#.#.....#.....#.#...#.......#.#.#...#...#.#
#.#####.#.#####.#.#.#.#######.#.###.###.#.###.###.###.#.#####.#####.#.#.#######.#
#.#...#q#..f#.....#...#.....#.#...#.#...#.#.#...#.#.....#...#.#...#...#.#.....#.#
#.#.#.#.#.#.#######.###.###.###.#.#.#.###.#.###.###.#####.#.#.###.#####.#.###.#.#
#...#.#.#.#...#...#p..#.#.#...#.#...#...#.....#...#.#.....#.#.....#...#...#...#.#
#####.#.#####.#.#.###.#.#.###.#########.#####.###.#.#.#####.#####.###.#####.###.#
#.....#.......#.#.#...#.#...#.#.......#.#...#.#.#...#.#...#.....#.....#.#...#.#.#
#.###########.#.#.#####.###.#L#.#####R#.#.#.#.#.#####.#.#.#####.#####.#.#.###.#.#
#...........#.#.#.......#...#...#...#...#.#.#.....#...#.#.....#...#...#.#...#...#
#######.###.#.#.#########.#.#####.#.#######.#####.#.#######.#.###.#.###.###.###.#
#.......#...#.#.#.........#.......#.....#...#.....#.#.....#.#...#.#...#...#...#.#
#.#######.###.#.#.###.#################.#.###.#####.#.#.#.###.###.###.###.###.#.#
#.#.........#.#.#...#.............#.....#.........#.#.#.#.....#...#.#.......#.#.#
#.###.#######.#.###########.#####.#.###############.###.#####.#.###.#.#####.#.###
#...#.#.......#.#.........#.#...#.#.#...#.......#...#...#.#...#.#.....#...#.#...#
#.#G###.#######.#.#######.#.###.#.###.#.#.#####.#.###.###.#.###.#######.#.#####.#
#.#...#....x#.#.#.#z#.....#.....#.....#.#.....#...#...#...#.#...#.......#.#...#.#
#.###.#####.#.#.#.#.#########.#########.#####.#######.#.###.#####.#######.#.#.#.#
#k#.#.....#...#...#.#.....#...#.......#.#...#.#.......#.#...#.....#.#...#...#.#.#
#.#.#####.###.#####.#.###.#.###.#####.#.#.#.#.#.#.#####.#.###.#####.#.#.#####.#H#
#.#.....#...#.....#.#...#.#.#...#...#...#.#...#.#.#.....#.#...#...#...#...#.#.#.#
#.#.###.###.#####.#.###.#.#.#.###.#.###.#.#######.#.###.#.#.###.#.#.###.#Y#.#.#.#
#...#...#.#...#...#.....#..o#.#.#.#.....#.#.......#.#...#...#...#...#...#...#..g#
#####.###.#.###.#######.#####.#.#.#######.#####.###.###.#############.#####.###.#
#...#.#...#.....#.....#.....#.#.#...#...#.......#.....#...#...........#.#...#...#
#.#.#.###.#######.###.#######.#.###.#.###########.###.###.#.###########.#.###.###
#.#.#.#.....#.#.....#.#.......#...#.#...#...#...#...#.#...#.......#...#.I.#.#...#
#.#.#.#.###.#.#.###.#.#.#######.#.#.###.#.###.#.#.###.#.#########.###.#.###.###.#
#.#.#.#.#...#s....#.#.#.......#a#.#.....#.#...#.#.#...#.....#.....#...#.....#.#.#
#.###M#U###.#####.#.#.###.###.###.#####.#.#.###.#.#.#.#####.#.#####.#V#####.#.#.#
#.....#...#...#...#.#...#...#.#...#....n#.#...#d..#.#.#.J.#...#.....#...#..w#.#.#
#.#######.###.#####.###.#####.#.###.#####.###.#####.#.#.#.###.#####.#####.###.#.#
#.......#.#.#...#...#.#.....#.#...#.#...#...#.#.#...#.#.#.#...#...#...........#.#
#######.#.#.###E#.###.#####.#.#.#.#.###.#.###.#.#.#####.#.#####.#.#############.#
#.........#.......#.........C.#.#.......#.......#.......#.......#...............#
#################################################################################

214
2019/d19/ex1/ex1.py Executable file
View file

@ -0,0 +1,214 @@
#!/usr/bin/env python
import sys
from copy import deepcopy
from dataclasses import dataclass, field
from enum import IntEnum
from itertools import product
from typing import List, NamedTuple
class ParameterMode(IntEnum):
POSITION = 0 # Acts on address
IMMEDIATE = 1 # Acts on the immediate value
RELATIVE = 2 # Acts on offset to relative base
class Instruction(NamedTuple):
address: int # The address of the instruction, for convenience
op: int # The opcode
p1_mode: ParameterMode # Which mode is the first parameter in
p2_mode: ParameterMode # Which mode is the second parameter in
p3_mode: ParameterMode # Which mode is the third parameter in
def lookup_ops(index: int, memory: List[int]) -> Instruction:
digits = list(map(int, str(memory[index])))
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
return Instruction(
address=index,
op=d * 10 + e,
p1_mode=ParameterMode(c),
p2_mode=ParameterMode(b),
p3_mode=ParameterMode(a),
)
class InputInterrupt(Exception):
pass
class OutputInterrupt(Exception):
pass
@dataclass
class Computer:
memory: List[int] # Memory space
rip: int = 0 # Instruction pointer
input_list: List[int] = field(default_factory=list)
output_list: List[int] = field(default_factory=list)
is_halted: bool = field(default=False, init=False)
relative_base: int = field(default=0, init=False)
def run(self) -> None:
while not self.is_halted:
self.run_single()
def run_no_output_interrupt(self) -> None:
while not self.is_halted:
try:
self.run_single()
except OutputInterrupt:
continue
def run_single(self) -> None: # Returns True when halted
instr = lookup_ops(self.rip, self.memory)
if instr.op == 99: # Halt
self.is_halted = True
elif instr.op == 1: # Sum
self._do_addition(instr)
elif instr.op == 2: # Multiplication
self._do_multiplication(instr)
elif instr.op == 3: # Load from input
self._do_input(instr)
elif instr.op == 4: # Store to output
self._do_output(instr)
elif instr.op == 5: # Jump if true
self._do_jump_if_true(instr)
elif instr.op == 6: # Jump if false
self._do_jump_if_false(instr)
elif instr.op == 7: # Less than
self._do_less_than(instr)
elif instr.op == 8: # Equal to
self._do_equal_to(instr)
elif instr.op == 9: # Change relative base
self._do_change_relative_base(instr)
else:
assert False # Sanity check
def _fill_to_addres(self, address: int) -> None:
values = address - len(self.memory) + 1
if values <= 0:
return
for __ in range(values):
self.memory.append(0)
def _get_value(self, mode: ParameterMode, val: int) -> int:
if mode == ParameterMode.POSITION:
assert 0 <= val # Sanity check
self._fill_to_addres(val)
return self.memory[val]
elif mode == ParameterMode.RELATIVE:
val += self.relative_base
assert 0 <= val # Sanity check
self._fill_to_addres(val)
return self.memory[val]
assert mode == ParameterMode.IMMEDIATE # Sanity check
return val
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
if mode == ParameterMode.RELATIVE:
address += self.relative_base
else:
assert mode == ParameterMode.POSITION # Sanity check
assert address >= 0 # Sanity check
self._fill_to_addres(address)
self.memory[address] = value
def _do_addition(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, lhs + rhs)
self.rip += 4 # Length of the instruction
def _do_multiplication(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, lhs * rhs)
self.rip += 4 # Length of the instruction
def _do_input(self, instr: Instruction) -> None:
if len(self.input_list) == 0:
raise InputInterrupt # No input, halt until an input is provided
value = int(self.input_list.pop(0))
param = self.memory[instr.address + 1]
self._set_value(instr.p1_mode, param, value)
self.rip += 2 # Length of the instruction
def _do_output(self, instr: Instruction) -> None:
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
self.output_list.append(value)
self.rip += 2 # Length of the instruction
raise OutputInterrupt # Alert that we got an output to give
def _do_jump_if_true(self, instr: Instruction) -> None:
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
if cond != 0:
self.rip = value
else:
self.rip += 3 # Length of the instruction
def _do_jump_if_false(self, instr: Instruction) -> None:
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
if cond == 0:
self.rip = value
else:
self.rip += 3 # Length of the instruction
def _do_less_than(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
self.rip += 4 # Length of the instruction
def _do_equal_to(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
self.rip += 4 # Length of the instruction
def _do_change_relative_base(self, instr: Instruction) -> None:
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
self.relative_base += value
self.rip += 2 # Length of the instruction
def main() -> None:
memory = [int(n) for n in sys.stdin.read().split(",")]
lines: List[List[int]] = [[0 for i in range(50)] for __ in range(50)]
for x, y in product(range(50), range(50)):
drone = Computer(deepcopy(memory), input_list=[x, y])
drone.run_no_output_interrupt()
assert len(drone.output_list) == 1
lines[x][y] = drone.output_list.pop()
print(sum(map(sum, lines)))
if __name__ == "__main__":
main()

1
2019/d19/ex1/input Normal file
View file

@ -0,0 +1 @@
109,424,203,1,21102,11,1,0,1106,0,282,21102,18,1,0,1106,0,259,1201,1,0,221,203,1,21102,31,1,0,1106,0,282,21101,38,0,0,1106,0,259,21002,23,1,2,22102,1,1,3,21101,1,0,1,21102,57,1,0,1105,1,303,2102,1,1,222,20101,0,221,3,20101,0,221,2,21102,259,1,1,21101,80,0,0,1106,0,225,21101,0,44,2,21102,91,1,0,1105,1,303,1201,1,0,223,20101,0,222,4,21101,0,259,3,21102,225,1,2,21101,225,0,1,21102,118,1,0,1105,1,225,21002,222,1,3,21101,100,0,2,21101,133,0,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21101,148,0,0,1106,0,259,2102,1,1,223,20102,1,221,4,21002,222,1,3,21102,1,12,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,1,195,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21101,0,214,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2102,1,-4,249,21201,-3,0,1,22101,0,-2,2,22101,0,-1,3,21101,0,250,0,1105,1,225,22102,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21202,-2,1,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22102,1,-2,3,21101,0,343,0,1105,1,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1106,0,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22102,1,1,-4,109,-5,2106,0,0

221
2019/d19/ex2/ex2.py Executable file
View file

@ -0,0 +1,221 @@
#!/usr/bin/env python
import sys
from copy import deepcopy
from dataclasses import dataclass, field
from enum import IntEnum
from typing import Iterator, List, NamedTuple, Tuple
class ParameterMode(IntEnum):
POSITION = 0 # Acts on address
IMMEDIATE = 1 # Acts on the immediate value
RELATIVE = 2 # Acts on offset to relative base
class Instruction(NamedTuple):
address: int # The address of the instruction, for convenience
op: int # The opcode
p1_mode: ParameterMode # Which mode is the first parameter in
p2_mode: ParameterMode # Which mode is the second parameter in
p3_mode: ParameterMode # Which mode is the third parameter in
def lookup_ops(index: int, memory: List[int]) -> Instruction:
digits = list(map(int, str(memory[index])))
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
return Instruction(
address=index,
op=d * 10 + e,
p1_mode=ParameterMode(c),
p2_mode=ParameterMode(b),
p3_mode=ParameterMode(a),
)
class InputInterrupt(Exception):
pass
class OutputInterrupt(Exception):
pass
@dataclass
class Computer:
memory: List[int] # Memory space
rip: int = 0 # Instruction pointer
input_list: List[int] = field(default_factory=list)
output_list: List[int] = field(default_factory=list)
is_halted: bool = field(default=False, init=False)
relative_base: int = field(default=0, init=False)
def run(self) -> None:
while not self.is_halted:
self.run_single()
def run_no_output_interrupt(self) -> None:
while not self.is_halted:
try:
self.run_single()
except OutputInterrupt:
continue
def run_single(self) -> None: # Returns True when halted
instr = lookup_ops(self.rip, self.memory)
if instr.op == 99: # Halt
self.is_halted = True
elif instr.op == 1: # Sum
self._do_addition(instr)
elif instr.op == 2: # Multiplication
self._do_multiplication(instr)
elif instr.op == 3: # Load from input
self._do_input(instr)
elif instr.op == 4: # Store to output
self._do_output(instr)
elif instr.op == 5: # Jump if true
self._do_jump_if_true(instr)
elif instr.op == 6: # Jump if false
self._do_jump_if_false(instr)
elif instr.op == 7: # Less than
self._do_less_than(instr)
elif instr.op == 8: # Equal to
self._do_equal_to(instr)
elif instr.op == 9: # Change relative base
self._do_change_relative_base(instr)
else:
assert False # Sanity check
def _fill_to_addres(self, address: int) -> None:
values = address - len(self.memory) + 1
if values <= 0:
return
for __ in range(values):
self.memory.append(0)
def _get_value(self, mode: ParameterMode, val: int) -> int:
if mode == ParameterMode.POSITION:
assert 0 <= val # Sanity check
self._fill_to_addres(val)
return self.memory[val]
elif mode == ParameterMode.RELATIVE:
val += self.relative_base
assert 0 <= val # Sanity check
self._fill_to_addres(val)
return self.memory[val]
assert mode == ParameterMode.IMMEDIATE # Sanity check
return val
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
if mode == ParameterMode.RELATIVE:
address += self.relative_base
else:
assert mode == ParameterMode.POSITION # Sanity check
assert address >= 0 # Sanity check
self._fill_to_addres(address)
self.memory[address] = value
def _do_addition(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, lhs + rhs)
self.rip += 4 # Length of the instruction
def _do_multiplication(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, lhs * rhs)
self.rip += 4 # Length of the instruction
def _do_input(self, instr: Instruction) -> None:
if len(self.input_list) == 0:
raise InputInterrupt # No input, halt until an input is provided
value = int(self.input_list.pop(0))
param = self.memory[instr.address + 1]
self._set_value(instr.p1_mode, param, value)
self.rip += 2 # Length of the instruction
def _do_output(self, instr: Instruction) -> None:
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
self.output_list.append(value)
self.rip += 2 # Length of the instruction
raise OutputInterrupt # Alert that we got an output to give
def _do_jump_if_true(self, instr: Instruction) -> None:
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
if cond != 0:
self.rip = value
else:
self.rip += 3 # Length of the instruction
def _do_jump_if_false(self, instr: Instruction) -> None:
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
if cond == 0:
self.rip = value
else:
self.rip += 3 # Length of the instruction
def _do_less_than(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
self.rip += 4 # Length of the instruction
def _do_equal_to(self, instr: Instruction) -> None:
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
dest = self.memory[instr.address + 3]
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
self.rip += 4 # Length of the instruction
def _do_change_relative_base(self, instr: Instruction) -> None:
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
self.relative_base += value
self.rip += 2 # Length of the instruction
def true_at(memory: List[int], x: int, y: int) -> bool:
drone = Computer(deepcopy(memory), input_list=[x, y])
drone.run_no_output_interrupt()
assert len(drone.output_list) == 1
return drone.output_list.pop() == 1
def main() -> None:
memory = [int(n) for n in sys.stdin.read().split(",")]
x = 0
y = 0
size = 100
while not true_at(memory, x + size - 1, y):
y += 1
while not true_at(memory, x, y + size - 1):
x += 1
print((x * 10000 + y))
if __name__ == "__main__":
main()

1
2019/d19/ex2/input Normal file
View file

@ -0,0 +1 @@
109,424,203,1,21102,11,1,0,1106,0,282,21102,18,1,0,1106,0,259,1201,1,0,221,203,1,21102,31,1,0,1106,0,282,21101,38,0,0,1106,0,259,21002,23,1,2,22102,1,1,3,21101,1,0,1,21102,57,1,0,1105,1,303,2102,1,1,222,20101,0,221,3,20101,0,221,2,21102,259,1,1,21101,80,0,0,1106,0,225,21101,0,44,2,21102,91,1,0,1105,1,303,1201,1,0,223,20101,0,222,4,21101,0,259,3,21102,225,1,2,21101,225,0,1,21102,118,1,0,1105,1,225,21002,222,1,3,21101,100,0,2,21101,133,0,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21101,148,0,0,1106,0,259,2102,1,1,223,20102,1,221,4,21002,222,1,3,21102,1,12,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,1,195,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21101,0,214,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2102,1,-4,249,21201,-3,0,1,22101,0,-2,2,22101,0,-1,3,21101,0,250,0,1105,1,225,22102,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21202,-2,1,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22102,1,-2,3,21101,0,343,0,1105,1,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1106,0,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22102,1,1,-4,109,-5,2106,0,0

25
2020/d03/ex1/ex1.py Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env python
import sys
from typing import List, Tuple
def solve(trees: List[str], delta: Tuple[int, int]) -> int:
x, y = 0, 0
sum = 0
while True:
x += delta[0]
y += delta[1]
if y >= len(trees):
break
sum += trees[y][x % len(trees[0])] == "#"
return sum
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input, (3, 1)))
if __name__ == "__main__":
main()

323
2020/d03/ex1/input Normal file
View file

@ -0,0 +1,323 @@
...............#.#.............
##..#....................#...##
......#..#.#.....#..#.#.##.....
.........#...#..............#.#
............#.......##.........
...#.....#.....#...#.....#..#..
..............#..##.#..#......#
.##.....#.....#......##.#......
.#..........###....#...##....#.
.....#....#.#.......#......##..
.#....#......#.......#........#
..#.#.......#..##.....##.......
...#.#....#.......#.......#...#
##.##...##..#......#.#.....#..#
.#.#.......#..#.#......#...#.#.
#.......##.......#...#.........
.....#......#.#.#.....#....##..
.#.#........#....#..#..#.......
...#....#..###.........#.....#.
........#........#........#....
..##..............#.....#.#..#.
.#...##.............#.#........
....#..#...........#.......#...
..#....#.....................#.
#.#..................##......##
.#.##....#......#........#.....
.........##.....#....#...##..#.
#..........#..#.#.............#
.........#...#.#.#.#..##..##...
#...#.....#..#..#....#...#.....
..##.....#..................#..
#..###.....#....#.......#..#...
...##.##..#............#......#
........###.........###......#.
#..##....#.........#.........#.
....#.....................#....
#..#..##..#..####.##..#.....##.
..#...#.#....#....##.....#.....
...#.#.........#.....#.#.......
....#................#..#...##.
....#..#..........#...#.#.##...
........#..##............#....#
...#......##..........#.##...#.
.......##......................
.......##..........#....#.#...#
......###.##..##..#....#...#..#
#.#...........##.....#........#
..#...........#..###....#.#.#..
........#...........#......##..
.........#...##.###...###..#...
.....#.....#..##.........##....
...##..............#.....#...##
.##....#.......###.....#.......
.#...........##.............##.
......#..#..##.##......#......#
........###........#......#.#..
#.#....#.....#........#......#.
.##..#.........##...##....#....
.....#.........#...##.....#....
.............#........###....#.
......#.......#.#........#.#...
..#....#.#...#....#...#.#...##.
#...#......##..##......#.##.###
...##.#....#...#....#.........#
...#..####.....##.#..#.#...##..
##.#..#....##......#......##...
###.........#.#..#.#.....#.....
...#........#..##...#.#.#..#.#.
...###..#.###.#...#............
....................###........
...........#...........#.......
#..............#.#.........###.
....................##.....#..#
#.#.....#.......#...#..........
.#...#......#....##...#...#....
.....#.##..................###.
.........#.#..#.#......#.......
.......#.....##..#.##.#........
..#..........#.###.....#....#..
......#.............#.#........
........##....#........#.......
...#.............#....#.#......
#........#..####.....#.....#.#.
.##......##...#........#..#.#..
....##....#...#...#..##...#.#..
#.##...###..#....##.#..........
....#.#...#.#...#..##.###...#..
#.....##..#..#....#.#.....##...
.#..#..........##.#.....##.....
.#..#........#.#.#.#...........
.#..#.....#...........#...#....
...#......##..........##..#....
...#..#....#.##...#..#.....###.
#.#....#.....##................
#..#......#.#.#.......#........
......#....#.#....#..##....#..#
.#.....#.#....###.##.........#.
.###..#.....#........#.#.......
.#...#......#..#.#......#.....#
#...............####...#.....#.
.......#..........##.#........#
#........##....##.....###..##..
#..#.....#..##.....#....#..#...
#.....#.......##......#.#.....#
#.##..#......##..#.............
##...#.....#........##.........
....#..##....#...#.......#.#...
....#...#...##..#....#..#...#..
..............#.#...#....###...
...#....#..##...##..#....##....
#.##.#..#..#......#.#.#.#...#..
.......#..#..##........#......#
##.#....#....##.#......##.#....
.#...#..............#........#.
.#.#....#.........#............
.#..#..###.............#....#..
#......#...#.#..##..#...#....#.
.......................#...#.#.
.............#..#...##.........
..#.#..#....#....#........#....
#......#.##..#...#.#...........
.....#....#...........##.#..#..
..#.#.....#..............#.#...
#.......#.....#................
#..............#...#....#...#..
...#...##..#..#............#...
......###.....................#
.........#.......##..#....#....
........#...#.##..#.##......#..
....###..#.#...#...#..#.#...###
##...#...##.#...#.#...#.#....#.
.........#...#.....###.........
...#........##..#.......##.....
.#.......##.........#.....##..#
.#..................#...#......
.##..#..#.#.....#.###..........
...#.....##..#.........#...#...
.#......#.#.......#.#..........
.........#.#...#..........#.#..
#..........#.##..#.##....#.....
.#.#....#.....#..##.....#...#..
..#........##...##..#..#....#..
#...........##....#..###....#..
...........##.........####...#.
..#........###...#.#.........#.
.#...............#.##.#.#...#..
.#.##..#.....#.#.....##..#.....
...#...#..#.##.##...#.......##.
..#...#...#......##.##.##...#..
##....#...#...#...............#
...##...........#......#..#.#..
#.........#......#.#.##.....#..
........#..#.........##........
..#.#....###.....##..#...#.....
.........#...#.......#.....##..
##.....................#...##..
.#.#..#......#.................
.....###..#......#..###..#.....
...#.....##.........#......#..#
......##.....#...#........#.#..
..#.#...#......#...#.##.##.....
...#..........#...#.......#..##
.###........#........##........
..#.#.#..........#.#...##......
.........#........#......###..#
....##..#.........#...........#
..####..#............##.......#
.....##.#..##.........#...#.#..
...#.........#.....#.....#.....
.......#...#..#...##.........#.
...#...#..#...#....#..#........
#............##.##...#.........
.#.#.....#.......####.....#....
..............#......#.#.......
..............#...........#...#
#...#........###....#.#....#.#.
##.#..#..#......#......#.#.#...
.#..#.....#..#.#..#.#.......##.
......##.#...#...#......#...#..
#...........##....#.#..........
....#.......###.#...#..........
.......................#.....#.
........#...#..#...#.#.#.#.#...
.#.#...........#......##...#...
.........................#.....
.................#.##.#...##...
...#...##.....#.....##....#.#..
...#...#...................#...
...#..#..#...#...#....#........
#....#...#.....#...............
.......#...........#...#.......
....#....#.....##.......#......
.......#..........##...........
.#.#........#..##....#......#..
.....#.......#.#.........#...#.
.#..####.#.#...............#..#
.....###..#..#..........#.#..##
..#.......#...#.....##..#..#.#.
#....#......#..................
........#.##.#....#...........#
....#.#....##..#.#.....##......
...#..#.......#....#.....#.#.#.
#...#......#.....#.#..........#
....#....#...............#.....
..###......................###.
.##....#..#.......###.....#..#.
..###............#........#.##.
.#........#......#.....#..#....
....#..##...#...#.###.......#.#
.......#.##...........#.#..#...
.....#...##....................
....#....#...##......#.........
..#............##....###.#...#.
.#........#...............#....
#..#.#.##.........#..##....##..
#.#....#..#.##....##...#.#.....
.....#.....##....#.#........#..
#..#...#...#....#....#.........
...#........#..#.#.....##......
..#...#...#................##..
#........#.#.##.......#.#...#..
#......#..####.##.....#.#..#.#.
............#..#.#....#......##
..#.....##....#...#.#..........
...#...#.........#...#.#.......
.###..#.......##.##.....#.#.#..
...#....#...............##.#...
....##..#..#..#.#......##.....#
#.#..............##...##...####
.....#.##...#.#...............#
.##.....#.........#.......#.#.#
#.#..#.....#.......#.......#..#
...#.#.....#.....#......#......
.......#....#..#.#..........#..
......#......#.##...#..........
.....#.......###...#...#.#.....
#..#.#.........#.....#.##....#.
..#.#.........#..#..#..#.....#.
.#..##..#..#....#......#.##..#.
...##......###.....#.##.##.....
.#.....#...#..#...#............
##..##..#.##....#..#...........
...#..##..#..#.............#.##
...............##............#.
..#.....##........##.#...#....#
.#.#...#.#.#..#.#.....#....#...
.#....#...............#..#.....
....#.##..#....#......#...###..
#................###...#.#.....
...#...#......##..#.#....#.....
.#....#....#.#...##............
....#...##..#..#........#.##...
..##.....#..#..##..............
..#..##..#.#..##....#....#....#
...##.............#............
#....#....#.#........#.....##.#
.....#..#.#.....####...###.....
................#......#.......
.....#.#.#.#.#....#..#........#
.##.#...#.#.......##....#....#.
.....#........#................
..#.....#..#...#..#...........#
.#.....#...##.....##..#.#....##
......#.......#..#......##.#...
#.#..........#.##.#........#...
...#..#.............#..........
#..#..#..........#..##.#.......
.#..#...............####..#....
.......#.....#......#.....#.#..
.#...............#...#.........
.#..#..........#..#.#..##..#..#
......##..#.....#..#......###..
..........#...#..#.......#.....
.#.#.#..#.....#.##.#...#..#....
........#.......#.....#.#......
......#.....##.....#....##.#...
...............#......#.......#
..#.#...#.....#.#...##......#..
#.#.........#.#...#........####
#..........##..#..#........##..
.............#..#.......##.#..#
..#........#.#....#........#.#.
.#......####..#..#.............
............###.......#.#..#...
#.##......##...#...#.........#.
....##.#.#.#......#....#..#...#
.#..#.#....#...#.........#.....
#...#.....##............#...#..
#.#...#..#.................#...
............#.#..#.....#.#.#..#
...................#....#.##...
.....#...#.#....#....#.#......#
.......##.#.#......##..........
.#..#...##.#...#..#......#.....
......#.#..#..###..##..##......
.#.#.#.#.....#...###.....#..#..
.#....#.....#.......#.......#..
..........##.........####......
.#.#.............#..#.#...#....
........#........##...#.#....#.
........#......................
..#.#....#...............#...##
.......#.#...#..#.....##......#
.#...#....#..........##........
.#.........#.#............##...
.....#......##...#.......#..#..
#.#..#.............#...#...#...
......#.......#............#...
...........##....#......##.....
.#.#..#.....................#..
##..##.....###..##.#...........
...##......##....#...##.....#..
#...#.##.............#.........
......#..#.........###.#......#
#.#.....#.....................#
....#####.....##........#.#..#.
...........##..##.###..........
..........##.....#........#...#
.......#..#......#.....##..##.#
.....##.#........#.........#...
......##......................#
.#.......#.#.#............#..#.
.....##.#.......#.#........#...

33
2020/d03/ex2/ex2.py Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python
import sys
from math import prod
from typing import List, Tuple
def solve(trees: List[str], delta: Tuple[int, int]) -> int:
x, y = 0, 0
sum = 0
while True:
x += delta[0]
y += delta[1]
if y >= len(trees):
break
sum += trees[y][x % len(trees[0])] == "#"
return sum
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
deltas = [
(1, 1),
(3, 1),
(5, 1),
(7, 1),
(1, 2),
]
print(prod(solve(input, delt) for delt in deltas))
if __name__ == "__main__":
main()

323
2020/d03/ex2/input Normal file
View file

@ -0,0 +1,323 @@
...............#.#.............
##..#....................#...##
......#..#.#.....#..#.#.##.....
.........#...#..............#.#
............#.......##.........
...#.....#.....#...#.....#..#..
..............#..##.#..#......#
.##.....#.....#......##.#......
.#..........###....#...##....#.
.....#....#.#.......#......##..
.#....#......#.......#........#
..#.#.......#..##.....##.......
...#.#....#.......#.......#...#
##.##...##..#......#.#.....#..#
.#.#.......#..#.#......#...#.#.
#.......##.......#...#.........
.....#......#.#.#.....#....##..
.#.#........#....#..#..#.......
...#....#..###.........#.....#.
........#........#........#....
..##..............#.....#.#..#.
.#...##.............#.#........
....#..#...........#.......#...
..#....#.....................#.
#.#..................##......##
.#.##....#......#........#.....
.........##.....#....#...##..#.
#..........#..#.#.............#
.........#...#.#.#.#..##..##...
#...#.....#..#..#....#...#.....
..##.....#..................#..
#..###.....#....#.......#..#...
...##.##..#............#......#
........###.........###......#.
#..##....#.........#.........#.
....#.....................#....
#..#..##..#..####.##..#.....##.
..#...#.#....#....##.....#.....
...#.#.........#.....#.#.......
....#................#..#...##.
....#..#..........#...#.#.##...
........#..##............#....#
...#......##..........#.##...#.
.......##......................
.......##..........#....#.#...#
......###.##..##..#....#...#..#
#.#...........##.....#........#
..#...........#..###....#.#.#..
........#...........#......##..
.........#...##.###...###..#...
.....#.....#..##.........##....
...##..............#.....#...##
.##....#.......###.....#.......
.#...........##.............##.
......#..#..##.##......#......#
........###........#......#.#..
#.#....#.....#........#......#.
.##..#.........##...##....#....
.....#.........#...##.....#....
.............#........###....#.
......#.......#.#........#.#...
..#....#.#...#....#...#.#...##.
#...#......##..##......#.##.###
...##.#....#...#....#.........#
...#..####.....##.#..#.#...##..
##.#..#....##......#......##...
###.........#.#..#.#.....#.....
...#........#..##...#.#.#..#.#.
...###..#.###.#...#............
....................###........
...........#...........#.......
#..............#.#.........###.
....................##.....#..#
#.#.....#.......#...#..........
.#...#......#....##...#...#....
.....#.##..................###.
.........#.#..#.#......#.......
.......#.....##..#.##.#........
..#..........#.###.....#....#..
......#.............#.#........
........##....#........#.......
...#.............#....#.#......
#........#..####.....#.....#.#.
.##......##...#........#..#.#..
....##....#...#...#..##...#.#..
#.##...###..#....##.#..........
....#.#...#.#...#..##.###...#..
#.....##..#..#....#.#.....##...
.#..#..........##.#.....##.....
.#..#........#.#.#.#...........
.#..#.....#...........#...#....
...#......##..........##..#....
...#..#....#.##...#..#.....###.
#.#....#.....##................
#..#......#.#.#.......#........
......#....#.#....#..##....#..#
.#.....#.#....###.##.........#.
.###..#.....#........#.#.......
.#...#......#..#.#......#.....#
#...............####...#.....#.
.......#..........##.#........#
#........##....##.....###..##..
#..#.....#..##.....#....#..#...
#.....#.......##......#.#.....#
#.##..#......##..#.............
##...#.....#........##.........
....#..##....#...#.......#.#...
....#...#...##..#....#..#...#..
..............#.#...#....###...
...#....#..##...##..#....##....
#.##.#..#..#......#.#.#.#...#..
.......#..#..##........#......#
##.#....#....##.#......##.#....
.#...#..............#........#.
.#.#....#.........#............
.#..#..###.............#....#..
#......#...#.#..##..#...#....#.
.......................#...#.#.
.............#..#...##.........
..#.#..#....#....#........#....
#......#.##..#...#.#...........
.....#....#...........##.#..#..
..#.#.....#..............#.#...
#.......#.....#................
#..............#...#....#...#..
...#...##..#..#............#...
......###.....................#
.........#.......##..#....#....
........#...#.##..#.##......#..
....###..#.#...#...#..#.#...###
##...#...##.#...#.#...#.#....#.
.........#...#.....###.........
...#........##..#.......##.....
.#.......##.........#.....##..#
.#..................#...#......
.##..#..#.#.....#.###..........
...#.....##..#.........#...#...
.#......#.#.......#.#..........
.........#.#...#..........#.#..
#..........#.##..#.##....#.....
.#.#....#.....#..##.....#...#..
..#........##...##..#..#....#..
#...........##....#..###....#..
...........##.........####...#.
..#........###...#.#.........#.
.#...............#.##.#.#...#..
.#.##..#.....#.#.....##..#.....
...#...#..#.##.##...#.......##.
..#...#...#......##.##.##...#..
##....#...#...#...............#
...##...........#......#..#.#..
#.........#......#.#.##.....#..
........#..#.........##........
..#.#....###.....##..#...#.....
.........#...#.......#.....##..
##.....................#...##..
.#.#..#......#.................
.....###..#......#..###..#.....
...#.....##.........#......#..#
......##.....#...#........#.#..
..#.#...#......#...#.##.##.....
...#..........#...#.......#..##
.###........#........##........
..#.#.#..........#.#...##......
.........#........#......###..#
....##..#.........#...........#
..####..#............##.......#
.....##.#..##.........#...#.#..
...#.........#.....#.....#.....
.......#...#..#...##.........#.
...#...#..#...#....#..#........
#............##.##...#.........
.#.#.....#.......####.....#....
..............#......#.#.......
..............#...........#...#
#...#........###....#.#....#.#.
##.#..#..#......#......#.#.#...
.#..#.....#..#.#..#.#.......##.
......##.#...#...#......#...#..
#...........##....#.#..........
....#.......###.#...#..........
.......................#.....#.
........#...#..#...#.#.#.#.#...
.#.#...........#......##...#...
.........................#.....
.................#.##.#...##...
...#...##.....#.....##....#.#..
...#...#...................#...
...#..#..#...#...#....#........
#....#...#.....#...............
.......#...........#...#.......
....#....#.....##.......#......
.......#..........##...........
.#.#........#..##....#......#..
.....#.......#.#.........#...#.
.#..####.#.#...............#..#
.....###..#..#..........#.#..##
..#.......#...#.....##..#..#.#.
#....#......#..................
........#.##.#....#...........#
....#.#....##..#.#.....##......
...#..#.......#....#.....#.#.#.
#...#......#.....#.#..........#
....#....#...............#.....
..###......................###.
.##....#..#.......###.....#..#.
..###............#........#.##.
.#........#......#.....#..#....
....#..##...#...#.###.......#.#
.......#.##...........#.#..#...
.....#...##....................
....#....#...##......#.........
..#............##....###.#...#.
.#........#...............#....
#..#.#.##.........#..##....##..
#.#....#..#.##....##...#.#.....
.....#.....##....#.#........#..
#..#...#...#....#....#.........
...#........#..#.#.....##......
..#...#...#................##..
#........#.#.##.......#.#...#..
#......#..####.##.....#.#..#.#.
............#..#.#....#......##
..#.....##....#...#.#..........
...#...#.........#...#.#.......
.###..#.......##.##.....#.#.#..
...#....#...............##.#...
....##..#..#..#.#......##.....#
#.#..............##...##...####
.....#.##...#.#...............#
.##.....#.........#.......#.#.#
#.#..#.....#.......#.......#..#
...#.#.....#.....#......#......
.......#....#..#.#..........#..
......#......#.##...#..........
.....#.......###...#...#.#.....
#..#.#.........#.....#.##....#.
..#.#.........#..#..#..#.....#.
.#..##..#..#....#......#.##..#.
...##......###.....#.##.##.....
.#.....#...#..#...#............
##..##..#.##....#..#...........
...#..##..#..#.............#.##
...............##............#.
..#.....##........##.#...#....#
.#.#...#.#.#..#.#.....#....#...
.#....#...............#..#.....
....#.##..#....#......#...###..
#................###...#.#.....
...#...#......##..#.#....#.....
.#....#....#.#...##............
....#...##..#..#........#.##...
..##.....#..#..##..............
..#..##..#.#..##....#....#....#
...##.............#............
#....#....#.#........#.....##.#
.....#..#.#.....####...###.....
................#......#.......
.....#.#.#.#.#....#..#........#
.##.#...#.#.......##....#....#.
.....#........#................
..#.....#..#...#..#...........#
.#.....#...##.....##..#.#....##
......#.......#..#......##.#...
#.#..........#.##.#........#...
...#..#.............#..........
#..#..#..........#..##.#.......
.#..#...............####..#....
.......#.....#......#.....#.#..
.#...............#...#.........
.#..#..........#..#.#..##..#..#
......##..#.....#..#......###..
..........#...#..#.......#.....
.#.#.#..#.....#.##.#...#..#....
........#.......#.....#.#......
......#.....##.....#....##.#...
...............#......#.......#
..#.#...#.....#.#...##......#..
#.#.........#.#...#........####
#..........##..#..#........##..
.............#..#.......##.#..#
..#........#.#....#........#.#.
.#......####..#..#.............
............###.......#.#..#...
#.##......##...#...#.........#.
....##.#.#.#......#....#..#...#
.#..#.#....#...#.........#.....
#...#.....##............#...#..
#.#...#..#.................#...
............#.#..#.....#.#.#..#
...................#....#.##...
.....#...#.#....#....#.#......#
.......##.#.#......##..........
.#..#...##.#...#..#......#.....
......#.#..#..###..##..##......
.#.#.#.#.....#...###.....#..#..
.#....#.....#.......#.......#..
..........##.........####......
.#.#.............#..#.#...#....
........#........##...#.#....#.
........#......................
..#.#....#...............#...##
.......#.#...#..#.....##......#
.#...#....#..........##........
.#.........#.#............##...
.....#......##...#.......#..#..
#.#..#.............#...#...#...
......#.......#............#...
...........##....#......##.....
.#.#..#.....................#..
##..##.....###..##.#...........
...##......##....#...##.....#..
#...#.##.............#.........
......#..#.........###.#......#
#.#.....#.....................#
....#####.....##........#.#..#.
...........##..##.###..........
..........##.....#........#...#
.......#..#......#.....##..##.#
.....##.#........#.........#...
......##......................#
.#.......#.#.#............#..#.
.....##.#.......#.#........#...

38
2020/d04/ex1/ex1.py Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env python
import sys
from typing import List
def validate(passport: List[str]) -> int:
fields = [
"byr",
"iyr",
"eyr",
"hgt",
"hcl",
"ecl",
"pid",
]
for field in fields:
if field not in passport:
return False
return True
def solve(passport_fields: List[List[str]]) -> int:
return sum(validate(passport) for passport in passport_fields)
def main() -> None:
passports: List[List[str]] = [[]]
for line in sys.stdin:
if line == "\n" or line == "":
passports.append([])
continue
passports[-1] += [s.split(":")[0] for s in line.split(" ")]
print(solve(passports))
if __name__ == "__main__":
main()

1069
2020/d04/ex1/input Normal file

File diff suppressed because it is too large Load diff

109
2020/d04/ex2/ex2.py Executable file
View file

@ -0,0 +1,109 @@
#!/usr/bin/env python
import re
import sys
from typing import List, Tuple
Field = Tuple[str, ...]
def validate_byr(field: str) -> bool:
pattern = "^[0-9]{4}$"
if not re.fullmatch(pattern, field):
return False
val = int(field)
return 1920 <= val <= 2002
def validate_iyr(field: str) -> bool:
pattern = "^[0-9]{4}$"
if not re.fullmatch(pattern, field):
return False
val = int(field)
return 2010 <= val <= 2020
def validate_eyr(field: str) -> bool:
pattern = "^[0-9]{4}$"
if not re.fullmatch(pattern, field):
return False
val = int(field)
return 2020 <= val <= 2030
def validate_hgt(field: str) -> bool:
pattern = "^[0-9]+(cm|in)$"
if not re.fullmatch(pattern, field):
return False
val = int(field[:-2])
if "cm" in field:
return 150 <= val <= 193
return 59 <= val <= 76
def validate_hcl(field: str) -> bool:
pattern = "^#[a-f0-9]{6}$"
if not re.fullmatch(pattern, field):
return False
return True
def validate_ecl(field: str) -> bool:
return field in {
"amb",
"blu",
"brn",
"gry",
"grn",
"hzl",
"oth",
}
def validate_pid(field: str) -> bool:
pattern = "^[0-9]{9}$"
if not re.fullmatch(pattern, field):
return False
return True
def validate(passport: List[Field]) -> int:
fields = {
"byr": validate_byr,
"iyr": validate_iyr,
"eyr": validate_eyr,
"hgt": validate_hgt,
"hcl": validate_hcl,
"ecl": validate_ecl,
"pid": validate_pid,
}
tot = 0
for field in passport:
if len(field) != 2:
continue
if field[0] not in fields:
if field[0] == "cid":
continue
return False
if not fields[field[0]](field[1].strip()):
return False
tot += 1
return tot == len(fields)
def solve(passport_fields: List[List[Field]]) -> int:
return sum(validate(passport) for passport in passport_fields)
def main() -> None:
passports: List[List[Field]] = [[]]
for line in sys.stdin:
if line == "\n" or line == "":
passports.append([])
continue
passports[-1] += [tuple(s.split(":")) for s in line.split(" ") if s]
print(solve(passports))
if __name__ == "__main__":
main()

1069
2020/d04/ex2/input Normal file

File diff suppressed because it is too large Load diff

35
2020/d05/ex1/ex1.py Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
import sys
from typing import List
def seat_id(boarding_pass: str) -> int:
min_x = 0
max_x = 128
min_y = 0
max_y = 8
for char in boarding_pass:
if char == "F":
max_x = (min_x + max_x) // 2
elif char == "B":
min_x = (min_x + max_x) // 2
elif char == "L":
max_y = (min_y + max_y) // 2
elif char == "R":
min_y = (min_y + max_y) // 2
return min_x * 8 + min_y
def solve(passes: List[str]) -> int:
return max(seat_id(p) for p in passes)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

781
2020/d05/ex1/input Normal file
View file

@ -0,0 +1,781 @@
FBFFBFFRLL
BFFFFBBRLR
FFFBBBBRLR
FBFFFBFLRL
FFBFBFFRRL
FFBBBBFRRR
FBFFBFBLRR
FFBBFBFRRL
FFFFBBFRRL
BFBBBBBLLL
FFBFBFBLLL
FFBFFFBLLL
FBBBFBFRLL
BBFFFBFRRR
FFFBFBBLLR
FBFBFBFRRR
BBFFBFBRLL
FBFBBBBLRL
FBFFFFFLLL
BFFFFFFRLL
BFFFBFBLRL
BFBBBFBRRL
BFFFBFFRRL
FBFFFFFRRR
FFBBBBBLLR
BFBBFFBLRL
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RR
FFFBBFBLRL
FBFFBBFRLR
BFFFBBFLRR
BBFFFBBLRL
FBBFFBFRLR
FFFBFBFLLL
FFFBFFFRRL
BBFBFFFLLL
FBFBFBFLRR
BFBFFFFRLL

41
2020/d05/ex2/ex2.py Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
import sys
from typing import List
def seat_id(boarding_pass: str) -> int:
min_x = 0
max_x = 128
min_y = 0
max_y = 8
for char in boarding_pass:
if char == "F":
max_x = (min_x + max_x) // 2
elif char == "B":
min_x = (min_x + max_x) // 2
elif char == "L":
max_y = (min_y + max_y) // 2
elif char == "R":
min_y = (min_y + max_y) // 2
return min_x * 8 + min_y
def solve(passes: List[str]) -> int:
ids = sorted(seat_id(p) for p in passes)
for prev, cur in zip(ids, ids[1:]):
if prev + 1 != cur:
return prev + 1
assert False # Sanity check
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

781
2020/d05/ex2/input Normal file
View file

@ -0,0 +1,781 @@
FBFFBFFRLL
BFFFFBBRLR
FFFBBBBRLR
FBFFFBFLRL
FFBFBFFRRL
FFBBBBFRRR
FBFFBFBLRR
FFBBFBFRRL
FFFFBBFRRL
BFBBBBBLLL
FFBFBFBLLL
FFBFFFBLLL
FBBBFBFRLL
BBFFFBFRRR
FFFBFBBLLR
FBFBFBFRRR
BBFFBFBRLL
FBFBBBBLRL
FBFFFFFLLL
BFFFFFFRLL
BFFFBFBLRL
BFBBBFBRRL
BFFFBFFRRL
FBFFFFFRRR
FFBBBBBLLR
BFBBFFBLRL
FBBFBBBRLR
BFBFBFFRLL
BFBFBFBRLL
BFFBFBFLLL
FFBBFFBLRL
FBBFFBFLRR
FBBBFBBRRR
BFBFFBFRLR
BFBBBFBLLL
FFBFBBBLRR
BFBFFBFLLL
FBFBFBBLLL
BFBBBFBLRL
FBFBFBFLRL
FFBFFBFRRL
FBBFFBFLLL
BFBBBBBLRL
FBBBBBFRLR
BFFFBBFRLL
FBBB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BFBBFBBRRR
BFBFBBFRRL
BFFBBBFRRL
FFFBFFFLLL
FBBFFBFLRL
FFFBFBBRLR
BFBBFFFLLR
BFBBFFBRRR
FBFFBFBRRL
FFBBBBBRLL
BFFBFFBLLL
BFFFBBFRRR
FBFFFBFRRR
FFBFBFBRLR
FBFBBFFLLR
FBBFBBBRRR
BFBFFFFRRR
FFBFFFFLLL
FBFBBFFRLL
BFBFFBFLRL
BFBBFFFLLL
FBFBBFBRRR
BFBFFFBLLR
BFBFFFBLLL
BBFFFBFLLR
BBFFBFFRLL
FFBBBBFRRL
BBFFFBFLRL
BBFFBBBLRL
BFBFFFBLRR
FFFBFBFRLL
BFBFFBBLLL
BBFFFBBRRL
BFBBBFFLLL
BFFBBFFLLR
FFBFFBBLLL
BFFBBFBRRL
BFFFFFBLRL
BBFFFFBRLR
FBFBBFFLLL
FFBBBFBRLR
FFFBBFBLLL
FBFFFBBRLR
FFBFBFFRLR
BFFFFFBLRR
FFFBBBBRLL
FFBBFFFRRR
BFFFFFBRLR
FBBBFFBLRR
FBFBFBBRLR
FBBFFFBLRR
BFBFFBBLRL
FBFFBFBRLR
FBFBFFFLRL
BFFFFFBRLL
BFBBBBFLRR
BFFBFFFLLL
FBFFBFFRRL
FFFBBFFRLL
BFFFBFFRRR
FBFFBFFLLR
FFFBBBFLLL
FBFFFBFLRR
BFFBFBBLLL
BFFFBBBLRR
FBBBBBBRRL
FBFFBFFRLR
FBBFFBBRLL
FBBBFFFRRR
BFFBFBBRRL
FFBBFFBRRR
BFBBBFFLRR
FFFBFBBRRL
BFBFBBBLRR
FFFBBFBLRL
FBFFBBFRLR
BFFFBBFLRR
BBFFFBBLRL
FBBFFBFRLR
FFFBFBFLLL
FFFBFFFRRL
BBFBFFFLLL
FBFBFBFLRR
BFBFFFFRLL

25
2020/d06/ex1/ex1.py Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env python
import sys
from collections import defaultdict
from typing import DefaultDict, List, Set
def solve(raw: List[str]) -> int:
answers: DefaultDict[int, Set[str]] = defaultdict(set)
group = 0
for line in raw:
if line == "":
group += 1
continue
answers[group] |= {char for char in line}
return sum(len(answer) for answer in answers.values())
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2246
2020/d06/ex1/input Normal file

File diff suppressed because it is too large Load diff

31
2020/d06/ex2/ex2.py Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
import sys
from collections import defaultdict
from typing import DefaultDict, List, Set
def solve(raw: List[str]) -> int:
answers: DefaultDict[int, Set[str]] = defaultdict(set)
group = 0
first = True
for line in raw:
if line == "":
group += 1
first = True
continue
if not first:
answers[group] &= {char for char in line}
else:
answers[group] = {char for char in line}
first = False
return sum(len(answer) for answer in answers.values())
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2246
2020/d06/ex2/input Normal file

File diff suppressed because it is too large Load diff

77
2020/d07/ex1/ex1.py Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env python
import re
import sys
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass
from typing import Dict, List, Set, Tuple
@dataclass(eq=True, frozen=True) # Hashable
class ColorInfo:
num: int
color: str
Graph = Dict[str, Set[ColorInfo]]
def extract_info(line: str) -> Tuple[str, Set[ColorInfo]]:
color_pattern = re.compile("(.*) contain ")
match = color_pattern.search(line)
assert match is not None
color = match.group(1).replace("bags", "bag")
line = line[match.end() : -1] # Remove period at end of line
if line == "no other bags":
return color, set()
colors: Set[ColorInfo] = set()
pattern = re.compile("([0-9]+) (.*)")
for col in line.split(", "):
match = pattern.search(col)
assert match is not None
colors |= {
ColorInfo(int(match.group(1)), match.group(2).replace("bags", "bag"))
}
return color, colors
def to_graph(raw: List[str]) -> Graph:
return {color: inside for color, inside in map(extract_info, raw)}
def reverse(graph: Graph) -> Graph:
reverse: Graph = defaultdict(set)
for color, contained in graph.items():
for col in contained:
reverse[col.color] |= {ColorInfo(-1, color)}
return reverse
def containing(graph: Graph, col: str) -> Set[ColorInfo]:
res = deepcopy(graph[col])
for contains in graph[col]:
res |= containing(graph, contains.color)
return res
def solve(raw: List[str]) -> int:
graph = to_graph(raw)
reverse_graph = reverse(graph)
return len(containing(reverse_graph, "shiny gold bag"))
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

594
2020/d07/ex1/input Normal file
View file

@ -0,0 +1,594 @@
shiny aqua bags contain 1 dark white bag.
muted blue bags contain 1 vibrant lavender bag, 4 dotted silver bags, 2 dim indigo bags.
drab gray bags contain 5 mirrored white bags, 1 light green bag, 5 shiny lavender bags, 5 faded aqua bags.
muted indigo bags contain 4 muted chartreuse bags, 2 dotted teal bags.
drab white bags contain 2 dull fuchsia bags, 1 vibrant bronze bag.
dim lavender bags contain 4 muted tan bags.
dotted tomato bags contain 1 mirrored lime bag, 2 vibrant white bags.
clear orange bags contain 5 clear violet bags, 2 dull beige bags, 2 dark chartreuse bags.
bright lime bags contain no other bags.
striped brown bags contain 3 bright orange bags.
vibrant green bags contain 3 shiny fuchsia bags.
plaid tomato bags contain 3 faded chartreuse bags, 2 wavy salmon bags, 1 faded white bag, 3 mirrored maroon bags.
drab beige bags contain 2 shiny bronze bags, 4 pale violet bags, 3 bright tomato bags, 4 pale red bags.
posh green bags contain 2 dull lavender bags, 4 clear plum bags, 2 dark gray bags.
dull maroon bags contain 3 dull magenta bags, 1 dull tan bag, 1 faded cyan bag, 5 dull silver bags.
faded crimson bags contain 2 muted purple bags, 4 dotted olive bags, 5 drab silver bags.
wavy bronze bags contain 3 dark orange bags, 2 dark brown bags, 5 bright silver bags.
dark turquoise bags contain 5 dull plum bags.
dull lavender bags contain 4 dotted maroon bags, 3 muted brown bags, 4 drab black bags, 4 dull cyan bags.
dotted plum bags contain 1 shiny bronze bag, 3 clear brown bags, 3 muted indigo bags.
dull white bags contain 3 clear tan bags, 5 shiny gold bags, 2 drab crimson bags.
dull teal bags contain 2 bright tomato bags.
shiny crimson bags contain 3 light green bags, 5 striped brown bags, 3 faded fuchsia bags.
wavy brown bags contain 1 drab crimson bag, 2 wavy indigo bags.
dark tan bags contain 2 faded gray bags, 4 shiny salmon bags.
shiny red bags contain 4 dull chartreuse bags, 5 pale tomato bags.
bright orange bags contain no other bags.
wavy yellow bags contain 5 light indigo bags, 5 dark gray bags, 5 plaid indigo bags, 4 faded red bags.
faded bronze bags contain 4 faded cyan bags, 5 shiny beige bags, 5 muted red bags.
dull bronze bags contain 1 mirrored beige bag, 5 muted violet bags, 1 wavy lime bag.
dark lime bags contain 2 drab maroon bags, 5 bright indigo bags, 4 shiny black bags, 5 dotted turquoise bags.
drab red bags contain 5 bright red bags, 2 vibrant brown bags.
dotted salmon bags contain 3 vibrant turquoise bags, 2 dull beige bags, 3 light turquoise bags.
dull gray bags contain 3 striped green bags, 3 wavy coral bags, 1 dark gray bag, 2 light indigo bags.
faded black bags contain 4 muted fuchsia bags, 4 wavy coral bags, 1 drab tomato bag.
muted magenta bags contain 2 posh chartreuse bags, 4 pale violet bags.
light tan bags contain 2 posh turquoise bags, 3 vibrant white bags, 1 light black bag.
dark blue bags contain 3 plaid indigo bags, 2 posh black bags.
dull indigo bags contain 4 light gray bags, 3 dotted tan bags, 4 dull coral bags.
dim fuchsia bags contain 3 vibrant yellow bags, 3 mirrored cyan bags, 4 mirrored brown bags.
shiny beige bags contain 2 dull silver bags, 3 bright lime bags, 5 dull magenta bags.
light cyan bags contain 3 vibrant violet bags, 2 mirrored tomato bags, 2 vibrant coral bags, 4 mirrored silver bags.
clear turquoise bags contain 4 drab tomato bags, 3 shiny gold bags, 4 drab gold bags.
pale teal bags contain 2 wavy maroon bags, 2 dotted olive bags, 4 shiny white bags, 2 drab turquoise bags.
dark purple bags contain 1 wavy indigo bag, 3 bright black bags, 3 dotted teal bags.
bright white bags contain 5 wavy red bags, 2 mirrored cyan bags, 3 drab green bags.
mirrored aqua bags contain 1 faded violet bag, 5 dotted purple bags.
shiny lime bags contain 4 dark aqua bags.
pale bronze bags contain 1 clear crimson bag.
vibrant white bags contain 5 plaid lavender bags, 1 drab red bag, 4 vibrant brown bags.
plaid tan bags contain 5 dim crimson bags.
posh olive bags contain 3 bright red bags.
plaid brown bags contain 5 vibrant turquoise bags.
mirrored tomato bags contain 2 dotted chartreuse bags, 3 light aqua bags, 3 posh beige bags.
plaid blue bags contain 5 striped green bags, 1 plaid purple bag, 4 muted gold bags.
shiny tan bags contain 5 striped coral bags, 1 dull brown bag.
shiny gold bags contain 1 dull magenta bag, 5 dark white bags, 4 faded turquoise bags.
dull salmon bags contain 2 plaid gold bags, 2 light indigo bags.
striped tomato bags contain 2 striped tan bags, 4 light blue bags, 4 drab tan bags.
drab tomato bags contain 3 dim teal bags, 4 striped yellow bags, 3 bright red bags.
faded olive bags contain 1 drab plum bag, 1 pale aqua bag, 3 light blue bags.
dotted indigo bags contain 2 clear tomato bags.
dark white bags contain 5 light aqua bags, 2 dim teal bags, 2 muted fuchsia bags, 5 light purple bags.
dull orange bags contain 4 pale gold bags, 5 posh brown bags, 2 mirrored brown bags, 3 dark bronze bags.
bright maroon bags contain 1 mirrored yellow bag, 4 light teal bags.
bright silver bags contain 1 vibrant coral bag, 3 dim teal bags, 5 light purple bags.
muted olive bags contain 5 plaid orange bags, 1 muted magenta bag.
dull silver bags contain no other bags.
pale maroon bags contain 2 pale bronze bags.
light gray bags contain 4 vibrant yellow bags, 2 pale red bags.
drab teal bags contain 2 light crimson bags, 3 vibrant brown bags, 3 vibrant tan bags.
bright gold bags contain 1 wavy red bag, 5 wavy coral bags.
plaid chartreuse bags contain 2 dim coral bags, 4 drab silver bags, 5 dim chartreuse bags, 3 light purple bags.
clear blue bags contain 2 pale tomato bags, 4 dull gold bags, 4 dim fuchsia bags, 4 pale coral bags.
vibrant purple bags contain 5 faded orange bags.
plaid aqua bags contain 3 muted cyan bags, 2 wavy gray bags, 4 drab green bags, 4 pale beige bags.
muted lime bags contain 1 muted tan bag.
faded coral bags contain 3 drab turquoise bags, 1 shiny plum bag, 5 mirrored green bags, 5 clear white bags.
vibrant lime bags contain 5 posh coral bags.
faded green bags contain 3 pale orange bags, 5 dull turquoise bags, 1 mirrored crimson bag.
mirrored gray bags contain 5 dim indigo bags.
wavy maroon bags contain 4 mirrored bronze bags, 1 striped olive bag, 2 dull salmon bags, 3 shiny crimson bags.
dark violet bags contain 2 light purple bags.
dark green bags contain 2 dim cyan bags.
pale black bags contain 1 mirrored gold bag.
bright yellow bags contain 2 vibrant crimson bags, 3 plaid lime bags, 2 dotted gold bags.
muted teal bags contain 1 pale violet bag, 4 dull silver bags.
dim beige bags contain 5 wavy red bags.
muted purple bags contain 4 clear cyan bags.
plaid fuchsia bags contain 3 dark coral bags.
plaid bronze bags contain 5 plaid orange bags, 2 drab indigo bags.
faded indigo bags contain 1 dark chartreuse bag, 4 dull green bags, 1 mirrored magenta bag.
posh plum bags contain 3 dark chartreuse bags, 3 dotted turquoise bags, 4 dull maroon bags, 1 posh bronze bag.
pale gold bags contain 4 striped brown bags.
mirrored chartreuse bags contain 4 bright silver bags, 3 mirrored tomato bags, 4 wavy orange bags.
pale orange bags contain 2 posh fuchsia bags, 2 clear salmon bags, 2 bright green bags.
clear brown bags contain 4 light lime bags, 4 bright green bags, 5 pale yellow bags, 2 drab cyan bags.
shiny plum bags contain 5 vibrant gray bags, 3 bright blue bags, 5 dark tomato bags.
wavy white bags contain 4 plaid lime bags, 4 posh maroon bags, 5 drab lime bags, 1 vibrant crimson bag.
faded red bags contain 1 dull coral bag, 5 clear cyan bags, 4 plaid chartreuse bags, 3 plaid orange bags.
plaid red bags contain 5 pale blue bags, 4 light crimson bags, 3 faded fuchsia bags.
bright cyan bags contain 3 dark white bags, 2 light crimson bags, 1 bright aqua bag.
muted lavender bags contain 1 light green bag, 4 striped silver bags, 3 posh crimson bags.
wavy crimson bags contain 1 light purple bag, 4 bright blue bags, 2 dull coral bags, 1 wavy beige bag.
faded aqua bags contain 5 muted brown bags.
mirrored fuchsia bags contain 1 faded beige bag, 3 muted gold bags.
dark chartreuse bags contain 5 bright lime bags.
plaid green bags contain 4 mirrored tan bags, 1 mirrored tomato bag, 5 pale indigo bags, 1 mirrored plum bag.
shiny black bags contain 3 plaid chartreuse bags.
dotted purple bags contain 2 dim teal bags.
faded tan bags contain 2 bright fuchsia bags, 5 shiny fuchsia bags, 1 muted fuchsia bag, 1 mirrored brown bag.
drab brown bags contain 1 striped orange bag, 4 dotted tomato bags.
dull olive bags contain 1 striped black bag, 1 vibrant magenta bag.
mirrored plum bags contain 1 clear gold bag, 5 pale green bags.
dim tomato bags contain 4 drab gold bags, 2 shiny aqua bags.
light lavender bags contain 1 muted violet bag.
dim gray bags contain 3 light purple bags, 1 posh crimson bag, 1 faded brown bag.
muted aqua bags contain 4 dull beige bags, 4 dull red bags.
faded silver bags contain 1 mirrored cyan bag.
shiny green bags contain 5 dull maroon bags.
muted chartreuse bags contain 2 clear tan bags.
plaid plum bags contain 1 dotted lime bag, 4 clear brown bags, 4 dull red bags.
dotted silver bags contain 1 posh coral bag.
dim crimson bags contain 4 faded violet bags, 1 striped silver bag.
bright brown bags contain 1 bright coral bag, 3 posh brown bags, 4 drab tan bags.
wavy cyan bags contain 3 clear gold bags, 1 mirrored salmon bag, 3 bright fuchsia bags, 2 light bronze bags.
dull violet bags contain 5 striped white bags, 4 light blue bags, 4 dim black bags.
vibrant olive bags contain 2 vibrant coral bags.
bright coral bags contain 2 vibrant tan bags, 3 shiny indigo bags, 2 plaid indigo bags.
dim turquoise bags contain 1 pale violet bag.
striped crimson bags contain 2 faded gray bags.
clear green bags contain 3 mirrored olive bags, 3 shiny tomato bags.
faded violet bags contain 2 wavy coral bags, 2 dull tan bags, 1 dull silver bag, 1 bright orange bag.
pale chartreuse bags contain 4 shiny crimson bags, 2 clear bronze bags.
light plum bags contain 3 drab bronze bags, 1 bright bronze bag, 1 posh yellow bag.
pale tomato bags contain 1 dim teal bag, 5 drab cyan bags, 3 muted coral bags, 2 dim chartreuse bags.
plaid coral bags contain 1 striped tan bag, 3 vibrant cyan bags, 3 light beige bags, 2 dotted green bags.
bright gray bags contain 4 mirrored teal bags, 4 striped brown bags, 1 dim green bag, 4 clear cyan bags.
drab fuchsia bags contain 2 mirrored salmon bags, 4 posh orange bags, 3 faded crimson bags, 3 pale plum bags.
light tomato bags contain 2 dotted gold bags, 1 dotted bronze bag.
muted violet bags contain 2 light chartreuse bags.
drab tan bags contain 2 light green bags, 5 bright red bags, 4 shiny beige bags.
drab chartreuse bags contain 2 drab salmon bags, 2 dark brown bags, 4 clear turquoise bags.
drab violet bags contain 4 faded red bags.
posh cyan bags contain 4 bright violet bags.
posh orange bags contain 4 pale plum bags, 5 posh aqua bags.
plaid silver bags contain 1 dotted brown bag, 3 drab gold bags, 4 clear yellow bags.
mirrored silver bags contain 3 shiny beige bags, 1 drab silver bag.
faded gray bags contain no other bags.
wavy tomato bags contain 1 bright brown bag, 3 striped red bags, 2 vibrant maroon bags.
posh violet bags contain 2 dim aqua bags.
bright blue bags contain 5 light lime bags, 2 faded violet bags, 3 light aqua bags, 4 vibrant coral bags.
dark teal bags contain 5 muted fuchsia bags.
striped fuchsia bags contain 1 wavy turquoise bag, 5 wavy green bags, 4 posh gold bags.
posh maroon bags contain 2 dull red bags.
shiny purple bags contain 2 clear tan bags.
wavy lime bags contain 2 dark coral bags, 1 shiny gold bag.
wavy silver bags contain 4 dotted white bags.
shiny silver bags contain 2 plaid gold bags, 2 dim green bags, 5 plaid lime bags, 3 dull red bags.
wavy red bags contain 3 vibrant brown bags, 4 bright indigo bags.
dull chartreuse bags contain 4 dotted lime bags, 2 bright silver bags, 3 dull red bags, 4 wavy maroon bags.
vibrant silver bags contain 1 bright fuchsia bag, 3 drab lavender bags, 2 drab olive bags, 3 dotted teal bags.
striped gray bags contain 5 plaid orange bags, 1 wavy coral bag.
striped green bags contain 4 wavy coral bags, 4 shiny gold bags, 3 dark brown bags, 5 vibrant brown bags.
mirrored violet bags contain 3 dim silver bags, 1 posh tomato bag, 1 light salmon bag.
dull purple bags contain 1 light gray bag, 3 wavy yellow bags, 1 wavy salmon bag.
mirrored beige bags contain 4 dark cyan bags, 5 dull green bags.
posh lime bags contain 3 posh chartreuse bags.
vibrant tan bags contain 2 dull plum bags, 1 striped brown bag, 4 vibrant coral bags.
dotted orange bags contain 1 mirrored olive bag, 5 drab silver bags.
clear indigo bags contain 3 light lime bags, 4 dull coral bags.
pale gray bags contain 1 faded black bag, 3 dim green bags, 4 wavy lavender bags, 2 posh brown bags.
posh gold bags contain 5 dark tan bags, 2 dotted olive bags, 5 dark aqua bags.
striped chartreuse bags contain 2 dull magenta bags, 1 posh tomato bag.
mirrored bronze bags contain 2 faded fuchsia bags.
clear salmon bags contain 4 posh bronze bags, 5 clear plum bags, 5 dull blue bags.
posh purple bags contain 5 dim gray bags, 3 faded brown bags.
faded lime bags contain 5 dim turquoise bags, 3 dark indigo bags, 2 vibrant gray bags, 1 muted silver bag.
wavy beige bags contain 1 dark bronze bag, 4 dull plum bags, 4 mirrored silver bags.
clear yellow bags contain 2 vibrant teal bags.
vibrant plum bags contain 4 muted chartreuse bags, 4 posh silver bags.
striped yellow bags contain 2 dull maroon bags, 5 bright red bags, 2 posh chartreuse bags.
dark coral bags contain 3 dull tan bags.
dull magenta bags contain no other bags.
dark gold bags contain 1 dotted indigo bag, 4 shiny teal bags, 4 dotted silver bags.
dim tan bags contain 1 striped lavender bag, 1 shiny tomato bag.
muted maroon bags contain 2 dull salmon bags, 4 dim chartreuse bags, 3 bright aqua bags, 2 faded indigo bags.
vibrant tomato bags contain 2 dark silver bags, 3 plaid purple bags.
dotted lime bags contain 3 shiny crimson bags, 2 pale yellow bags.
muted fuchsia bags contain 1 dull tan bag.
bright tan bags contain 5 pale gold bags, 5 drab teal bags, 2 light blue bags.
dark crimson bags contain 4 shiny orange bags, 3 faded purple bags, 3 bright white bags.
striped tan bags contain 4 dotted turquoise bags, 4 drab lime bags, 5 dim teal bags.
posh fuchsia bags contain 2 dotted olive bags, 2 mirrored beige bags, 3 shiny bronze bags.
pale silver bags contain 4 vibrant lavender bags, 4 clear beige bags, 4 striped gold bags.
posh aqua bags contain 4 drab lime bags, 4 dull tan bags, 5 vibrant tan bags.
plaid salmon bags contain 5 dim coral bags, 2 wavy bronze bags.
mirrored orange bags contain 4 vibrant gray bags.
dim yellow bags contain 5 pale tan bags, 4 dark black bags.
dotted coral bags contain 4 dotted chartreuse bags, 2 bright red bags, 1 vibrant white bag, 1 vibrant brown bag.
muted crimson bags contain 4 striped orange bags, 5 pale yellow bags, 3 posh blue bags, 1 muted red bag.
striped lavender bags contain 3 striped brown bags.
striped maroon bags contain 2 shiny yellow bags.
vibrant blue bags contain 3 faded cyan bags, 1 shiny lime bag, 3 dark tomato bags.
pale lavender bags contain 4 plaid magenta bags, 4 striped blue bags.
dull tan bags contain 4 shiny indigo bags, 2 light purple bags, 4 faded cyan bags.
dotted beige bags contain 3 drab indigo bags.
light indigo bags contain 1 faded cyan bag, 5 bright aqua bags, 1 shiny indigo bag.
vibrant crimson bags contain 4 dotted fuchsia bags.
wavy blue bags contain 4 wavy teal bags, 1 dull blue bag.
vibrant chartreuse bags contain 4 striped orange bags.
vibrant cyan bags contain 5 wavy coral bags.
faded brown bags contain 5 faded turquoise bags.
faded magenta bags contain 1 dull indigo bag, 4 plaid aqua bags, 4 dim crimson bags.
mirrored coral bags contain 4 drab crimson bags, 2 light salmon bags, 2 clear indigo bags.
faded cyan bags contain no other bags.
dark brown bags contain 5 light purple bags.
wavy violet bags contain 3 dull coral bags, 1 bright aqua bag, 3 shiny lavender bags.
posh tomato bags contain 4 vibrant chartreuse bags, 4 mirrored teal bags.
pale crimson bags contain 1 plaid orange bag, 1 dark violet bag, 3 plaid lavender bags.
dark fuchsia bags contain 4 plaid beige bags, 2 plaid chartreuse bags.
plaid magenta bags contain 3 clear lavender bags, 5 mirrored brown bags, 5 shiny bronze bags.
striped blue bags contain 1 dull bronze bag, 1 dotted fuchsia bag, 1 light lavender bag, 1 clear turquoise bag.
dotted olive bags contain 4 dotted turquoise bags, 5 dotted bronze bags, 3 pale yellow bags, 4 pale red bags.
posh silver bags contain 3 pale violet bags, 1 plaid salmon bag, 1 posh coral bag.
dotted chartreuse bags contain 3 bright blue bags.
light coral bags contain 4 shiny fuchsia bags, 2 pale red bags, 1 muted silver bag, 2 bright cyan bags.
pale brown bags contain 5 light aqua bags.
dotted black bags contain 2 plaid purple bags, 1 mirrored aqua bag, 5 posh beige bags.
posh coral bags contain 3 dark aqua bags, 2 pale yellow bags, 5 plaid blue bags, 4 dim aqua bags.
shiny gray bags contain 1 bright gold bag, 1 muted bronze bag, 5 striped green bags, 5 shiny teal bags.
drab orange bags contain 5 plaid salmon bags, 2 vibrant beige bags.
plaid yellow bags contain 4 clear teal bags, 2 bright red bags.
striped violet bags contain 4 mirrored fuchsia bags, 4 vibrant white bags, 3 dim teal bags.
dim aqua bags contain 1 muted fuchsia bag, 1 dull tan bag.
light orange bags contain 2 bright red bags, 4 dark white bags, 1 dim chartreuse bag, 5 faded fuchsia bags.
faded salmon bags contain 5 wavy gray bags.
shiny yellow bags contain 2 vibrant plum bags, 3 dim teal bags, 1 plaid tan bag, 5 posh plum bags.
vibrant beige bags contain 2 wavy lavender bags, 4 posh chartreuse bags, 3 pale teal bags, 5 wavy lime bags.
light fuchsia bags contain 3 clear brown bags, 3 bright lavender bags.
pale magenta bags contain 4 posh silver bags.
dark maroon bags contain 3 drab turquoise bags.
faded beige bags contain 1 vibrant white bag, 4 drab red bags, 1 drab lavender bag.
bright bronze bags contain 1 pale bronze bag, 3 muted silver bags, 2 striped coral bags, 3 clear gray bags.
light silver bags contain 3 dotted lavender bags, 2 wavy lavender bags.
muted salmon bags contain 2 drab tan bags, 5 wavy tomato bags.
bright black bags contain 5 plaid tan bags.
dim chartreuse bags contain 5 muted gold bags, 5 bright blue bags, 5 faded cyan bags.
shiny white bags contain 4 bright tan bags.
bright red bags contain 3 dull silver bags.
dark aqua bags contain 2 dull red bags.
drab plum bags contain 4 muted brown bags, 5 muted plum bags.
muted yellow bags contain 5 light purple bags, 3 dotted silver bags, 3 faded turquoise bags.
light violet bags contain 1 pale red bag, 4 dim silver bags, 2 mirrored bronze bags.
pale lime bags contain 4 bright lavender bags.
pale tan bags contain 4 striped green bags, 2 dotted chartreuse bags.
dim green bags contain 1 light lime bag, 1 shiny beige bag.
mirrored gold bags contain 4 mirrored white bags.
dim silver bags contain 5 pale coral bags, 3 wavy coral bags.
dull aqua bags contain 3 posh indigo bags, 5 dotted coral bags, 1 dark salmon bag, 3 striped crimson bags.
posh yellow bags contain 1 dark bronze bag, 2 mirrored white bags, 2 light crimson bags.
mirrored magenta bags contain 1 bright violet bag, 2 drab lavender bags, 3 pale violet bags, 2 plaid salmon bags.
shiny chartreuse bags contain 2 dotted purple bags, 5 wavy red bags, 3 plaid beige bags.
light black bags contain 1 dark chartreuse bag, 3 faded tomato bags.
clear plum bags contain 5 vibrant brown bags, 3 dim coral bags, 4 mirrored brown bags, 1 faded black bag.
pale violet bags contain 2 dull tan bags.
bright fuchsia bags contain 4 dull orange bags.
dotted teal bags contain 5 bright red bags, 3 wavy red bags, 1 dull coral bag, 3 clear plum bags.
dotted blue bags contain 2 wavy beige bags, 3 muted purple bags.
muted gray bags contain 3 faded aqua bags, 1 shiny olive bag, 5 clear salmon bags, 1 vibrant violet bag.
dull beige bags contain 1 wavy lavender bag, 4 dark bronze bags, 5 dull tan bags.
drab turquoise bags contain 3 posh gray bags, 5 drab red bags.
vibrant yellow bags contain 2 shiny aqua bags, 4 light chartreuse bags.
posh brown bags contain 3 bright green bags, 5 posh lavender bags.
faded gold bags contain 4 vibrant maroon bags, 4 dotted purple bags.
dotted turquoise bags contain 5 clear plum bags, 3 muted gold bags, 4 dark violet bags.
dotted tan bags contain 5 dim aqua bags, 4 striped violet bags.
posh crimson bags contain 4 striped blue bags, 5 dull magenta bags, 2 bright coral bags.
muted white bags contain 5 dull olive bags.
vibrant teal bags contain 5 dotted turquoise bags, 1 striped tan bag, 1 drab tan bag.
dotted yellow bags contain 3 plaid turquoise bags, 2 posh yellow bags, 4 striped blue bags, 5 posh black bags.
posh magenta bags contain 5 mirrored black bags.
dotted green bags contain 4 dim crimson bags, 1 shiny lavender bag, 4 bright salmon bags, 1 plaid gray bag.
bright green bags contain 3 bright aqua bags, 3 dull maroon bags, 4 dark brown bags.
dark gray bags contain 5 muted purple bags, 2 striped blue bags, 4 faded lavender bags.
bright crimson bags contain 2 striped olive bags, 3 muted blue bags.
muted cyan bags contain 3 shiny tomato bags.
light yellow bags contain 2 striped red bags, 4 shiny crimson bags.
pale aqua bags contain 5 shiny yellow bags, 3 dark lavender bags, 3 posh white bags.
clear red bags contain 1 dotted silver bag, 1 dull teal bag, 1 faded maroon bag, 1 dotted salmon bag.
pale red bags contain 2 faded gray bags.
dotted maroon bags contain 5 posh aqua bags, 3 dull silver bags.
dull blue bags contain 4 light crimson bags, 3 light lime bags, 1 dark orange bag, 5 light indigo bags.
posh turquoise bags contain 1 muted gold bag, 5 striped lavender bags, 3 dull salmon bags, 5 vibrant chartreuse bags.
striped magenta bags contain 1 posh silver bag, 5 dark brown bags.
pale blue bags contain 2 muted gold bags, 4 vibrant brown bags, 1 light lavender bag.
vibrant violet bags contain 5 bright red bags.
faded fuchsia bags contain 2 light lime bags, 4 bright lime bags, 3 pale violet bags.
shiny coral bags contain 1 clear plum bag, 5 muted chartreuse bags, 1 muted violet bag, 5 striped yellow bags.
pale olive bags contain 4 plaid lime bags, 1 posh salmon bag.
wavy tan bags contain 3 faded gray bags.
faded chartreuse bags contain 3 dim coral bags, 1 mirrored bronze bag, 3 posh bronze bags.
mirrored brown bags contain 1 faded violet bag, 4 dull maroon bags, 5 dotted magenta bags.
clear white bags contain 5 muted magenta bags, 4 dull magenta bags, 3 pale plum bags, 4 drab indigo bags.
drab maroon bags contain 2 clear beige bags, 3 wavy beige bags, 5 faded purple bags.
striped silver bags contain 3 drab tomato bags.
faded plum bags contain 1 clear teal bag, 3 bright aqua bags.
plaid violet bags contain 2 drab violet bags, 4 muted turquoise bags, 5 muted indigo bags.
clear black bags contain 5 muted fuchsia bags, 1 muted coral bag, 2 light black bags.
vibrant maroon bags contain 1 dark lavender bag, 1 pale crimson bag, 4 bright indigo bags, 5 mirrored maroon bags.
drab indigo bags contain 2 dim coral bags, 1 drab green bag, 2 shiny lavender bags.
drab olive bags contain 2 dark aqua bags, 4 striped brown bags.
dull crimson bags contain 3 dull cyan bags.
wavy teal bags contain 4 striped orange bags, 2 drab cyan bags.
dark red bags contain 2 dull maroon bags, 4 muted plum bags, 4 dull plum bags.
striped salmon bags contain 3 bright red bags, 1 light aqua bag, 4 wavy gold bags.
mirrored tan bags contain 5 dotted olive bags, 2 dim tomato bags, 2 mirrored tomato bags, 4 clear teal bags.
striped white bags contain 2 pale coral bags, 2 shiny green bags.
shiny tomato bags contain 5 pale coral bags, 5 dull beige bags.
vibrant indigo bags contain 2 dim black bags, 4 dim blue bags, 3 dim white bags.
wavy lavender bags contain 4 faded bronze bags, 4 muted red bags, 3 light lime bags, 4 muted gold bags.
shiny turquoise bags contain 2 dull red bags, 5 faded gray bags, 1 muted turquoise bag.
shiny lavender bags contain 5 bright aqua bags.
posh tan bags contain 1 shiny yellow bag, 3 drab magenta bags.
light green bags contain 4 bright red bags, 1 vibrant coral bag.
drab black bags contain 5 faded tomato bags, 3 dotted chartreuse bags.
clear chartreuse bags contain 3 wavy bronze bags, 4 plaid purple bags, 3 dark orange bags.
dull black bags contain 1 wavy teal bag, 3 light lavender bags, 2 striped indigo bags.
wavy black bags contain 2 clear orange bags, 4 muted purple bags.
pale plum bags contain 1 bright coral bag, 1 drab tan bag, 1 plaid fuchsia bag, 1 dotted fuchsia bag.
dotted violet bags contain 3 bright black bags.
posh red bags contain 3 bright black bags.
plaid lime bags contain 5 posh beige bags, 1 dotted turquoise bag.
wavy aqua bags contain 1 dark yellow bag, 3 drab indigo bags.
dim magenta bags contain 3 dark violet bags.
drab aqua bags contain 5 posh orange bags, 1 dark silver bag, 4 plaid purple bags, 2 wavy teal bags.
dull brown bags contain 4 light lime bags.
striped orange bags contain 5 light crimson bags, 3 muted tan bags, 5 dotted coral bags, 3 plaid blue bags.
muted brown bags contain 1 posh blue bag, 4 dotted magenta bags, 3 dull coral bags.
faded blue bags contain 5 striped black bags, 1 vibrant yellow bag.
plaid indigo bags contain 3 dark brown bags, 5 light purple bags, 4 light aqua bags, 3 light green bags.
plaid turquoise bags contain 5 dotted teal bags.
light turquoise bags contain 2 dull salmon bags, 5 dotted tan bags.
dim purple bags contain 4 muted white bags, 5 drab purple bags.
pale coral bags contain 5 posh gray bags.
clear lime bags contain 3 dim magenta bags, 3 plaid tomato bags, 1 drab magenta bag, 3 shiny purple bags.
dim black bags contain 3 clear gold bags, 4 muted violet bags.
light maroon bags contain 4 muted yellow bags, 1 pale cyan bag, 2 mirrored turquoise bags, 4 dull lavender bags.
clear magenta bags contain 2 shiny magenta bags, 2 muted chartreuse bags.
striped bronze bags contain 5 clear tan bags, 1 drab lavender bag, 2 pale crimson bags.
dark salmon bags contain 1 vibrant plum bag, 5 drab tan bags, 4 drab coral bags, 4 dull tan bags.
vibrant salmon bags contain 2 muted olive bags.
dim gold bags contain 2 dim olive bags, 5 plaid olive bags, 2 posh orange bags.
wavy chartreuse bags contain 4 shiny yellow bags, 4 vibrant blue bags.
vibrant brown bags contain 3 striped brown bags, 4 muted red bags, 2 shiny indigo bags.
plaid maroon bags contain 2 muted teal bags, 2 pale yellow bags, 2 bright beige bags, 5 striped yellow bags.
dim indigo bags contain 4 dull tomato bags, 4 clear cyan bags, 2 shiny salmon bags, 1 bright aqua bag.
muted red bags contain 3 dull tan bags, 4 dull magenta bags, 1 bright aqua bag.
posh beige bags contain 5 shiny black bags, 3 dotted magenta bags, 3 drab blue bags, 2 muted coral bags.
pale fuchsia bags contain 3 dark brown bags, 5 posh gold bags.
dark bronze bags contain 1 dim green bag, 5 posh chartreuse bags.
dim coral bags contain 3 dull coral bags, 3 striped brown bags.
drab crimson bags contain 2 dark bronze bags, 4 shiny indigo bags, 3 dull tan bags.
bright indigo bags contain 3 bright blue bags.
pale yellow bags contain 5 dim aqua bags, 1 vibrant brown bag, 2 vibrant tan bags, 3 wavy lavender bags.
drab salmon bags contain 1 dotted indigo bag, 3 muted chartreuse bags, 5 dark olive bags.
muted orange bags contain 4 faded lime bags, 2 dull coral bags, 5 vibrant magenta bags, 4 dull magenta bags.
striped gold bags contain 2 dull silver bags, 5 bright lavender bags, 5 dim teal bags, 5 dark coral bags.
posh chartreuse bags contain 3 dim teal bags, 5 light aqua bags.
shiny blue bags contain 3 dull tan bags, 5 muted magenta bags.
muted silver bags contain 3 wavy blue bags, 2 dim teal bags, 5 muted bronze bags.
shiny bronze bags contain 1 light green bag, 4 vibrant magenta bags.
wavy coral bags contain no other bags.
shiny orange bags contain 2 muted purple bags.
posh teal bags contain 4 clear plum bags.
striped turquoise bags contain 3 muted indigo bags.
dim bronze bags contain 2 shiny silver bags, 1 light silver bag, 2 dim indigo bags, 4 dim tomato bags.
plaid white bags contain 4 drab turquoise bags.
wavy indigo bags contain 3 clear gold bags, 5 mirrored bronze bags.
faded teal bags contain 4 mirrored white bags.
shiny fuchsia bags contain 3 drab indigo bags.
dim red bags contain 3 clear bronze bags.
dotted brown bags contain 4 wavy maroon bags, 5 drab green bags, 3 dark purple bags.
dark tomato bags contain 3 vibrant coral bags, 5 dull coral bags, 2 drab cyan bags, 1 posh blue bag.
clear teal bags contain 3 dark white bags.
dark silver bags contain 3 dark cyan bags, 4 plaid salmon bags.
wavy fuchsia bags contain 4 bright brown bags, 4 bright aqua bags, 5 light orange bags.
light bronze bags contain 4 clear plum bags.
striped purple bags contain 1 dim indigo bag.
clear tomato bags contain 4 mirrored tomato bags, 3 muted indigo bags, 1 striped tan bag.
muted turquoise bags contain 5 faded beige bags, 4 clear crimson bags, 2 bright teal bags.
dull cyan bags contain 5 mirrored aqua bags, 2 shiny aqua bags, 3 light black bags, 4 bright coral bags.
plaid crimson bags contain 2 mirrored teal bags, 2 dull fuchsia bags.
shiny maroon bags contain 1 posh gold bag.
dim white bags contain 5 striped brown bags, 2 dull magenta bags, 5 plaid tan bags.
muted green bags contain 2 dull magenta bags, 5 clear cyan bags.
plaid teal bags contain 2 dark tan bags, 3 pale lime bags.
dotted lavender bags contain 2 posh aqua bags, 3 dull cyan bags.
light salmon bags contain 5 dark silver bags.
faded white bags contain 2 wavy maroon bags, 3 dull cyan bags.
dull tomato bags contain 2 dim aqua bags, 4 posh lavender bags, 1 faded red bag.
dark olive bags contain 5 clear bronze bags, 2 drab plum bags.
pale indigo bags contain 2 mirrored beige bags, 5 wavy turquoise bags, 4 striped green bags, 2 dotted lavender bags.
plaid purple bags contain 1 light lime bag.
clear purple bags contain 3 vibrant white bags.
dark yellow bags contain 2 pale olive bags, 4 pale cyan bags, 5 bright teal bags.
muted beige bags contain 2 posh lime bags, 5 shiny gray bags, 2 dull blue bags.
vibrant orange bags contain 5 posh crimson bags, 4 light chartreuse bags.
light magenta bags contain 2 plaid maroon bags, 1 posh beige bag, 5 pale salmon bags.
dotted crimson bags contain 5 dark chartreuse bags.
striped coral bags contain 2 dim aqua bags.
striped aqua bags contain 3 posh salmon bags, 3 dull red bags.
mirrored salmon bags contain 5 bright red bags, 2 light green bags, 3 clear black bags, 5 posh brown bags.
posh white bags contain 4 drab violet bags, 2 dotted silver bags.
posh blue bags contain 4 dull maroon bags, 3 vibrant coral bags.
dim orange bags contain 2 dull olive bags.
shiny teal bags contain 1 faded tomato bag, 4 muted violet bags.
mirrored maroon bags contain 3 dull blue bags.
dark lavender bags contain 1 drab red bag, 3 shiny indigo bags, 4 faded beige bags, 1 drab turquoise bag.
shiny olive bags contain 3 dark violet bags, 1 striped gold bag, 2 mirrored lime bags.
bright violet bags contain 2 wavy bronze bags, 3 drab olive bags, 5 mirrored olive bags, 2 wavy lavender bags.
clear olive bags contain 5 faded turquoise bags.
mirrored lavender bags contain 1 light white bag, 4 light purple bags, 3 wavy lavender bags, 2 shiny lime bags.
pale turquoise bags contain 4 dark tan bags.
shiny salmon bags contain 1 shiny gold bag, 5 drab turquoise bags.
vibrant gray bags contain 3 posh brown bags.
dark indigo bags contain 1 mirrored black bag, 5 dull beige bags, 4 shiny beige bags, 3 drab lavender bags.
light teal bags contain 5 dark olive bags, 5 vibrant chartreuse bags, 3 plaid salmon bags, 5 light yellow bags.
clear violet bags contain 3 light crimson bags.
clear tan bags contain 3 striped orange bags, 4 wavy lavender bags, 3 striped silver bags.
clear bronze bags contain 2 plaid beige bags.
clear gray bags contain 4 dotted cyan bags, 4 vibrant plum bags.
drab cyan bags contain 1 light aqua bag, 1 drab teal bag, 3 bright orange bags, 3 dark white bags.
plaid beige bags contain 3 dull green bags.
wavy gold bags contain 4 shiny olive bags, 3 bright tan bags.
clear aqua bags contain 3 posh chartreuse bags, 4 drab silver bags, 5 clear gray bags.
bright chartreuse bags contain 2 light violet bags, 3 vibrant gray bags.
plaid black bags contain 2 posh gray bags.
light beige bags contain 4 dotted olive bags, 5 dull olive bags, 1 faded orange bag.
mirrored teal bags contain 4 mirrored aqua bags.
bright magenta bags contain 1 mirrored magenta bag, 3 bright blue bags, 1 vibrant blue bag, 2 drab gold bags.
dim maroon bags contain 4 light bronze bags, 5 clear violet bags.
light lime bags contain 4 plaid indigo bags.
posh lavender bags contain 4 dark brown bags.
clear beige bags contain 4 posh silver bags, 3 dull coral bags, 2 posh gray bags.
drab bronze bags contain 4 plaid maroon bags.
mirrored purple bags contain 3 dim magenta bags.
dark magenta bags contain 4 faded maroon bags, 1 drab crimson bag, 5 dotted brown bags, 2 bright teal bags.
dim brown bags contain 3 muted olive bags, 5 drab green bags, 1 mirrored olive bag.
dark plum bags contain 2 vibrant tan bags.
bright turquoise bags contain 1 mirrored aqua bag, 3 clear plum bags.
muted black bags contain 5 faded cyan bags, 5 pale tan bags, 2 dotted chartreuse bags.
dotted gray bags contain 3 posh plum bags.
vibrant black bags contain 2 vibrant magenta bags, 5 faded cyan bags.
mirrored cyan bags contain 2 clear cyan bags, 4 light aqua bags, 5 drab blue bags, 1 drab gold bag.
wavy purple bags contain 5 striped magenta bags, 3 clear maroon bags, 1 mirrored green bag, 1 pale black bag.
drab blue bags contain 3 mirrored lime bags, 1 mirrored blue bag.
clear maroon bags contain 5 bright orange bags.
shiny cyan bags contain 2 clear gray bags, 5 pale crimson bags.
pale cyan bags contain 2 wavy turquoise bags, 5 wavy salmon bags.
plaid gold bags contain 1 clear lavender bag, 1 bright beige bag.
mirrored lime bags contain 2 dull tan bags, 3 shiny beige bags.
drab green bags contain 1 vibrant yellow bag.
dull red bags contain 5 plaid blue bags, 5 clear brown bags, 3 pale salmon bags, 2 dark orange bags.
bright beige bags contain 4 dull silver bags, 5 vibrant brown bags, 4 drab red bags, 2 pale violet bags.
clear silver bags contain 4 drab indigo bags, 2 clear salmon bags.
posh bronze bags contain 5 bright indigo bags, 5 dotted purple bags, 1 dark violet bag, 2 dark orange bags.
posh salmon bags contain 5 bright red bags, 3 striped green bags, 3 dark brown bags.
clear cyan bags contain 5 dark chartreuse bags, 1 bright indigo bag, 4 pale yellow bags, 2 vibrant coral bags.
mirrored blue bags contain 2 vibrant white bags.
mirrored yellow bags contain 5 dotted gray bags, 4 dull maroon bags, 2 striped violet bags, 5 clear tomato bags.
striped teal bags contain 2 clear black bags, 3 pale coral bags.
faded orange bags contain 2 dark bronze bags.
mirrored indigo bags contain 3 light tomato bags, 2 shiny crimson bags.
pale green bags contain 4 light chartreuse bags.
plaid cyan bags contain 4 plaid fuchsia bags, 2 shiny teal bags, 3 dotted fuchsia bags, 3 dim red bags.
muted gold bags contain 2 dull tan bags, 1 faded bronze bag, 4 dull maroon bags.
wavy green bags contain 5 pale coral bags, 1 dull blue bag, 4 drab blue bags, 1 striped tan bag.
light chartreuse bags contain 4 striped brown bags, 5 plaid purple bags, 4 drab cyan bags, 3 dull plum bags.
dotted cyan bags contain 4 shiny black bags.
light purple bags contain no other bags.
dotted aqua bags contain 4 light gray bags, 2 light purple bags, 5 mirrored lime bags.
drab gold bags contain 2 bright green bags, 5 bright indigo bags.
posh gray bags contain 5 bright orange bags, 5 bright blue bags.
striped red bags contain 4 drab green bags, 1 clear cyan bag.
dotted bronze bags contain 5 light orange bags.
muted plum bags contain 2 bright black bags, 3 dotted tomato bags, 2 vibrant brown bags.
mirrored black bags contain 3 plaid chartreuse bags, 2 shiny indigo bags, 2 shiny beige bags.
drab lavender bags contain 5 drab cyan bags, 1 muted purple bag, 1 wavy red bag, 3 drab crimson bags.
vibrant turquoise bags contain 3 shiny beige bags, 3 striped brown bags, 5 dim teal bags.
muted tan bags contain 1 plaid purple bag, 3 shiny beige bags, 1 drab gold bag.
pale beige bags contain 5 bright silver bags.
wavy olive bags contain 4 dotted turquoise bags, 4 dull silver bags, 1 bright gold bag.
dim olive bags contain 5 light lavender bags, 4 shiny tomato bags, 4 clear cyan bags.
wavy salmon bags contain 4 bright aqua bags.
dotted gold bags contain 3 shiny red bags, 3 dull fuchsia bags.
shiny violet bags contain 3 dotted tomato bags, 1 drab coral bag.
striped plum bags contain 4 drab beige bags, 3 clear tan bags, 5 light aqua bags, 1 shiny fuchsia bag.
clear lavender bags contain 2 bright aqua bags, 3 dull silver bags, 3 bright green bags, 2 bright orange bags.
faded maroon bags contain 5 dark indigo bags, 1 posh fuchsia bag.
vibrant red bags contain 4 striped fuchsia bags, 3 drab orange bags, 1 clear brown bag, 1 plaid turquoise bag.
dull coral bags contain 2 dim teal bags, 3 faded bronze bags.
pale salmon bags contain 3 dull magenta bags, 1 light crimson bag.
dotted magenta bags contain 4 dull maroon bags, 2 bright lime bags, 4 plaid indigo bags, 4 faded cyan bags.
wavy gray bags contain 4 muted gray bags, 3 shiny magenta bags, 1 posh teal bag.
light red bags contain 4 shiny chartreuse bags.
dim blue bags contain 4 vibrant orange bags.
muted bronze bags contain 5 mirrored aqua bags, 4 dim green bags.
drab lime bags contain 1 drab cyan bag, 3 pale crimson bags, 4 bright green bags, 3 drab lavender bags.
light white bags contain 5 bright green bags.
bright teal bags contain 4 shiny brown bags, 4 dark silver bags.
striped beige bags contain 2 shiny magenta bags.
wavy magenta bags contain 5 pale bronze bags, 5 pale plum bags, 3 muted silver bags.
dark orange bags contain 1 drab tomato bag, 3 striped brown bags, 1 dim teal bag, 5 bright beige bags.
striped indigo bags contain 1 vibrant gold bag, 1 shiny green bag.
clear coral bags contain 2 shiny gray bags.
faded yellow bags contain 4 faded gold bags, 2 bright turquoise bags, 5 dark silver bags, 3 wavy coral bags.
dim plum bags contain 1 clear purple bag, 4 light brown bags.
mirrored turquoise bags contain 5 wavy indigo bags, 3 dark fuchsia bags, 5 plaid white bags, 2 dim turquoise bags.
posh black bags contain 2 striped black bags, 5 dim teal bags, 3 bright silver bags, 5 posh beige bags.
dotted fuchsia bags contain 1 faded turquoise bag, 2 shiny lavender bags, 4 posh salmon bags, 1 clear olive bag.
faded lavender bags contain 2 striped yellow bags, 1 posh lavender bag.
dim lime bags contain 2 wavy gray bags, 5 clear gray bags.
vibrant bronze bags contain 3 drab tomato bags, 5 bright tan bags.
dull plum bags contain 5 bright red bags, 4 dull magenta bags.
dim teal bags contain 4 light purple bags, 4 plaid lavender bags, 1 dull magenta bag.
dull yellow bags contain 4 vibrant orange bags, 1 dark tomato bag, 5 pale tan bags.
dull green bags contain 2 bright blue bags, 5 dull red bags.
light crimson bags contain 5 dull maroon bags, 4 muted gold bags.
dark black bags contain 1 dim silver bag, 3 plaid magenta bags.
bright lavender bags contain 4 muted fuchsia bags.
drab coral bags contain 4 shiny chartreuse bags, 3 posh yellow bags, 3 wavy indigo bags.
mirrored crimson bags contain 3 posh maroon bags, 5 striped olive bags, 3 mirrored magenta bags.
muted coral bags contain 3 wavy violet bags, 1 dotted chartreuse bag, 1 shiny beige bag.
vibrant gold bags contain 2 dull orange bags, 1 clear chartreuse bag.
wavy orange bags contain 5 dark bronze bags.
mirrored white bags contain 5 clear gold bags, 3 drab tomato bags, 4 dotted bronze bags, 3 striped orange bags.
clear gold bags contain 3 drab indigo bags, 4 wavy violet bags, 2 shiny salmon bags, 4 light brown bags.
shiny magenta bags contain 5 drab silver bags, 2 muted gold bags.
dim violet bags contain 1 posh lime bag, 4 shiny orange bags, 2 posh chartreuse bags.
striped olive bags contain 4 plaid indigo bags, 5 dim chartreuse bags, 4 clear lavender bags.
plaid gray bags contain 3 shiny gold bags, 2 dull coral bags.
clear crimson bags contain 4 shiny aqua bags, 3 light crimson bags, 5 dim chartreuse bags.
drab silver bags contain 1 dim teal bag, 3 faded cyan bags, 1 shiny indigo bag.
mirrored green bags contain 5 dotted lime bags, 4 pale cyan bags.
bright aqua bags contain no other bags.
bright plum bags contain 4 dim aqua bags, 2 dull crimson bags, 1 wavy maroon bag.
vibrant lavender bags contain 1 plaid tan bag, 3 vibrant brown bags, 3 drab gold bags, 4 faded red bags.
pale white bags contain 3 bright brown bags, 4 mirrored beige bags.
plaid lavender bags contain 1 dull magenta bag, 2 dull silver bags, 1 shiny indigo bag.
bright salmon bags contain 1 striped coral bag, 4 plaid lavender bags, 1 muted red bag, 1 drab red bag.
plaid olive bags contain 5 faded turquoise bags, 4 dim green bags, 2 striped beige bags.
wavy plum bags contain 1 clear lavender bag, 2 faded brown bags.
clear fuchsia bags contain 1 muted bronze bag.
wavy turquoise bags contain 5 shiny lime bags, 1 drab olive bag, 4 dim white bags, 1 dotted gray bag.
vibrant aqua bags contain 2 faded lavender bags.
dotted white bags contain 3 muted crimson bags, 5 mirrored white bags, 1 mirrored fuchsia bag.
bright purple bags contain 2 dotted chartreuse bags, 4 posh cyan bags, 3 bright plum bags.
light aqua bags contain 1 plaid lavender bag, 3 wavy coral bags, 5 shiny indigo bags.
drab yellow bags contain 4 shiny teal bags, 2 dotted green bags, 5 vibrant silver bags, 3 dotted turquoise bags.
mirrored olive bags contain 1 dull plum bag.
light olive bags contain 1 shiny coral bag, 4 drab white bags, 3 dim turquoise bags, 4 dull gold bags.
shiny indigo bags contain no other bags.
dull gold bags contain 3 dark indigo bags.
bright tomato bags contain 5 muted blue bags.
faded purple bags contain 4 bright orange bags, 2 faded violet bags.
drab magenta bags contain 3 wavy lavender bags, 2 drab cyan bags, 2 clear beige bags, 4 bright indigo bags.
striped lime bags contain 4 light tan bags.
light gold bags contain 2 pale plum bags.
striped black bags contain 1 plaid salmon bag, 2 plaid beige bags, 4 dotted teal bags, 2 posh chartreuse bags.
faded tomato bags contain 2 striped yellow bags, 4 muted red bags.
dull fuchsia bags contain 5 dotted olive bags, 2 muted purple bags.
pale purple bags contain 4 posh silver bags, 4 wavy yellow bags.
bright olive bags contain 5 shiny fuchsia bags, 5 dull crimson bags, 5 drab red bags, 5 posh turquoise bags.
vibrant fuchsia bags contain 1 vibrant beige bag, 5 shiny magenta bags.
faded turquoise bags contain 5 light lime bags, 4 dark white bags.
plaid orange bags contain 5 vibrant coral bags, 4 light crimson bags, 4 plaid chartreuse bags, 1 dull green bag.
posh indigo bags contain 3 wavy green bags, 2 shiny orange bags, 5 faded violet bags, 2 dotted coral bags.
mirrored red bags contain 4 mirrored olive bags, 1 dark silver bag, 1 dull red bag.
dim salmon bags contain 1 striped salmon bag, 5 faded gray bags.
dim cyan bags contain 3 wavy olive bags, 5 drab purple bags, 3 mirrored bronze bags.
light blue bags contain 2 striped bronze bags, 4 dull white bags, 1 posh bronze bag.
dull turquoise bags contain 4 striped red bags, 1 light lavender bag, 5 plaid bronze bags, 1 mirrored brown bag.
vibrant coral bags contain 1 bright orange bag.
striped cyan bags contain 2 dark white bags, 4 drab red bags, 2 plaid salmon bags.
muted tomato bags contain 4 drab red bags, 3 vibrant silver bags, 4 clear fuchsia bags, 3 wavy white bags.
dotted red bags contain 1 light blue bag.
dark beige bags contain 2 posh lime bags, 3 striped black bags.
dark cyan bags contain 1 dim chartreuse bag, 2 shiny beige bags, 4 dotted magenta bags, 4 light chartreuse bags.
dull lime bags contain 3 muted chartreuse bags.
light brown bags contain 3 mirrored brown bags.
vibrant magenta bags contain 1 dim green bag.
shiny brown bags contain 5 bright brown bags, 3 faded cyan bags, 5 clear tan bags, 2 plaid maroon bags.
drab purple bags contain 1 shiny indigo bag, 4 striped yellow bags.

66
2020/d07/ex2/ex2.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
import re
import sys
from collections import defaultdict
from copy import deepcopy
from dataclasses import dataclass
from typing import Dict, List, Set, Tuple
@dataclass(eq=True, frozen=True) # Hashable
class ColorInfo:
num: int
color: str
Graph = Dict[str, Set[ColorInfo]]
def extract_info(line: str) -> Tuple[str, Set[ColorInfo]]:
color_pattern = re.compile("(.*) contain ")
match = color_pattern.search(line)
assert match is not None
color = match.group(1).replace("bags", "bag")
line = line[match.end() : -1] # Remove period at end of line
if line == "no other bags":
return color, set()
colors: Set[ColorInfo] = set()
pattern = re.compile("([0-9]+) (.*)")
for col in line.split(", "):
match = pattern.search(col)
assert match is not None
colors |= {
ColorInfo(int(match.group(1)), match.group(2).replace("bags", "bag"))
}
return color, colors
def to_graph(raw: List[str]) -> Graph:
return {color: inside for color, inside in map(extract_info, raw)}
def num_bags(graph: Graph, col: str) -> int:
return sum(
contained.num * (1 + num_bags(graph, contained.color))
for contained in graph[col]
)
def solve(raw: List[str]) -> int:
graph = to_graph(raw)
return num_bags(graph, "shiny gold bag")
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

594
2020/d07/ex2/input Normal file
View file

@ -0,0 +1,594 @@
shiny aqua bags contain 1 dark white bag.
muted blue bags contain 1 vibrant lavender bag, 4 dotted silver bags, 2 dim indigo bags.
drab gray bags contain 5 mirrored white bags, 1 light green bag, 5 shiny lavender bags, 5 faded aqua bags.
muted indigo bags contain 4 muted chartreuse bags, 2 dotted teal bags.
drab white bags contain 2 dull fuchsia bags, 1 vibrant bronze bag.
dim lavender bags contain 4 muted tan bags.
dotted tomato bags contain 1 mirrored lime bag, 2 vibrant white bags.
clear orange bags contain 5 clear violet bags, 2 dull beige bags, 2 dark chartreuse bags.
bright lime bags contain no other bags.
striped brown bags contain 3 bright orange bags.
vibrant green bags contain 3 shiny fuchsia bags.
plaid tomato bags contain 3 faded chartreuse bags, 2 wavy salmon bags, 1 faded white bag, 3 mirrored maroon bags.
drab beige bags contain 2 shiny bronze bags, 4 pale violet bags, 3 bright tomato bags, 4 pale red bags.
posh green bags contain 2 dull lavender bags, 4 clear plum bags, 2 dark gray bags.
dull maroon bags contain 3 dull magenta bags, 1 dull tan bag, 1 faded cyan bag, 5 dull silver bags.
faded crimson bags contain 2 muted purple bags, 4 dotted olive bags, 5 drab silver bags.
wavy bronze bags contain 3 dark orange bags, 2 dark brown bags, 5 bright silver bags.
dark turquoise bags contain 5 dull plum bags.
dull lavender bags contain 4 dotted maroon bags, 3 muted brown bags, 4 drab black bags, 4 dull cyan bags.
dotted plum bags contain 1 shiny bronze bag, 3 clear brown bags, 3 muted indigo bags.
dull white bags contain 3 clear tan bags, 5 shiny gold bags, 2 drab crimson bags.
dull teal bags contain 2 bright tomato bags.
shiny crimson bags contain 3 light green bags, 5 striped brown bags, 3 faded fuchsia bags.
wavy brown bags contain 1 drab crimson bag, 2 wavy indigo bags.
dark tan bags contain 2 faded gray bags, 4 shiny salmon bags.
shiny red bags contain 4 dull chartreuse bags, 5 pale tomato bags.
bright orange bags contain no other bags.
wavy yellow bags contain 5 light indigo bags, 5 dark gray bags, 5 plaid indigo bags, 4 faded red bags.
faded bronze bags contain 4 faded cyan bags, 5 shiny beige bags, 5 muted red bags.
dull bronze bags contain 1 mirrored beige bag, 5 muted violet bags, 1 wavy lime bag.
dark lime bags contain 2 drab maroon bags, 5 bright indigo bags, 4 shiny black bags, 5 dotted turquoise bags.
drab red bags contain 5 bright red bags, 2 vibrant brown bags.
dotted salmon bags contain 3 vibrant turquoise bags, 2 dull beige bags, 3 light turquoise bags.
dull gray bags contain 3 striped green bags, 3 wavy coral bags, 1 dark gray bag, 2 light indigo bags.
faded black bags contain 4 muted fuchsia bags, 4 wavy coral bags, 1 drab tomato bag.
muted magenta bags contain 2 posh chartreuse bags, 4 pale violet bags.
light tan bags contain 2 posh turquoise bags, 3 vibrant white bags, 1 light black bag.
dark blue bags contain 3 plaid indigo bags, 2 posh black bags.
dull indigo bags contain 4 light gray bags, 3 dotted tan bags, 4 dull coral bags.
dim fuchsia bags contain 3 vibrant yellow bags, 3 mirrored cyan bags, 4 mirrored brown bags.
shiny beige bags contain 2 dull silver bags, 3 bright lime bags, 5 dull magenta bags.
light cyan bags contain 3 vibrant violet bags, 2 mirrored tomato bags, 2 vibrant coral bags, 4 mirrored silver bags.
clear turquoise bags contain 4 drab tomato bags, 3 shiny gold bags, 4 drab gold bags.
pale teal bags contain 2 wavy maroon bags, 2 dotted olive bags, 4 shiny white bags, 2 drab turquoise bags.
dark purple bags contain 1 wavy indigo bag, 3 bright black bags, 3 dotted teal bags.
bright white bags contain 5 wavy red bags, 2 mirrored cyan bags, 3 drab green bags.
mirrored aqua bags contain 1 faded violet bag, 5 dotted purple bags.
shiny lime bags contain 4 dark aqua bags.
pale bronze bags contain 1 clear crimson bag.
vibrant white bags contain 5 plaid lavender bags, 1 drab red bag, 4 vibrant brown bags.
plaid tan bags contain 5 dim crimson bags.
posh olive bags contain 3 bright red bags.
plaid brown bags contain 5 vibrant turquoise bags.
mirrored tomato bags contain 2 dotted chartreuse bags, 3 light aqua bags, 3 posh beige bags.
plaid blue bags contain 5 striped green bags, 1 plaid purple bag, 4 muted gold bags.
shiny tan bags contain 5 striped coral bags, 1 dull brown bag.
shiny gold bags contain 1 dull magenta bag, 5 dark white bags, 4 faded turquoise bags.
dull salmon bags contain 2 plaid gold bags, 2 light indigo bags.
striped tomato bags contain 2 striped tan bags, 4 light blue bags, 4 drab tan bags.
drab tomato bags contain 3 dim teal bags, 4 striped yellow bags, 3 bright red bags.
faded olive bags contain 1 drab plum bag, 1 pale aqua bag, 3 light blue bags.
dotted indigo bags contain 2 clear tomato bags.
dark white bags contain 5 light aqua bags, 2 dim teal bags, 2 muted fuchsia bags, 5 light purple bags.
dull orange bags contain 4 pale gold bags, 5 posh brown bags, 2 mirrored brown bags, 3 dark bronze bags.
bright maroon bags contain 1 mirrored yellow bag, 4 light teal bags.
bright silver bags contain 1 vibrant coral bag, 3 dim teal bags, 5 light purple bags.
muted olive bags contain 5 plaid orange bags, 1 muted magenta bag.
dull silver bags contain no other bags.
pale maroon bags contain 2 pale bronze bags.
light gray bags contain 4 vibrant yellow bags, 2 pale red bags.
drab teal bags contain 2 light crimson bags, 3 vibrant brown bags, 3 vibrant tan bags.
bright gold bags contain 1 wavy red bag, 5 wavy coral bags.
plaid chartreuse bags contain 2 dim coral bags, 4 drab silver bags, 5 dim chartreuse bags, 3 light purple bags.
clear blue bags contain 2 pale tomato bags, 4 dull gold bags, 4 dim fuchsia bags, 4 pale coral bags.
vibrant purple bags contain 5 faded orange bags.
plaid aqua bags contain 3 muted cyan bags, 2 wavy gray bags, 4 drab green bags, 4 pale beige bags.
muted lime bags contain 1 muted tan bag.
faded coral bags contain 3 drab turquoise bags, 1 shiny plum bag, 5 mirrored green bags, 5 clear white bags.
vibrant lime bags contain 5 posh coral bags.
faded green bags contain 3 pale orange bags, 5 dull turquoise bags, 1 mirrored crimson bag.
mirrored gray bags contain 5 dim indigo bags.
wavy maroon bags contain 4 mirrored bronze bags, 1 striped olive bag, 2 dull salmon bags, 3 shiny crimson bags.
dark violet bags contain 2 light purple bags.
dark green bags contain 2 dim cyan bags.
pale black bags contain 1 mirrored gold bag.
bright yellow bags contain 2 vibrant crimson bags, 3 plaid lime bags, 2 dotted gold bags.
muted teal bags contain 1 pale violet bag, 4 dull silver bags.
dim beige bags contain 5 wavy red bags.
muted purple bags contain 4 clear cyan bags.
plaid fuchsia bags contain 3 dark coral bags.
plaid bronze bags contain 5 plaid orange bags, 2 drab indigo bags.
faded indigo bags contain 1 dark chartreuse bag, 4 dull green bags, 1 mirrored magenta bag.
posh plum bags contain 3 dark chartreuse bags, 3 dotted turquoise bags, 4 dull maroon bags, 1 posh bronze bag.
pale gold bags contain 4 striped brown bags.
mirrored chartreuse bags contain 4 bright silver bags, 3 mirrored tomato bags, 4 wavy orange bags.
pale orange bags contain 2 posh fuchsia bags, 2 clear salmon bags, 2 bright green bags.
clear brown bags contain 4 light lime bags, 4 bright green bags, 5 pale yellow bags, 2 drab cyan bags.
shiny plum bags contain 5 vibrant gray bags, 3 bright blue bags, 5 dark tomato bags.
wavy white bags contain 4 plaid lime bags, 4 posh maroon bags, 5 drab lime bags, 1 vibrant crimson bag.
faded red bags contain 1 dull coral bag, 5 clear cyan bags, 4 plaid chartreuse bags, 3 plaid orange bags.
plaid red bags contain 5 pale blue bags, 4 light crimson bags, 3 faded fuchsia bags.
bright cyan bags contain 3 dark white bags, 2 light crimson bags, 1 bright aqua bag.
muted lavender bags contain 1 light green bag, 4 striped silver bags, 3 posh crimson bags.
wavy crimson bags contain 1 light purple bag, 4 bright blue bags, 2 dull coral bags, 1 wavy beige bag.
faded aqua bags contain 5 muted brown bags.
mirrored fuchsia bags contain 1 faded beige bag, 3 muted gold bags.
dark chartreuse bags contain 5 bright lime bags.
plaid green bags contain 4 mirrored tan bags, 1 mirrored tomato bag, 5 pale indigo bags, 1 mirrored plum bag.
shiny black bags contain 3 plaid chartreuse bags.
dotted purple bags contain 2 dim teal bags.
faded tan bags contain 2 bright fuchsia bags, 5 shiny fuchsia bags, 1 muted fuchsia bag, 1 mirrored brown bag.
drab brown bags contain 1 striped orange bag, 4 dotted tomato bags.
dull olive bags contain 1 striped black bag, 1 vibrant magenta bag.
mirrored plum bags contain 1 clear gold bag, 5 pale green bags.
dim tomato bags contain 4 drab gold bags, 2 shiny aqua bags.
light lavender bags contain 1 muted violet bag.
dim gray bags contain 3 light purple bags, 1 posh crimson bag, 1 faded brown bag.
muted aqua bags contain 4 dull beige bags, 4 dull red bags.
faded silver bags contain 1 mirrored cyan bag.
shiny green bags contain 5 dull maroon bags.
muted chartreuse bags contain 2 clear tan bags.
plaid plum bags contain 1 dotted lime bag, 4 clear brown bags, 4 dull red bags.
dotted silver bags contain 1 posh coral bag.
dim crimson bags contain 4 faded violet bags, 1 striped silver bag.
bright brown bags contain 1 bright coral bag, 3 posh brown bags, 4 drab tan bags.
wavy cyan bags contain 3 clear gold bags, 1 mirrored salmon bag, 3 bright fuchsia bags, 2 light bronze bags.
dull violet bags contain 5 striped white bags, 4 light blue bags, 4 dim black bags.
vibrant olive bags contain 2 vibrant coral bags.
bright coral bags contain 2 vibrant tan bags, 3 shiny indigo bags, 2 plaid indigo bags.
dim turquoise bags contain 1 pale violet bag.
striped crimson bags contain 2 faded gray bags.
clear green bags contain 3 mirrored olive bags, 3 shiny tomato bags.
faded violet bags contain 2 wavy coral bags, 2 dull tan bags, 1 dull silver bag, 1 bright orange bag.
pale chartreuse bags contain 4 shiny crimson bags, 2 clear bronze bags.
light plum bags contain 3 drab bronze bags, 1 bright bronze bag, 1 posh yellow bag.
pale tomato bags contain 1 dim teal bag, 5 drab cyan bags, 3 muted coral bags, 2 dim chartreuse bags.
plaid coral bags contain 1 striped tan bag, 3 vibrant cyan bags, 3 light beige bags, 2 dotted green bags.
bright gray bags contain 4 mirrored teal bags, 4 striped brown bags, 1 dim green bag, 4 clear cyan bags.
drab fuchsia bags contain 2 mirrored salmon bags, 4 posh orange bags, 3 faded crimson bags, 3 pale plum bags.
light tomato bags contain 2 dotted gold bags, 1 dotted bronze bag.
muted violet bags contain 2 light chartreuse bags.
drab tan bags contain 2 light green bags, 5 bright red bags, 4 shiny beige bags.
drab chartreuse bags contain 2 drab salmon bags, 2 dark brown bags, 4 clear turquoise bags.
drab violet bags contain 4 faded red bags.
posh cyan bags contain 4 bright violet bags.
posh orange bags contain 4 pale plum bags, 5 posh aqua bags.
plaid silver bags contain 1 dotted brown bag, 3 drab gold bags, 4 clear yellow bags.
mirrored silver bags contain 3 shiny beige bags, 1 drab silver bag.
faded gray bags contain no other bags.
wavy tomato bags contain 1 bright brown bag, 3 striped red bags, 2 vibrant maroon bags.
posh violet bags contain 2 dim aqua bags.
bright blue bags contain 5 light lime bags, 2 faded violet bags, 3 light aqua bags, 4 vibrant coral bags.
dark teal bags contain 5 muted fuchsia bags.
striped fuchsia bags contain 1 wavy turquoise bag, 5 wavy green bags, 4 posh gold bags.
posh maroon bags contain 2 dull red bags.
shiny purple bags contain 2 clear tan bags.
wavy lime bags contain 2 dark coral bags, 1 shiny gold bag.
wavy silver bags contain 4 dotted white bags.
shiny silver bags contain 2 plaid gold bags, 2 dim green bags, 5 plaid lime bags, 3 dull red bags.
wavy red bags contain 3 vibrant brown bags, 4 bright indigo bags.
dull chartreuse bags contain 4 dotted lime bags, 2 bright silver bags, 3 dull red bags, 4 wavy maroon bags.
vibrant silver bags contain 1 bright fuchsia bag, 3 drab lavender bags, 2 drab olive bags, 3 dotted teal bags.
striped gray bags contain 5 plaid orange bags, 1 wavy coral bag.
striped green bags contain 4 wavy coral bags, 4 shiny gold bags, 3 dark brown bags, 5 vibrant brown bags.
mirrored violet bags contain 3 dim silver bags, 1 posh tomato bag, 1 light salmon bag.
dull purple bags contain 1 light gray bag, 3 wavy yellow bags, 1 wavy salmon bag.
mirrored beige bags contain 4 dark cyan bags, 5 dull green bags.
posh lime bags contain 3 posh chartreuse bags.
vibrant tan bags contain 2 dull plum bags, 1 striped brown bag, 4 vibrant coral bags.
dotted orange bags contain 1 mirrored olive bag, 5 drab silver bags.
clear indigo bags contain 3 light lime bags, 4 dull coral bags.
pale gray bags contain 1 faded black bag, 3 dim green bags, 4 wavy lavender bags, 2 posh brown bags.
posh gold bags contain 5 dark tan bags, 2 dotted olive bags, 5 dark aqua bags.
striped chartreuse bags contain 2 dull magenta bags, 1 posh tomato bag.
mirrored bronze bags contain 2 faded fuchsia bags.
clear salmon bags contain 4 posh bronze bags, 5 clear plum bags, 5 dull blue bags.
posh purple bags contain 5 dim gray bags, 3 faded brown bags.
faded lime bags contain 5 dim turquoise bags, 3 dark indigo bags, 2 vibrant gray bags, 1 muted silver bag.
wavy beige bags contain 1 dark bronze bag, 4 dull plum bags, 4 mirrored silver bags.
clear yellow bags contain 2 vibrant teal bags.
vibrant plum bags contain 4 muted chartreuse bags, 4 posh silver bags.
striped yellow bags contain 2 dull maroon bags, 5 bright red bags, 2 posh chartreuse bags.
dark coral bags contain 3 dull tan bags.
dull magenta bags contain no other bags.
dark gold bags contain 1 dotted indigo bag, 4 shiny teal bags, 4 dotted silver bags.
dim tan bags contain 1 striped lavender bag, 1 shiny tomato bag.
muted maroon bags contain 2 dull salmon bags, 4 dim chartreuse bags, 3 bright aqua bags, 2 faded indigo bags.
vibrant tomato bags contain 2 dark silver bags, 3 plaid purple bags.
dotted lime bags contain 3 shiny crimson bags, 2 pale yellow bags.
muted fuchsia bags contain 1 dull tan bag.
bright tan bags contain 5 pale gold bags, 5 drab teal bags, 2 light blue bags.
dark crimson bags contain 4 shiny orange bags, 3 faded purple bags, 3 bright white bags.
striped tan bags contain 4 dotted turquoise bags, 4 drab lime bags, 5 dim teal bags.
posh fuchsia bags contain 2 dotted olive bags, 2 mirrored beige bags, 3 shiny bronze bags.
pale silver bags contain 4 vibrant lavender bags, 4 clear beige bags, 4 striped gold bags.
posh aqua bags contain 4 drab lime bags, 4 dull tan bags, 5 vibrant tan bags.
plaid salmon bags contain 5 dim coral bags, 2 wavy bronze bags.
mirrored orange bags contain 4 vibrant gray bags.
dim yellow bags contain 5 pale tan bags, 4 dark black bags.
dotted coral bags contain 4 dotted chartreuse bags, 2 bright red bags, 1 vibrant white bag, 1 vibrant brown bag.
muted crimson bags contain 4 striped orange bags, 5 pale yellow bags, 3 posh blue bags, 1 muted red bag.
striped lavender bags contain 3 striped brown bags.
striped maroon bags contain 2 shiny yellow bags.
vibrant blue bags contain 3 faded cyan bags, 1 shiny lime bag, 3 dark tomato bags.
pale lavender bags contain 4 plaid magenta bags, 4 striped blue bags.
dull tan bags contain 4 shiny indigo bags, 2 light purple bags, 4 faded cyan bags.
dotted beige bags contain 3 drab indigo bags.
light indigo bags contain 1 faded cyan bag, 5 bright aqua bags, 1 shiny indigo bag.
vibrant crimson bags contain 4 dotted fuchsia bags.
wavy blue bags contain 4 wavy teal bags, 1 dull blue bag.
vibrant chartreuse bags contain 4 striped orange bags.
vibrant cyan bags contain 5 wavy coral bags.
faded brown bags contain 5 faded turquoise bags.
faded magenta bags contain 1 dull indigo bag, 4 plaid aqua bags, 4 dim crimson bags.
mirrored coral bags contain 4 drab crimson bags, 2 light salmon bags, 2 clear indigo bags.
faded cyan bags contain no other bags.
dark brown bags contain 5 light purple bags.
wavy violet bags contain 3 dull coral bags, 1 bright aqua bag, 3 shiny lavender bags.
posh tomato bags contain 4 vibrant chartreuse bags, 4 mirrored teal bags.
pale crimson bags contain 1 plaid orange bag, 1 dark violet bag, 3 plaid lavender bags.
dark fuchsia bags contain 4 plaid beige bags, 2 plaid chartreuse bags.
plaid magenta bags contain 3 clear lavender bags, 5 mirrored brown bags, 5 shiny bronze bags.
striped blue bags contain 1 dull bronze bag, 1 dotted fuchsia bag, 1 light lavender bag, 1 clear turquoise bag.
dotted olive bags contain 4 dotted turquoise bags, 5 dotted bronze bags, 3 pale yellow bags, 4 pale red bags.
posh silver bags contain 3 pale violet bags, 1 plaid salmon bag, 1 posh coral bag.
dotted chartreuse bags contain 3 bright blue bags.
light coral bags contain 4 shiny fuchsia bags, 2 pale red bags, 1 muted silver bag, 2 bright cyan bags.
pale brown bags contain 5 light aqua bags.
dotted black bags contain 2 plaid purple bags, 1 mirrored aqua bag, 5 posh beige bags.
posh coral bags contain 3 dark aqua bags, 2 pale yellow bags, 5 plaid blue bags, 4 dim aqua bags.
shiny gray bags contain 1 bright gold bag, 1 muted bronze bag, 5 striped green bags, 5 shiny teal bags.
drab orange bags contain 5 plaid salmon bags, 2 vibrant beige bags.
plaid yellow bags contain 4 clear teal bags, 2 bright red bags.
striped violet bags contain 4 mirrored fuchsia bags, 4 vibrant white bags, 3 dim teal bags.
dim aqua bags contain 1 muted fuchsia bag, 1 dull tan bag.
light orange bags contain 2 bright red bags, 4 dark white bags, 1 dim chartreuse bag, 5 faded fuchsia bags.
faded salmon bags contain 5 wavy gray bags.
shiny yellow bags contain 2 vibrant plum bags, 3 dim teal bags, 1 plaid tan bag, 5 posh plum bags.
vibrant beige bags contain 2 wavy lavender bags, 4 posh chartreuse bags, 3 pale teal bags, 5 wavy lime bags.
light fuchsia bags contain 3 clear brown bags, 3 bright lavender bags.
pale magenta bags contain 4 posh silver bags.
dark maroon bags contain 3 drab turquoise bags.
faded beige bags contain 1 vibrant white bag, 4 drab red bags, 1 drab lavender bag.
bright bronze bags contain 1 pale bronze bag, 3 muted silver bags, 2 striped coral bags, 3 clear gray bags.
light silver bags contain 3 dotted lavender bags, 2 wavy lavender bags.
muted salmon bags contain 2 drab tan bags, 5 wavy tomato bags.
bright black bags contain 5 plaid tan bags.
dim chartreuse bags contain 5 muted gold bags, 5 bright blue bags, 5 faded cyan bags.
shiny white bags contain 4 bright tan bags.
bright red bags contain 3 dull silver bags.
dark aqua bags contain 2 dull red bags.
drab plum bags contain 4 muted brown bags, 5 muted plum bags.
muted yellow bags contain 5 light purple bags, 3 dotted silver bags, 3 faded turquoise bags.
light violet bags contain 1 pale red bag, 4 dim silver bags, 2 mirrored bronze bags.
pale lime bags contain 4 bright lavender bags.
pale tan bags contain 4 striped green bags, 2 dotted chartreuse bags.
dim green bags contain 1 light lime bag, 1 shiny beige bag.
mirrored gold bags contain 4 mirrored white bags.
dim silver bags contain 5 pale coral bags, 3 wavy coral bags.
dull aqua bags contain 3 posh indigo bags, 5 dotted coral bags, 1 dark salmon bag, 3 striped crimson bags.
posh yellow bags contain 1 dark bronze bag, 2 mirrored white bags, 2 light crimson bags.
mirrored magenta bags contain 1 bright violet bag, 2 drab lavender bags, 3 pale violet bags, 2 plaid salmon bags.
shiny chartreuse bags contain 2 dotted purple bags, 5 wavy red bags, 3 plaid beige bags.
light black bags contain 1 dark chartreuse bag, 3 faded tomato bags.
clear plum bags contain 5 vibrant brown bags, 3 dim coral bags, 4 mirrored brown bags, 1 faded black bag.
pale violet bags contain 2 dull tan bags.
bright fuchsia bags contain 4 dull orange bags.
dotted teal bags contain 5 bright red bags, 3 wavy red bags, 1 dull coral bag, 3 clear plum bags.
dotted blue bags contain 2 wavy beige bags, 3 muted purple bags.
muted gray bags contain 3 faded aqua bags, 1 shiny olive bag, 5 clear salmon bags, 1 vibrant violet bag.
dull beige bags contain 1 wavy lavender bag, 4 dark bronze bags, 5 dull tan bags.
drab turquoise bags contain 3 posh gray bags, 5 drab red bags.
vibrant yellow bags contain 2 shiny aqua bags, 4 light chartreuse bags.
posh brown bags contain 3 bright green bags, 5 posh lavender bags.
faded gold bags contain 4 vibrant maroon bags, 4 dotted purple bags.
dotted turquoise bags contain 5 clear plum bags, 3 muted gold bags, 4 dark violet bags.
dotted tan bags contain 5 dim aqua bags, 4 striped violet bags.
posh crimson bags contain 4 striped blue bags, 5 dull magenta bags, 2 bright coral bags.
muted white bags contain 5 dull olive bags.
vibrant teal bags contain 5 dotted turquoise bags, 1 striped tan bag, 1 drab tan bag.
dotted yellow bags contain 3 plaid turquoise bags, 2 posh yellow bags, 4 striped blue bags, 5 posh black bags.
posh magenta bags contain 5 mirrored black bags.
dotted green bags contain 4 dim crimson bags, 1 shiny lavender bag, 4 bright salmon bags, 1 plaid gray bag.
bright green bags contain 3 bright aqua bags, 3 dull maroon bags, 4 dark brown bags.
dark gray bags contain 5 muted purple bags, 2 striped blue bags, 4 faded lavender bags.
bright crimson bags contain 2 striped olive bags, 3 muted blue bags.
muted cyan bags contain 3 shiny tomato bags.
light yellow bags contain 2 striped red bags, 4 shiny crimson bags.
pale aqua bags contain 5 shiny yellow bags, 3 dark lavender bags, 3 posh white bags.
clear red bags contain 1 dotted silver bag, 1 dull teal bag, 1 faded maroon bag, 1 dotted salmon bag.
pale red bags contain 2 faded gray bags.
dotted maroon bags contain 5 posh aqua bags, 3 dull silver bags.
dull blue bags contain 4 light crimson bags, 3 light lime bags, 1 dark orange bag, 5 light indigo bags.
posh turquoise bags contain 1 muted gold bag, 5 striped lavender bags, 3 dull salmon bags, 5 vibrant chartreuse bags.
striped magenta bags contain 1 posh silver bag, 5 dark brown bags.
pale blue bags contain 2 muted gold bags, 4 vibrant brown bags, 1 light lavender bag.
vibrant violet bags contain 5 bright red bags.
faded fuchsia bags contain 2 light lime bags, 4 bright lime bags, 3 pale violet bags.
shiny coral bags contain 1 clear plum bag, 5 muted chartreuse bags, 1 muted violet bag, 5 striped yellow bags.
pale olive bags contain 4 plaid lime bags, 1 posh salmon bag.
wavy tan bags contain 3 faded gray bags.
faded chartreuse bags contain 3 dim coral bags, 1 mirrored bronze bag, 3 posh bronze bags.
mirrored brown bags contain 1 faded violet bag, 4 dull maroon bags, 5 dotted magenta bags.
clear white bags contain 5 muted magenta bags, 4 dull magenta bags, 3 pale plum bags, 4 drab indigo bags.
drab maroon bags contain 2 clear beige bags, 3 wavy beige bags, 5 faded purple bags.
striped silver bags contain 3 drab tomato bags.
faded plum bags contain 1 clear teal bag, 3 bright aqua bags.
plaid violet bags contain 2 drab violet bags, 4 muted turquoise bags, 5 muted indigo bags.
clear black bags contain 5 muted fuchsia bags, 1 muted coral bag, 2 light black bags.
vibrant maroon bags contain 1 dark lavender bag, 1 pale crimson bag, 4 bright indigo bags, 5 mirrored maroon bags.
drab indigo bags contain 2 dim coral bags, 1 drab green bag, 2 shiny lavender bags.
drab olive bags contain 2 dark aqua bags, 4 striped brown bags.
dull crimson bags contain 3 dull cyan bags.
wavy teal bags contain 4 striped orange bags, 2 drab cyan bags.
dark red bags contain 2 dull maroon bags, 4 muted plum bags, 4 dull plum bags.
striped salmon bags contain 3 bright red bags, 1 light aqua bag, 4 wavy gold bags.
mirrored tan bags contain 5 dotted olive bags, 2 dim tomato bags, 2 mirrored tomato bags, 4 clear teal bags.
striped white bags contain 2 pale coral bags, 2 shiny green bags.
shiny tomato bags contain 5 pale coral bags, 5 dull beige bags.
vibrant indigo bags contain 2 dim black bags, 4 dim blue bags, 3 dim white bags.
wavy lavender bags contain 4 faded bronze bags, 4 muted red bags, 3 light lime bags, 4 muted gold bags.
shiny turquoise bags contain 2 dull red bags, 5 faded gray bags, 1 muted turquoise bag.
shiny lavender bags contain 5 bright aqua bags.
posh tan bags contain 1 shiny yellow bag, 3 drab magenta bags.
light green bags contain 4 bright red bags, 1 vibrant coral bag.
drab black bags contain 5 faded tomato bags, 3 dotted chartreuse bags.
clear chartreuse bags contain 3 wavy bronze bags, 4 plaid purple bags, 3 dark orange bags.
dull black bags contain 1 wavy teal bag, 3 light lavender bags, 2 striped indigo bags.
wavy black bags contain 2 clear orange bags, 4 muted purple bags.
pale plum bags contain 1 bright coral bag, 1 drab tan bag, 1 plaid fuchsia bag, 1 dotted fuchsia bag.
dotted violet bags contain 3 bright black bags.
posh red bags contain 3 bright black bags.
plaid lime bags contain 5 posh beige bags, 1 dotted turquoise bag.
wavy aqua bags contain 1 dark yellow bag, 3 drab indigo bags.
dim magenta bags contain 3 dark violet bags.
drab aqua bags contain 5 posh orange bags, 1 dark silver bag, 4 plaid purple bags, 2 wavy teal bags.
dull brown bags contain 4 light lime bags.
striped orange bags contain 5 light crimson bags, 3 muted tan bags, 5 dotted coral bags, 3 plaid blue bags.
muted brown bags contain 1 posh blue bag, 4 dotted magenta bags, 3 dull coral bags.
faded blue bags contain 5 striped black bags, 1 vibrant yellow bag.
plaid indigo bags contain 3 dark brown bags, 5 light purple bags, 4 light aqua bags, 3 light green bags.
plaid turquoise bags contain 5 dotted teal bags.
light turquoise bags contain 2 dull salmon bags, 5 dotted tan bags.
dim purple bags contain 4 muted white bags, 5 drab purple bags.
pale coral bags contain 5 posh gray bags.
clear lime bags contain 3 dim magenta bags, 3 plaid tomato bags, 1 drab magenta bag, 3 shiny purple bags.
dim black bags contain 3 clear gold bags, 4 muted violet bags.
light maroon bags contain 4 muted yellow bags, 1 pale cyan bag, 2 mirrored turquoise bags, 4 dull lavender bags.
clear magenta bags contain 2 shiny magenta bags, 2 muted chartreuse bags.
striped bronze bags contain 5 clear tan bags, 1 drab lavender bag, 2 pale crimson bags.
dark salmon bags contain 1 vibrant plum bag, 5 drab tan bags, 4 drab coral bags, 4 dull tan bags.
vibrant salmon bags contain 2 muted olive bags.
dim gold bags contain 2 dim olive bags, 5 plaid olive bags, 2 posh orange bags.
wavy chartreuse bags contain 4 shiny yellow bags, 4 vibrant blue bags.
vibrant brown bags contain 3 striped brown bags, 4 muted red bags, 2 shiny indigo bags.
plaid maroon bags contain 2 muted teal bags, 2 pale yellow bags, 2 bright beige bags, 5 striped yellow bags.
dim indigo bags contain 4 dull tomato bags, 4 clear cyan bags, 2 shiny salmon bags, 1 bright aqua bag.
muted red bags contain 3 dull tan bags, 4 dull magenta bags, 1 bright aqua bag.
posh beige bags contain 5 shiny black bags, 3 dotted magenta bags, 3 drab blue bags, 2 muted coral bags.
pale fuchsia bags contain 3 dark brown bags, 5 posh gold bags.
dark bronze bags contain 1 dim green bag, 5 posh chartreuse bags.
dim coral bags contain 3 dull coral bags, 3 striped brown bags.
drab crimson bags contain 2 dark bronze bags, 4 shiny indigo bags, 3 dull tan bags.
bright indigo bags contain 3 bright blue bags.
pale yellow bags contain 5 dim aqua bags, 1 vibrant brown bag, 2 vibrant tan bags, 3 wavy lavender bags.
drab salmon bags contain 1 dotted indigo bag, 3 muted chartreuse bags, 5 dark olive bags.
muted orange bags contain 4 faded lime bags, 2 dull coral bags, 5 vibrant magenta bags, 4 dull magenta bags.
striped gold bags contain 2 dull silver bags, 5 bright lavender bags, 5 dim teal bags, 5 dark coral bags.
posh chartreuse bags contain 3 dim teal bags, 5 light aqua bags.
shiny blue bags contain 3 dull tan bags, 5 muted magenta bags.
muted silver bags contain 3 wavy blue bags, 2 dim teal bags, 5 muted bronze bags.
shiny bronze bags contain 1 light green bag, 4 vibrant magenta bags.
wavy coral bags contain no other bags.
shiny orange bags contain 2 muted purple bags.
posh teal bags contain 4 clear plum bags.
striped turquoise bags contain 3 muted indigo bags.
dim bronze bags contain 2 shiny silver bags, 1 light silver bag, 2 dim indigo bags, 4 dim tomato bags.
plaid white bags contain 4 drab turquoise bags.
wavy indigo bags contain 3 clear gold bags, 5 mirrored bronze bags.
faded teal bags contain 4 mirrored white bags.
shiny fuchsia bags contain 3 drab indigo bags.
dim red bags contain 3 clear bronze bags.
dotted brown bags contain 4 wavy maroon bags, 5 drab green bags, 3 dark purple bags.
dark tomato bags contain 3 vibrant coral bags, 5 dull coral bags, 2 drab cyan bags, 1 posh blue bag.
clear teal bags contain 3 dark white bags.
dark silver bags contain 3 dark cyan bags, 4 plaid salmon bags.
wavy fuchsia bags contain 4 bright brown bags, 4 bright aqua bags, 5 light orange bags.
light bronze bags contain 4 clear plum bags.
striped purple bags contain 1 dim indigo bag.
clear tomato bags contain 4 mirrored tomato bags, 3 muted indigo bags, 1 striped tan bag.
muted turquoise bags contain 5 faded beige bags, 4 clear crimson bags, 2 bright teal bags.
dull cyan bags contain 5 mirrored aqua bags, 2 shiny aqua bags, 3 light black bags, 4 bright coral bags.
plaid crimson bags contain 2 mirrored teal bags, 2 dull fuchsia bags.
shiny maroon bags contain 1 posh gold bag.
dim white bags contain 5 striped brown bags, 2 dull magenta bags, 5 plaid tan bags.
muted green bags contain 2 dull magenta bags, 5 clear cyan bags.
plaid teal bags contain 2 dark tan bags, 3 pale lime bags.
dotted lavender bags contain 2 posh aqua bags, 3 dull cyan bags.
light salmon bags contain 5 dark silver bags.
faded white bags contain 2 wavy maroon bags, 3 dull cyan bags.
dull tomato bags contain 2 dim aqua bags, 4 posh lavender bags, 1 faded red bag.
dark olive bags contain 5 clear bronze bags, 2 drab plum bags.
pale indigo bags contain 2 mirrored beige bags, 5 wavy turquoise bags, 4 striped green bags, 2 dotted lavender bags.
plaid purple bags contain 1 light lime bag.
clear purple bags contain 3 vibrant white bags.
dark yellow bags contain 2 pale olive bags, 4 pale cyan bags, 5 bright teal bags.
muted beige bags contain 2 posh lime bags, 5 shiny gray bags, 2 dull blue bags.
vibrant orange bags contain 5 posh crimson bags, 4 light chartreuse bags.
light magenta bags contain 2 plaid maroon bags, 1 posh beige bag, 5 pale salmon bags.
dotted crimson bags contain 5 dark chartreuse bags.
striped coral bags contain 2 dim aqua bags.
striped aqua bags contain 3 posh salmon bags, 3 dull red bags.
mirrored salmon bags contain 5 bright red bags, 2 light green bags, 3 clear black bags, 5 posh brown bags.
posh white bags contain 4 drab violet bags, 2 dotted silver bags.
posh blue bags contain 4 dull maroon bags, 3 vibrant coral bags.
dim orange bags contain 2 dull olive bags.
shiny teal bags contain 1 faded tomato bag, 4 muted violet bags.
mirrored maroon bags contain 3 dull blue bags.
dark lavender bags contain 1 drab red bag, 3 shiny indigo bags, 4 faded beige bags, 1 drab turquoise bag.
shiny olive bags contain 3 dark violet bags, 1 striped gold bag, 2 mirrored lime bags.
bright violet bags contain 2 wavy bronze bags, 3 drab olive bags, 5 mirrored olive bags, 2 wavy lavender bags.
clear olive bags contain 5 faded turquoise bags.
mirrored lavender bags contain 1 light white bag, 4 light purple bags, 3 wavy lavender bags, 2 shiny lime bags.
pale turquoise bags contain 4 dark tan bags.
shiny salmon bags contain 1 shiny gold bag, 5 drab turquoise bags.
vibrant gray bags contain 3 posh brown bags.
dark indigo bags contain 1 mirrored black bag, 5 dull beige bags, 4 shiny beige bags, 3 drab lavender bags.
light teal bags contain 5 dark olive bags, 5 vibrant chartreuse bags, 3 plaid salmon bags, 5 light yellow bags.
clear violet bags contain 3 light crimson bags.
clear tan bags contain 3 striped orange bags, 4 wavy lavender bags, 3 striped silver bags.
clear bronze bags contain 2 plaid beige bags.
clear gray bags contain 4 dotted cyan bags, 4 vibrant plum bags.
drab cyan bags contain 1 light aqua bag, 1 drab teal bag, 3 bright orange bags, 3 dark white bags.
plaid beige bags contain 3 dull green bags.
wavy gold bags contain 4 shiny olive bags, 3 bright tan bags.
clear aqua bags contain 3 posh chartreuse bags, 4 drab silver bags, 5 clear gray bags.
bright chartreuse bags contain 2 light violet bags, 3 vibrant gray bags.
plaid black bags contain 2 posh gray bags.
light beige bags contain 4 dotted olive bags, 5 dull olive bags, 1 faded orange bag.
mirrored teal bags contain 4 mirrored aqua bags.
bright magenta bags contain 1 mirrored magenta bag, 3 bright blue bags, 1 vibrant blue bag, 2 drab gold bags.
dim maroon bags contain 4 light bronze bags, 5 clear violet bags.
light lime bags contain 4 plaid indigo bags.
posh lavender bags contain 4 dark brown bags.
clear beige bags contain 4 posh silver bags, 3 dull coral bags, 2 posh gray bags.
drab bronze bags contain 4 plaid maroon bags.
mirrored purple bags contain 3 dim magenta bags.
dark magenta bags contain 4 faded maroon bags, 1 drab crimson bag, 5 dotted brown bags, 2 bright teal bags.
dim brown bags contain 3 muted olive bags, 5 drab green bags, 1 mirrored olive bag.
dark plum bags contain 2 vibrant tan bags.
bright turquoise bags contain 1 mirrored aqua bag, 3 clear plum bags.
muted black bags contain 5 faded cyan bags, 5 pale tan bags, 2 dotted chartreuse bags.
dotted gray bags contain 3 posh plum bags.
vibrant black bags contain 2 vibrant magenta bags, 5 faded cyan bags.
mirrored cyan bags contain 2 clear cyan bags, 4 light aqua bags, 5 drab blue bags, 1 drab gold bag.
wavy purple bags contain 5 striped magenta bags, 3 clear maroon bags, 1 mirrored green bag, 1 pale black bag.
drab blue bags contain 3 mirrored lime bags, 1 mirrored blue bag.
clear maroon bags contain 5 bright orange bags.
shiny cyan bags contain 2 clear gray bags, 5 pale crimson bags.
pale cyan bags contain 2 wavy turquoise bags, 5 wavy salmon bags.
plaid gold bags contain 1 clear lavender bag, 1 bright beige bag.
mirrored lime bags contain 2 dull tan bags, 3 shiny beige bags.
drab green bags contain 1 vibrant yellow bag.
dull red bags contain 5 plaid blue bags, 5 clear brown bags, 3 pale salmon bags, 2 dark orange bags.
bright beige bags contain 4 dull silver bags, 5 vibrant brown bags, 4 drab red bags, 2 pale violet bags.
clear silver bags contain 4 drab indigo bags, 2 clear salmon bags.
posh bronze bags contain 5 bright indigo bags, 5 dotted purple bags, 1 dark violet bag, 2 dark orange bags.
posh salmon bags contain 5 bright red bags, 3 striped green bags, 3 dark brown bags.
clear cyan bags contain 5 dark chartreuse bags, 1 bright indigo bag, 4 pale yellow bags, 2 vibrant coral bags.
mirrored blue bags contain 2 vibrant white bags.
mirrored yellow bags contain 5 dotted gray bags, 4 dull maroon bags, 2 striped violet bags, 5 clear tomato bags.
striped teal bags contain 2 clear black bags, 3 pale coral bags.
faded orange bags contain 2 dark bronze bags.
mirrored indigo bags contain 3 light tomato bags, 2 shiny crimson bags.
pale green bags contain 4 light chartreuse bags.
plaid cyan bags contain 4 plaid fuchsia bags, 2 shiny teal bags, 3 dotted fuchsia bags, 3 dim red bags.
muted gold bags contain 2 dull tan bags, 1 faded bronze bag, 4 dull maroon bags.
wavy green bags contain 5 pale coral bags, 1 dull blue bag, 4 drab blue bags, 1 striped tan bag.
light chartreuse bags contain 4 striped brown bags, 5 plaid purple bags, 4 drab cyan bags, 3 dull plum bags.
dotted cyan bags contain 4 shiny black bags.
light purple bags contain no other bags.
dotted aqua bags contain 4 light gray bags, 2 light purple bags, 5 mirrored lime bags.
drab gold bags contain 2 bright green bags, 5 bright indigo bags.
posh gray bags contain 5 bright orange bags, 5 bright blue bags.
striped red bags contain 4 drab green bags, 1 clear cyan bag.
dotted bronze bags contain 5 light orange bags.
muted plum bags contain 2 bright black bags, 3 dotted tomato bags, 2 vibrant brown bags.
mirrored black bags contain 3 plaid chartreuse bags, 2 shiny indigo bags, 2 shiny beige bags.
drab lavender bags contain 5 drab cyan bags, 1 muted purple bag, 1 wavy red bag, 3 drab crimson bags.
vibrant turquoise bags contain 3 shiny beige bags, 3 striped brown bags, 5 dim teal bags.
muted tan bags contain 1 plaid purple bag, 3 shiny beige bags, 1 drab gold bag.
pale beige bags contain 5 bright silver bags.
wavy olive bags contain 4 dotted turquoise bags, 4 dull silver bags, 1 bright gold bag.
dim olive bags contain 5 light lavender bags, 4 shiny tomato bags, 4 clear cyan bags.
wavy salmon bags contain 4 bright aqua bags.
dotted gold bags contain 3 shiny red bags, 3 dull fuchsia bags.
shiny violet bags contain 3 dotted tomato bags, 1 drab coral bag.
striped plum bags contain 4 drab beige bags, 3 clear tan bags, 5 light aqua bags, 1 shiny fuchsia bag.
clear lavender bags contain 2 bright aqua bags, 3 dull silver bags, 3 bright green bags, 2 bright orange bags.
faded maroon bags contain 5 dark indigo bags, 1 posh fuchsia bag.
vibrant red bags contain 4 striped fuchsia bags, 3 drab orange bags, 1 clear brown bag, 1 plaid turquoise bag.
dull coral bags contain 2 dim teal bags, 3 faded bronze bags.
pale salmon bags contain 3 dull magenta bags, 1 light crimson bag.
dotted magenta bags contain 4 dull maroon bags, 2 bright lime bags, 4 plaid indigo bags, 4 faded cyan bags.
wavy gray bags contain 4 muted gray bags, 3 shiny magenta bags, 1 posh teal bag.
light red bags contain 4 shiny chartreuse bags.
dim blue bags contain 4 vibrant orange bags.
muted bronze bags contain 5 mirrored aqua bags, 4 dim green bags.
drab lime bags contain 1 drab cyan bag, 3 pale crimson bags, 4 bright green bags, 3 drab lavender bags.
light white bags contain 5 bright green bags.
bright teal bags contain 4 shiny brown bags, 4 dark silver bags.
striped beige bags contain 2 shiny magenta bags.
wavy magenta bags contain 5 pale bronze bags, 5 pale plum bags, 3 muted silver bags.
dark orange bags contain 1 drab tomato bag, 3 striped brown bags, 1 dim teal bag, 5 bright beige bags.
striped indigo bags contain 1 vibrant gold bag, 1 shiny green bag.
clear coral bags contain 2 shiny gray bags.
faded yellow bags contain 4 faded gold bags, 2 bright turquoise bags, 5 dark silver bags, 3 wavy coral bags.
dim plum bags contain 1 clear purple bag, 4 light brown bags.
mirrored turquoise bags contain 5 wavy indigo bags, 3 dark fuchsia bags, 5 plaid white bags, 2 dim turquoise bags.
posh black bags contain 2 striped black bags, 5 dim teal bags, 3 bright silver bags, 5 posh beige bags.
dotted fuchsia bags contain 1 faded turquoise bag, 2 shiny lavender bags, 4 posh salmon bags, 1 clear olive bag.
faded lavender bags contain 2 striped yellow bags, 1 posh lavender bag.
dim lime bags contain 2 wavy gray bags, 5 clear gray bags.
vibrant bronze bags contain 3 drab tomato bags, 5 bright tan bags.
dull plum bags contain 5 bright red bags, 4 dull magenta bags.
dim teal bags contain 4 light purple bags, 4 plaid lavender bags, 1 dull magenta bag.
dull yellow bags contain 4 vibrant orange bags, 1 dark tomato bag, 5 pale tan bags.
dull green bags contain 2 bright blue bags, 5 dull red bags.
light crimson bags contain 5 dull maroon bags, 4 muted gold bags.
dark black bags contain 1 dim silver bag, 3 plaid magenta bags.
bright lavender bags contain 4 muted fuchsia bags.
drab coral bags contain 4 shiny chartreuse bags, 3 posh yellow bags, 3 wavy indigo bags.
mirrored crimson bags contain 3 posh maroon bags, 5 striped olive bags, 3 mirrored magenta bags.
muted coral bags contain 3 wavy violet bags, 1 dotted chartreuse bag, 1 shiny beige bag.
vibrant gold bags contain 2 dull orange bags, 1 clear chartreuse bag.
wavy orange bags contain 5 dark bronze bags.
mirrored white bags contain 5 clear gold bags, 3 drab tomato bags, 4 dotted bronze bags, 3 striped orange bags.
clear gold bags contain 3 drab indigo bags, 4 wavy violet bags, 2 shiny salmon bags, 4 light brown bags.
shiny magenta bags contain 5 drab silver bags, 2 muted gold bags.
dim violet bags contain 1 posh lime bag, 4 shiny orange bags, 2 posh chartreuse bags.
striped olive bags contain 4 plaid indigo bags, 5 dim chartreuse bags, 4 clear lavender bags.
plaid gray bags contain 3 shiny gold bags, 2 dull coral bags.
clear crimson bags contain 4 shiny aqua bags, 3 light crimson bags, 5 dim chartreuse bags.
drab silver bags contain 1 dim teal bag, 3 faded cyan bags, 1 shiny indigo bag.
mirrored green bags contain 5 dotted lime bags, 4 pale cyan bags.
bright aqua bags contain no other bags.
bright plum bags contain 4 dim aqua bags, 2 dull crimson bags, 1 wavy maroon bag.
vibrant lavender bags contain 1 plaid tan bag, 3 vibrant brown bags, 3 drab gold bags, 4 faded red bags.
pale white bags contain 3 bright brown bags, 4 mirrored beige bags.
plaid lavender bags contain 1 dull magenta bag, 2 dull silver bags, 1 shiny indigo bag.
bright salmon bags contain 1 striped coral bag, 4 plaid lavender bags, 1 muted red bag, 1 drab red bag.
plaid olive bags contain 5 faded turquoise bags, 4 dim green bags, 2 striped beige bags.
wavy plum bags contain 1 clear lavender bag, 2 faded brown bags.
clear fuchsia bags contain 1 muted bronze bag.
wavy turquoise bags contain 5 shiny lime bags, 1 drab olive bag, 4 dim white bags, 1 dotted gray bag.
vibrant aqua bags contain 2 faded lavender bags.
dotted white bags contain 3 muted crimson bags, 5 mirrored white bags, 1 mirrored fuchsia bag.
bright purple bags contain 2 dotted chartreuse bags, 4 posh cyan bags, 3 bright plum bags.
light aqua bags contain 1 plaid lavender bag, 3 wavy coral bags, 5 shiny indigo bags.
drab yellow bags contain 4 shiny teal bags, 2 dotted green bags, 5 vibrant silver bags, 3 dotted turquoise bags.
mirrored olive bags contain 1 dull plum bag.
light olive bags contain 1 shiny coral bag, 4 drab white bags, 3 dim turquoise bags, 4 dull gold bags.
shiny indigo bags contain no other bags.
dull gold bags contain 3 dark indigo bags.
bright tomato bags contain 5 muted blue bags.
faded purple bags contain 4 bright orange bags, 2 faded violet bags.
drab magenta bags contain 3 wavy lavender bags, 2 drab cyan bags, 2 clear beige bags, 4 bright indigo bags.
striped lime bags contain 4 light tan bags.
light gold bags contain 2 pale plum bags.
striped black bags contain 1 plaid salmon bag, 2 plaid beige bags, 4 dotted teal bags, 2 posh chartreuse bags.
faded tomato bags contain 2 striped yellow bags, 4 muted red bags.
dull fuchsia bags contain 5 dotted olive bags, 2 muted purple bags.
pale purple bags contain 4 posh silver bags, 4 wavy yellow bags.
bright olive bags contain 5 shiny fuchsia bags, 5 dull crimson bags, 5 drab red bags, 5 posh turquoise bags.
vibrant fuchsia bags contain 1 vibrant beige bag, 5 shiny magenta bags.
faded turquoise bags contain 5 light lime bags, 4 dark white bags.
plaid orange bags contain 5 vibrant coral bags, 4 light crimson bags, 4 plaid chartreuse bags, 1 dull green bag.
posh indigo bags contain 3 wavy green bags, 2 shiny orange bags, 5 faded violet bags, 2 dotted coral bags.
mirrored red bags contain 4 mirrored olive bags, 1 dark silver bag, 1 dull red bag.
dim salmon bags contain 1 striped salmon bag, 5 faded gray bags.
dim cyan bags contain 3 wavy olive bags, 5 drab purple bags, 3 mirrored bronze bags.
light blue bags contain 2 striped bronze bags, 4 dull white bags, 1 posh bronze bag.
dull turquoise bags contain 4 striped red bags, 1 light lavender bag, 5 plaid bronze bags, 1 mirrored brown bag.
vibrant coral bags contain 1 bright orange bag.
striped cyan bags contain 2 dark white bags, 4 drab red bags, 2 plaid salmon bags.
muted tomato bags contain 4 drab red bags, 3 vibrant silver bags, 4 clear fuchsia bags, 3 wavy white bags.
dotted red bags contain 1 light blue bag.
dark beige bags contain 2 posh lime bags, 3 striped black bags.
dark cyan bags contain 1 dim chartreuse bag, 2 shiny beige bags, 4 dotted magenta bags, 4 light chartreuse bags.
dull lime bags contain 3 muted chartreuse bags.
light brown bags contain 3 mirrored brown bags.
vibrant magenta bags contain 1 dim green bag.
shiny brown bags contain 5 bright brown bags, 3 faded cyan bags, 5 clear tan bags, 2 plaid maroon bags.
drab purple bags contain 1 shiny indigo bag, 4 striped yellow bags.

51
2020/d08/ex1/ex1.py Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env python
import sys
from typing import List, Tuple
def run(code: List[Tuple[str, int]]) -> int:
accumulator = 0
rip = 0
def acc(val: int) -> None:
nonlocal accumulator
nonlocal rip
accumulator += val
rip += 1
def nop(val: int) -> None:
nonlocal rip
rip += 1
def jmp(val: int) -> None:
nonlocal rip
rip += val
instrs = {
"acc": acc,
"jmp": jmp,
"nop": nop,
}
seen = set()
while rip not in seen:
seen |= {rip}
func = instrs[code[rip][0]]
func(code[rip][1])
return accumulator
def solve(raw: List[str]) -> int:
return run([(line[:3], int(line[3:])) for line in raw])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

675
2020/d08/ex1/input Normal file
View file

@ -0,0 +1,675 @@
acc -8
jmp +5
acc +0
acc +44
acc +42
jmp +324
acc -17
jmp +1
acc -17
jmp +51
acc -13
acc +4
jmp +1
nop +608
jmp +274
acc -17
jmp +169
acc +28
nop +508
jmp +1
jmp +570
acc +22
acc -14
jmp +377
acc -13
acc +27
jmp +474
acc -5
jmp +1
acc +12
jmp +37
jmp +184
acc +36
acc +32
acc -8
jmp +465
acc -13
acc +18
jmp +169
acc +20
acc +26
acc +23
jmp +333
jmp +584
acc +9
acc +28
acc +28
nop +571
jmp +143
acc +39
acc +39
acc -16
jmp +361
acc +48
acc +3
acc +15
nop +4
jmp +504
acc +6
jmp +285
acc +26
acc +33
jmp +1
acc +36
jmp +577
acc +36
jmp +6
nop +498
acc +42
jmp +496
acc +10
jmp +74
acc +17
acc +16
acc +30
jmp +254
acc -3
acc +16
acc -2
nop +106
jmp +541
acc -15
jmp +579
jmp +165
acc +22
acc -6
acc +29
acc -19
jmp +342
acc -19
jmp +340
acc +13
acc +25
acc +29
jmp +269
acc -14
acc +27
acc +41
acc +49
jmp +181
nop +350
jmp +1
nop +437
acc +34
jmp +494
acc +19
acc +2
acc +44
jmp +558
acc +10
jmp +44
nop +4
nop -80
nop +540
jmp +16
acc +28
jmp +14
acc +13
nop +399
acc +29
nop -60
jmp -6
acc +41
acc +30
jmp +232
acc +28
nop +495
acc +15
acc +48
jmp +157
nop +483
jmp -59
acc +5
acc +30
acc +30
acc +2
jmp +349
acc +11
acc +27
acc +1
jmp +367
acc +8
acc +45
acc +11
jmp +171
jmp -113
acc +48
jmp -38
acc +12
jmp +145
acc +8
nop +29
nop +319
jmp +154
nop +166
jmp +395
nop +15
jmp +237
acc +22
acc +3
acc +42
acc +1
jmp +288
jmp -63
nop +489
acc +33
jmp +247
jmp +1
acc -8
acc +9
jmp +413
acc -17
acc +3
acc +3
jmp +432
nop -17
acc +36
nop +198
acc +45
jmp +109
nop +242
acc +40
acc +11
jmp +448
jmp +437
acc +3
acc +49
acc +27
jmp +221
nop +158
jmp +143
acc +50
jmp -70
acc +46
acc +8
acc +35
acc -3
jmp +104
acc +11
acc +0
jmp +34
nop +132
jmp +425
jmp +219
acc -12
acc +48
jmp +21
jmp +434
acc +30
acc +1
acc +40
jmp +435
jmp +132
acc +40
jmp +236
jmp +179
jmp -149
acc +25
acc +40
acc -9
acc +49
jmp +445
nop +399
acc -14
nop +374
acc +0
jmp +152
acc +39
nop +322
acc +49
nop +117
jmp -19
acc +24
jmp +385
acc +17
acc +39
acc +44
acc -8
jmp -58
acc -18
nop -76
jmp +66
acc +14
jmp +427
acc +11
acc +47
acc +9
jmp +1
acc +42
jmp -7
acc -16
acc -13
jmp +409
acc +1
acc +35
acc +34
jmp +371
acc +24
acc +46
acc -4
jmp +367
acc +19
acc +27
acc -8
acc +41
jmp -184
nop -185
acc +23
acc -8
acc +35
jmp -9
acc -7
nop -101
nop +121
acc +37
jmp -72
acc +24
jmp +1
nop -124
jmp +163
acc +37
acc -12
jmp +331
acc -12
acc +1
jmp +232
jmp -233
jmp -72
acc +28
jmp +169
acc +43
acc +18
nop +108
jmp -184
acc -4
acc -10
nop +317
acc +48
jmp +173
nop +45
jmp -73
acc +35
jmp +198
acc -15
acc +46
acc +31
jmp +41
nop +169
jmp +1
nop -92
nop -271
jmp -113
jmp +1
nop -42
jmp +42
nop -283
acc +22
nop +200
jmp -17
jmp +1
acc +49
nop +35
nop -185
jmp +298
acc +1
jmp +1
nop +301
acc +19
jmp -34
jmp +163
jmp +1
acc +49
jmp -115
jmp -62
acc +8
acc +5
acc -6
jmp -146
acc -4
nop -202
acc +47
jmp -114
acc +8
jmp +57
acc +37
jmp +61
jmp +267
acc +2
acc +28
nop -20
jmp -186
acc +24
nop +269
acc +48
acc +45
jmp -22
acc +11
acc +36
jmp -267
acc +7
nop -45
nop -231
jmp +32
nop +220
acc +19
jmp -250
acc +33
jmp -169
acc +45
acc -13
acc +0
acc +44
jmp +6
acc +42
jmp +84
acc +48
jmp -332
jmp +213
acc -16
acc +31
acc +17
acc +3
jmp -75
jmp +1
acc +11
acc +4
jmp -271
acc -12
nop +97
nop +11
jmp -43
acc +30
jmp +1
jmp +49
jmp -379
nop -51
acc +0
acc -8
nop -191
jmp -346
jmp -255
acc +2
acc +21
acc -16
nop +217
jmp -30
acc +31
jmp -270
jmp -324
jmp +130
acc +49
nop +179
jmp -37
acc +11
acc +15
acc +29
acc +17
jmp -237
acc +47
acc -13
acc +6
jmp +169
nop +54
acc -12
jmp -233
nop +33
acc +17
acc +14
acc +21
jmp -275
acc -8
acc +1
nop +229
jmp +1
jmp +119
jmp -193
nop +217
jmp +95
acc -2
acc +1
acc +41
jmp -332
acc +44
nop -343
acc +23
jmp -165
acc +7
acc -12
nop -339
jmp +9
nop -390
acc -17
acc +43
jmp -138
nop -247
acc +42
acc +0
jmp +170
acc +48
jmp -139
acc +6
acc +13
acc +35
jmp -85
nop -117
jmp -307
acc +25
acc -10
acc -14
acc +0
jmp -355
jmp +102
acc -8
acc +47
acc +36
jmp +42
acc +33
acc +17
acc +46
jmp -331
jmp +1
acc -11
jmp +1
acc +27
jmp +147
acc -14
nop -28
acc +32
jmp -482
acc +11
nop -390
jmp -485
acc -12
acc +37
acc +33
acc +28
jmp -32
acc +42
acc -11
jmp -460
acc +36
acc +6
acc +39
jmp +80
nop +123
acc -13
jmp -97
acc +25
acc +46
acc +13
nop -450
jmp +84
acc +3
nop -260
jmp +1
acc +22
jmp -510
acc -4
acc +17
acc -19
jmp -420
acc -14
acc +26
acc +29
acc +17
jmp -458
acc -10
acc +23
nop -2
jmp -196
acc -5
jmp -416
acc +49
jmp -165
acc +4
acc +7
acc +20
nop -217
jmp +103
jmp +5
acc -1
acc +2
jmp +1
jmp +84
acc -14
jmp -518
jmp +1
acc +30
acc +21
jmp -202
nop -18
jmp -344
jmp -88
nop -472
acc -5
acc +13
jmp -295
nop -315
acc +41
nop -317
jmp -299
nop +105
jmp -86
acc +7
jmp -226
nop -277
acc +21
acc +13
acc +47
jmp -283
acc -11
acc -1
jmp -408
acc +47
nop -553
acc +37
acc -11
jmp -468
acc +43
nop -299
acc +40
acc +2
jmp -275
acc +24
acc -14
acc +13
acc +36
jmp -249
acc +35
jmp -45
acc +47
acc +31
acc -19
jmp -151
jmp -33
acc +6
jmp -160
jmp -553
acc +25
jmp +1
nop -267
jmp -430
acc +23
nop +63
acc +37
jmp -434
nop -579
jmp +11
acc +25
acc -17
acc +22
acc +27
jmp +15
jmp -546
acc -4
acc +41
acc +0
jmp -261
acc +20
jmp -404
jmp -408
acc +26
jmp -464
acc +34
nop -80
acc -12
jmp -43
jmp -410
acc -13
acc -3
jmp -310
nop -433
acc -7
acc -11
acc +9
jmp -29
nop -564
acc -5
acc -16
acc +36
jmp -587
jmp -115
acc +24
acc +35
nop -638
jmp -573
acc +31
acc +14
jmp -609
acc +25
acc -10
acc +18
jmp -308
acc +25
acc +33
acc +21
acc -12
jmp -172
nop -37
acc +12
jmp -316
acc +41
acc +14
jmp -415
acc +40
jmp -112
jmp -613
acc +26
nop -151
jmp -471
acc +50
acc +16
nop -119
acc +46
jmp +1

62
2020/d08/ex2/ex2.py Executable file
View file

@ -0,0 +1,62 @@
#!/usr/bin/env python
import sys
from copy import deepcopy
from typing import List, Tuple
def run(code: List[Tuple[str, int]]) -> Tuple[int, bool]:
accumulator = 0
rip = 0
def acc(val: int) -> None:
nonlocal accumulator
nonlocal rip
accumulator += val
rip += 1
def nop(val: int) -> None:
nonlocal rip
rip += 1
def jmp(val: int) -> None:
nonlocal rip
rip += val
instrs = {
"acc": acc,
"jmp": jmp,
"nop": nop,
}
seen = set()
while rip not in seen and rip < len(code):
seen |= {rip}
func = instrs[code[rip][0]]
func(code[rip][1])
return accumulator, rip == len(code)
def solve(raw: List[str]) -> int:
code = [(line[:3], int(line[3:])) for line in raw]
lut = {"jmp": "nop", "nop": "jmp"}
for i in range(len(code)):
if code[i][0] not in lut:
continue
new_code = deepcopy(code)
new_code[i] = lut[new_code[i][0]], new_code[i][1]
val, halted = run(new_code)
if halted:
return val
assert False # Sanity check
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

675
2020/d08/ex2/input Normal file
View file

@ -0,0 +1,675 @@
acc -8
jmp +5
acc +0
acc +44
acc +42
jmp +324
acc -17
jmp +1
acc -17
jmp +51
acc -13
acc +4
jmp +1
nop +608
jmp +274
acc -17
jmp +169
acc +28
nop +508
jmp +1
jmp +570
acc +22
acc -14
jmp +377
acc -13
acc +27
jmp +474
acc -5
jmp +1
acc +12
jmp +37
jmp +184
acc +36
acc +32
acc -8
jmp +465
acc -13
acc +18
jmp +169
acc +20
acc +26
acc +23
jmp +333
jmp +584
acc +9
acc +28
acc +28
nop +571
jmp +143
acc +39
acc +39
acc -16
jmp +361
acc +48
acc +3
acc +15
nop +4
jmp +504
acc +6
jmp +285
acc +26
acc +33
jmp +1
acc +36
jmp +577
acc +36
jmp +6
nop +498
acc +42
jmp +496
acc +10
jmp +74
acc +17
acc +16
acc +30
jmp +254
acc -3
acc +16
acc -2
nop +106
jmp +541
acc -15
jmp +579
jmp +165
acc +22
acc -6
acc +29
acc -19
jmp +342
acc -19
jmp +340
acc +13
acc +25
acc +29
jmp +269
acc -14
acc +27
acc +41
acc +49
jmp +181
nop +350
jmp +1
nop +437
acc +34
jmp +494
acc +19
acc +2
acc +44
jmp +558
acc +10
jmp +44
nop +4
nop -80
nop +540
jmp +16
acc +28
jmp +14
acc +13
nop +399
acc +29
nop -60
jmp -6
acc +41
acc +30
jmp +232
acc +28
nop +495
acc +15
acc +48
jmp +157
nop +483
jmp -59
acc +5
acc +30
acc +30
acc +2
jmp +349
acc +11
acc +27
acc +1
jmp +367
acc +8
acc +45
acc +11
jmp +171
jmp -113
acc +48
jmp -38
acc +12
jmp +145
acc +8
nop +29
nop +319
jmp +154
nop +166
jmp +395
nop +15
jmp +237
acc +22
acc +3
acc +42
acc +1
jmp +288
jmp -63
nop +489
acc +33
jmp +247
jmp +1
acc -8
acc +9
jmp +413
acc -17
acc +3
acc +3
jmp +432
nop -17
acc +36
nop +198
acc +45
jmp +109
nop +242
acc +40
acc +11
jmp +448
jmp +437
acc +3
acc +49
acc +27
jmp +221
nop +158
jmp +143
acc +50
jmp -70
acc +46
acc +8
acc +35
acc -3
jmp +104
acc +11
acc +0
jmp +34
nop +132
jmp +425
jmp +219
acc -12
acc +48
jmp +21
jmp +434
acc +30
acc +1
acc +40
jmp +435
jmp +132
acc +40
jmp +236
jmp +179
jmp -149
acc +25
acc +40
acc -9
acc +49
jmp +445
nop +399
acc -14
nop +374
acc +0
jmp +152
acc +39
nop +322
acc +49
nop +117
jmp -19
acc +24
jmp +385
acc +17
acc +39
acc +44
acc -8
jmp -58
acc -18
nop -76
jmp +66
acc +14
jmp +427
acc +11
acc +47
acc +9
jmp +1
acc +42
jmp -7
acc -16
acc -13
jmp +409
acc +1
acc +35
acc +34
jmp +371
acc +24
acc +46
acc -4
jmp +367
acc +19
acc +27
acc -8
acc +41
jmp -184
nop -185
acc +23
acc -8
acc +35
jmp -9
acc -7
nop -101
nop +121
acc +37
jmp -72
acc +24
jmp +1
nop -124
jmp +163
acc +37
acc -12
jmp +331
acc -12
acc +1
jmp +232
jmp -233
jmp -72
acc +28
jmp +169
acc +43
acc +18
nop +108
jmp -184
acc -4
acc -10
nop +317
acc +48
jmp +173
nop +45
jmp -73
acc +35
jmp +198
acc -15
acc +46
acc +31
jmp +41
nop +169
jmp +1
nop -92
nop -271
jmp -113
jmp +1
nop -42
jmp +42
nop -283
acc +22
nop +200
jmp -17
jmp +1
acc +49
nop +35
nop -185
jmp +298
acc +1
jmp +1
nop +301
acc +19
jmp -34
jmp +163
jmp +1
acc +49
jmp -115
jmp -62
acc +8
acc +5
acc -6
jmp -146
acc -4
nop -202
acc +47
jmp -114
acc +8
jmp +57
acc +37
jmp +61
jmp +267
acc +2
acc +28
nop -20
jmp -186
acc +24
nop +269
acc +48
acc +45
jmp -22
acc +11
acc +36
jmp -267
acc +7
nop -45
nop -231
jmp +32
nop +220
acc +19
jmp -250
acc +33
jmp -169
acc +45
acc -13
acc +0
acc +44
jmp +6
acc +42
jmp +84
acc +48
jmp -332
jmp +213
acc -16
acc +31
acc +17
acc +3
jmp -75
jmp +1
acc +11
acc +4
jmp -271
acc -12
nop +97
nop +11
jmp -43
acc +30
jmp +1
jmp +49
jmp -379
nop -51
acc +0
acc -8
nop -191
jmp -346
jmp -255
acc +2
acc +21
acc -16
nop +217
jmp -30
acc +31
jmp -270
jmp -324
jmp +130
acc +49
nop +179
jmp -37
acc +11
acc +15
acc +29
acc +17
jmp -237
acc +47
acc -13
acc +6
jmp +169
nop +54
acc -12
jmp -233
nop +33
acc +17
acc +14
acc +21
jmp -275
acc -8
acc +1
nop +229
jmp +1
jmp +119
jmp -193
nop +217
jmp +95
acc -2
acc +1
acc +41
jmp -332
acc +44
nop -343
acc +23
jmp -165
acc +7
acc -12
nop -339
jmp +9
nop -390
acc -17
acc +43
jmp -138
nop -247
acc +42
acc +0
jmp +170
acc +48
jmp -139
acc +6
acc +13
acc +35
jmp -85
nop -117
jmp -307
acc +25
acc -10
acc -14
acc +0
jmp -355
jmp +102
acc -8
acc +47
acc +36
jmp +42
acc +33
acc +17
acc +46
jmp -331
jmp +1
acc -11
jmp +1
acc +27
jmp +147
acc -14
nop -28
acc +32
jmp -482
acc +11
nop -390
jmp -485
acc -12
acc +37
acc +33
acc +28
jmp -32
acc +42
acc -11
jmp -460
acc +36
acc +6
acc +39
jmp +80
nop +123
acc -13
jmp -97
acc +25
acc +46
acc +13
nop -450
jmp +84
acc +3
nop -260
jmp +1
acc +22
jmp -510
acc -4
acc +17
acc -19
jmp -420
acc -14
acc +26
acc +29
acc +17
jmp -458
acc -10
acc +23
nop -2
jmp -196
acc -5
jmp -416
acc +49
jmp -165
acc +4
acc +7
acc +20
nop -217
jmp +103
jmp +5
acc -1
acc +2
jmp +1
jmp +84
acc -14
jmp -518
jmp +1
acc +30
acc +21
jmp -202
nop -18
jmp -344
jmp -88
nop -472
acc -5
acc +13
jmp -295
nop -315
acc +41
nop -317
jmp -299
nop +105
jmp -86
acc +7
jmp -226
nop -277
acc +21
acc +13
acc +47
jmp -283
acc -11
acc -1
jmp -408
acc +47
nop -553
acc +37
acc -11
jmp -468
acc +43
nop -299
acc +40
acc +2
jmp -275
acc +24
acc -14
acc +13
acc +36
jmp -249
acc +35
jmp -45
acc +47
acc +31
acc -19
jmp -151
jmp -33
acc +6
jmp -160
jmp -553
acc +25
jmp +1
nop -267
jmp -430
acc +23
nop +63
acc +37
jmp -434
nop -579
jmp +11
acc +25
acc -17
acc +22
acc +27
jmp +15
jmp -546
acc -4
acc +41
acc +0
jmp -261
acc +20
jmp -404
jmp -408
acc +26
jmp -464
acc +34
nop -80
acc -12
jmp -43
jmp -410
acc -13
acc -3
jmp -310
nop -433
acc -7
acc -11
acc +9
jmp -29
nop -564
acc -5
acc -16
acc +36
jmp -587
jmp -115
acc +24
acc +35
nop -638
jmp -573
acc +31
acc +14
jmp -609
acc +25
acc -10
acc +18
jmp -308
acc +25
acc +33
acc +21
acc -12
jmp -172
nop -37
acc +12
jmp -316
acc +41
acc +14
jmp -415
acc +40
jmp -112
jmp -613
acc +26
nop -151
jmp -471
acc +50
acc +16
nop -119
acc +46
jmp +1

32
2020/d09/ex1/ex1.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import itertools
import sys
from typing import List
def find_invalid(nums: List[int]) -> int:
for i in range(25, len(nums)):
num = nums[i]
found = False
for lhs, rhs in itertools.combinations(nums[i - 25 : i], 2):
if lhs + rhs == num:
found = True
break
if not found:
return num
assert False # Sanity check
def solve(raw: List[str]) -> int:
return find_invalid([int(line) for line in raw])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

1000
2020/d09/ex1/input Normal file

File diff suppressed because it is too large Load diff

42
2020/d09/ex2/ex2.py Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env python
import itertools
import sys
from typing import List
def find_invalid(nums: List[int]) -> int:
for i in range(25, len(nums)):
num = nums[i]
found = False
for lhs, rhs in itertools.combinations(nums[i - 25 : i], 2):
if lhs + rhs == num:
found = True
break
if not found:
return num
assert False # Sanity check
def find_weakness(nums: List[int], invalid: int) -> int:
for i in range(len(nums) - 2):
for j in range(i + 2, len(nums)):
if sum(nums[i:j]) == invalid:
return min(nums[i:j]) + max(nums[i:j])
assert False # Sanity check((
def solve(raw: List[str]) -> int:
nums = [int(line) for line in raw]
invalid = find_invalid(nums)
return find_weakness(nums, invalid)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

1000
2020/d09/ex2/input Normal file

File diff suppressed because it is too large Load diff

32
2020/d10/ex1/ex1.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import sys
from collections import defaultdict
from typing import Dict, List
def make_chain(adapters: List[int]) -> int:
adapters = sorted(adapters)
output = 0
device = adapters[-1] + 3
jolts: Dict[int, int] = defaultdict(int)
for adapter in adapters:
delt = adapter - output
jolts[delt] += 1
output = adapter
jolts[device - output] += 1
return jolts[1] * jolts[3]
def solve(raw: List[str]) -> int:
return make_chain([int(line) for line in raw])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

101
2020/d10/ex1/input Normal file
View file

@ -0,0 +1,101 @@
144
10
75
3
36
80
143
59
111
133
1
112
23
62
101
137
41
24
8
121
35
105
161
69
52
21
55
29
135
142
38
108
141
115
68
7
98
82
9
72
118
27
153
140
61
90
158
102
28
134
91
2
17
81
31
15
120
20
34
56
4
44
74
14
147
11
49
128
16
99
66
47
125
155
130
37
67
54
60
48
136
89
119
154
122
129
163
73
100
85
95
30
76
162
22
79
88
150
53
63
92

39
2020/d10/ex2/ex2.py Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python
import sys
from typing import Dict, List
def make_chain(adapters: List[int]) -> int:
adapters += [0, max(adapters) + 3]
adapters = sorted(adapters)
jolts: Dict[int, int] = {}
N = len(adapters)
def rec(index: int) -> int:
if (res := jolts.get(index)) is not None:
return res
if index == N - 1:
return 1
total = sum(
rec(i)
for i in range(index + 1, min(N, index + 4))
if (adapters[i] - adapters[index]) <= 3
)
jolts[index] = total
return total
return rec(0)
def solve(raw: List[str]) -> int:
return make_chain([int(line) for line in raw])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

101
2020/d10/ex2/input Normal file
View file

@ -0,0 +1,101 @@
144
10
75
3
36
80
143
59
111
133
1
112
23
62
101
137
41
24
8
121
35
105
161
69
52
21
55
29
135
142
38
108
141
115
68
7
98
82
9
72
118
27
153
140
61
90
158
102
28
134
91
2
17
81
31
15
120
20
34
56
4
44
74
14
147
11
49
128
16
99
66
47
125
155
130
37
67
54
60
48
136
89
119
154
122
129
163
73
100
85
95
30
76
162
22
79
88
150
53
63
92

45
2020/d11/ex1/ex1.py Executable file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env python
import itertools
import sys
from copy import deepcopy
from typing import Iterator, List, Tuple
Grid = List[List[str]]
def update(grid: Grid) -> Grid:
def neightbours(x: int, y: int) -> Iterator[Tuple[int, int]]:
for dx, dy in itertools.product(range(-1, 2), range(-1, 2)):
if dx == 0 and dy == 0:
continue
new_x, new_y = x + dx, y + dy
if 0 <= new_x < len(grid) and 0 <= new_y < len(grid[0]):
yield new_x, new_y
new_grid = deepcopy(grid)
for x, y in itertools.product(range(len(grid)), range(len(grid[0]))):
num_alive = sum(grid[nx][ny] == "#" for nx, ny in neightbours(x, y))
if num_alive == 0 and grid[x][y] == "L":
new_grid[x][y] = "#"
elif num_alive >= 4 and grid[x][y] == "#":
new_grid[x][y] = "L"
return new_grid
def solve(grid: Grid) -> int:
while (new_grid := update(grid)) != grid:
grid = new_grid
return sum(sum(pos == "#" for pos in line) for line in grid)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve([[line[i] for i in range(len(line))] for line in input]))
if __name__ == "__main__":
main()

91
2020/d11/ex1/input Normal file
View file

@ -0,0 +1,91 @@
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LL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LLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
LLLLLLLLLL.LLLL.LLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
L...L.LL......L...LLLLLL.L.L.L...L.L..L..L.LL....L......LL..L...LLL....L...LL......L.........
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
LLLLLLLLLL.LLL..LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLL.LLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL

48
2020/d11/ex2/ex2.py Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env python
import itertools
import sys
from copy import deepcopy
from typing import Iterator, List, Tuple
Grid = List[List[str]]
def update(grid: Grid) -> Grid:
def neightbours(x: int, y: int) -> Iterator[Tuple[int, int]]:
for dx, dy in itertools.product(range(-1, 2), range(-1, 2)):
if dx == 0 and dy == 0:
continue
new_x, new_y = x + dx, y + dy
while 0 <= new_x < len(grid) and 0 <= new_y < len(grid[0]):
if grid[new_x][new_y] in "L#":
yield new_x, new_y
break
new_x, new_y = new_x + dx, new_y + dy
new_grid = deepcopy(grid)
for x, y in itertools.product(range(len(grid)), range(len(grid[0]))):
num_alive = sum(grid[nx][ny] == "#" for nx, ny in neightbours(x, y))
if num_alive == 0 and grid[x][y] == "L":
new_grid[x][y] = "#"
elif num_alive >= 5 and grid[x][y] == "#":
new_grid[x][y] = "L"
return new_grid
def solve(grid: Grid) -> int:
while (new_grid := update(grid)) != grid:
grid = new_grid
return sum(sum(pos == "#" for pos in line) for line in grid)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve([[line[i] for i in range(len(line))] for line in input]))
if __name__ == "__main__":
main()

91
2020/d11/ex2/input Normal file
View file

@ -0,0 +1,91 @@
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL..LLLLLLLLL
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLL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LLLLLLL.LLL..LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLL.LLLL
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL

53
2020/d12/ex1/ex1.py Executable file
View file

@ -0,0 +1,53 @@
#!/usr/bin/env python
import sys
from typing import List, Tuple
Positiom = Tuple[str, int, int]
Instruction = Tuple[str, int]
ORIENTATIONS = ["N", "W", "S", "E"]
MOVES = {
"N": (1, 0),
"W": (0, -1),
"S": (-1, 0),
"E": (0, 1),
}
def move_ship(pos: Positiom, instr: Instruction) -> Positiom:
if instr[0] == "L":
assert instr[1] % 90 == 0 # Sanity check
delt = instr[1] // 90
orientation = ORIENTATIONS[
(ORIENTATIONS.index(pos[0]) + delt) % len(ORIENTATIONS)
]
return (orientation, *pos[1:])
elif instr[0] == "R":
assert instr[1] % 90 == 0 # Sanity check
delt = instr[1] // 90
orientation = ORIENTATIONS[ORIENTATIONS.index(pos[0]) - delt]
return (orientation, *pos[1:])
else:
dx, dy = MOVES[pos[0] if instr[0] == "F" else instr[0]]
x, y = pos[1], pos[2]
x += dx * instr[1]
y += dy * instr[1]
return (pos[0], x, y)
def solve(raw: List[str]) -> int:
instructions = [(i[0], int(i[1:])) for i in raw]
ship = ("E", 0, 0)
for i in instructions:
ship = move_ship(ship, i)
return abs(ship[1]) + abs(ship[2])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

785
2020/d12/ex1/input Normal file
View file

@ -0,0 +1,785 @@
N2
F85
L90
W5
R90
F56
F16
F98
W4
S3
F92
N3
W2
N3
E2
S4
W1
N2
F7
N2
E3
S1
L90
N2
E2
F13
E5
S4
R90
N2
W4
F55
W3
N1
F93
L90
N3
F72
E4
W1
N2
F76
S5
L90
F44
N2
F81
S1
F28
R270
E5
N4
E5
F23
R270
F53
N2
L90
E5
R180
N1
F99
N3
E2
R180
W5
F70
W5
R180
F9
S1
R90
S1
F58
N3
N4
R180
N3
R90
S5
F6
E3
N4
F38
W4
R180
F53
R180
E2
R90
W4
L180
F13
N3
F80
W1
R270
E2
S1
F24
E5
F1
S3
F34
R90
F54
E4
F59
E4
R180
F88
R90
S1
R90
F6
R90
N1
F89
W3
F9
L180
W1
F47
R180
N2
W1
F28
F73
S1
F27
E2
F82
W3
F38
E4
L90
E4
F64
W5
W3
S2
L180
F22
L90
F10
L90
F64
E4
N4
F21
S4
E3
N5
F71
N3
F93
N2
R90
E4
F64
E1
L90
F37
E5
F96
W2
N4
E2
R90
S1
R90
W1
R180
E2
S2
R90
W3
S2
F94
W2
L180
S2
E4
F54
N2
E4
S3
L180
W2
N1
W2
R90
F54
L180
N2
F87
E2
F23
W3
R180
W4
S3
F93
E5
R90
N4
R90
S4
E3
S3
F31
R90
F89
E3
F73
S5
F97
W1
L180
F52
E3
F68
R90
S2
S5
F26
L180
F12
E2
F83
F9
N2
R90
F99
R90
S4
E5
R90
S4
F84
W4
E5
R90
F42
W4
F94
W1
R270
S3
E5
F23
F38
W2
W1
N5
E2
L180
N1
F26
L90
F5
R90
N5
R180
F25
L90
S1
N3
F62
S1
F77
N3
E3
L90
F93
W3
E3
N2
F14
N5
F80
S2
L90
N4
W2
L180
F81
R180
N4
F8
W4
S4
R90
F34
W2
L180
F49
S4
E4
R90
W2
F75
R90
S5
E4
L90
N3
W4
R90
N4
E3
F62
R90
E4
N2
W3
N1
R90
F75
E1
L180
S3
W1
N2
W5
N3
F70
L90
W1
S2
L270
E5
F21
S3
W3
R90
F3
N3
F85
E5
R90
F8
W2
S3
W4
F38
N5
F54
L90
W3
R90
E5
F2
S5
F79
N4
E2
R180
W2
N1
R90
F57
W4
S1
F27
E5
F31
R90
F11
S5
W4
N3
W1
S1
F93
N3
L180
E1
F63
E2
R180
F99
N3
E3
N3
W5
F66
E5
R90
S1
L90
N1
R90
W5
R90
L90
E4
R270
W3
N5
R90
S5
F8
F93
E3
N4
F48
W1
R180
N1
R90
W3
R180
F3
R180
F8
N4
E1
F34
N1
F33
N4
R90
L180
E3
F35
S5
F64
L90
E4
F30
R90
L90
E5
N4
R180
S2
W3
R90
F35
L180
E2
S3
E5
L90
N5
R90
R90
N4
E5
F34
W5
W4
L90
E2
N2
S5
F85
S5
F98
W1
S3
F7
E2
S4
F27
L180
F30
L90
W1
F87
W1
E2
E2
N3
F64
E4
F31
L270
S3
W2
F60
S2
E1
L180
F2
W3
S3
E3
R180
F12
L180
E1
R90
L180
F60
R90
E4
R180
E3
S1
E3
S1
F86
R90
E1
S4
F47
N4
E4
N4
W4
R90
S3
F81
S1
E1
L270
S2
L90
E5
F62
W4
F78
L90
F18
S5
R180
S1
R270
S3
W5
F3
N1
R90
N4
F59
N1
W4
R90
E3
N3
N4
L90
W5
S2
L90
N2
W1
L180
F49
N4
F14
L180
N2
F43
S3
F84
E3
R180
S4
W1
F90
F58
W3
F18
E5
L90
F72
W1
N1
R90
S3
F79
E4
S4
F31
N4
F66
L90
W1
N2
E4
F74
W1
N2
E5
S5
L90
E3
F71
N3
R90
N4
E2
N2
F83
L90
W4
F64
L90
W1
S2
E4
F48
S3
W5
L90
E5
S1
L180
E4
N4
F40
E4
R270
F85
E4
R90
L90
S1
R270
W1
R180
F72
S2
R90
F63
R180
F93
E4
S4
R90
W3
R90
F10
E4
F93
R180
E1
E3
R90
W1
L180
F83
W4
F41
W4
R90
F1
L90
W4
L90
N4
R180
S5
F63
S2
E4
R90
F90
E5
S2
L90
F64
R90
L90
N1
E4
F20
W3
N4
R90
W5
N1
E5
W4
R90
N1
F72
S5
F78
S2
R180
N4
L180
N5
F22
W4
R180
F19
W3
L90
E4
F27
W5
S4
E4
F34
N4
F40
N3
R90
L90
S2
W1
R90
E3
R90
N1
W4
F93
N5
L90
F7
E1
L90
W4
N3
E5
F62
R90
W4
L90
S3
E4
L270
S3
W5
S2
F30
N2
F70
S5
W1
S3
R90
E4
S5
L90
S2
R90
W1
L90
W5
F8
R90
N4
L180
N5
L90
N3
F30
W2
F39
E3
F17
W3
S1
F48
E1
R90
F35
W2
L180
S1
L90
E5
S1
R90
E2
S5
W2
N1
E3
F100
S2
E4
L90
W5
R90
F81
S4
R90
F80

69
2020/d12/ex2/ex2.py Executable file
View file

@ -0,0 +1,69 @@
#!/usr/bin/env python
import sys
from dataclasses import dataclass
from typing import List, Tuple
Instruction = Tuple[str, int]
Position = Tuple[int, int]
@dataclass
class Ship:
pos: Position
rel_waypoint: Position
ORIENTATIONS = ["N", "W", "S", "E"]
MOVES = {
"N": (1, 0),
"W": (0, -1),
"S": (-1, 0),
"E": (0, 1),
}
def move_ship(pos: Ship, instr: Instruction) -> Ship:
if instr[0] == "L":
assert instr[1] % 90 == 0
turns = instr[1] // 90
x, y = pos.rel_waypoint
for __ in range(turns):
x, y = y, -x
return Ship(pos.pos, (x, y))
elif instr[0] == "R":
assert instr[1] % 90 == 0
turns = instr[1] // 90
x, y = pos.rel_waypoint
for __ in range(turns):
x, y = -y, x
return Ship(pos.pos, (x, y))
elif instr[0] == "F":
dx, dy = pos.rel_waypoint
x, y = pos.pos
x += dx * instr[1]
y += dy * instr[1]
return Ship((x, y), pos.rel_waypoint)
else:
dx, dy = MOVES[instr[0]]
x, y = pos.rel_waypoint
x += dx * instr[1]
y += dy * instr[1]
return Ship(pos.pos, (x, y))
def solve(raw: List[str]) -> int:
instructions = [(i[0], int(i[1:])) for i in raw]
ship = Ship((0, 0), (1, 10))
for i in instructions:
ship = move_ship(ship, i)
return sum(abs(c) for c in ship.pos)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

785
2020/d12/ex2/input Normal file
View file

@ -0,0 +1,785 @@
N2
F85
L90
W5
R90
F56
F16
F98
W4
S3
F92
N3
W2
N3
E2
S4
W1
N2
F7
N2
E3
S1
L90
N2
E2
F13
E5
S4
R90
N2
W4
F55
W3
N1
F93
L90
N3
F72
E4
W1
N2
F76
S5
L90
F44
N2
F81
S1
F28
R270
E5
N4
E5
F23
R270
F53
N2
L90
E5
R180
N1
F99
N3
E2
R180
W5
F70
W5
R180
F9
S1
R90
S1
F58
N3
N4
R180
N3
R90
S5
F6
E3
N4
F38
W4
R180
F53
R180
E2
R90
W4
L180
F13
N3
F80
W1
R270
E2
S1
F24
E5
F1
S3
F34
R90
F54
E4
F59
E4
R180
F88
R90
S1
R90
F6
R90
N1
F89
W3
F9
L180
W1
F47
R180
N2
W1
F28
F73
S1
F27
E2
F82
W3
F38
E4
L90
E4
F64
W5
W3
S2
L180
F22
L90
F10
L90
F64
E4
N4
F21
S4
E3
N5
F71
N3
F93
N2
R90
E4
F64
E1
L90
F37
E5
F96
W2
N4
E2
R90
S1
R90
W1
R180
E2
S2
R90
W3
S2
F94
W2
L180
S2
E4
F54
N2
E4
S3
L180
W2
N1
W2
R90
F54
L180
N2
F87
E2
F23
W3
R180
W4
S3
F93
E5
R90
N4
R90
S4
E3
S3
F31
R90
F89
E3
F73
S5
F97
W1
L180
F52
E3
F68
R90
S2
S5
F26
L180
F12
E2
F83
F9
N2
R90
F99
R90
S4
E5
R90
S4
F84
W4
E5
R90
F42
W4
F94
W1
R270
S3
E5
F23
F38
W2
W1
N5
E2
L180
N1
F26
L90
F5
R90
N5
R180
F25
L90
S1
N3
F62
S1
F77
N3
E3
L90
F93
W3
E3
N2
F14
N5
F80
S2
L90
N4
W2
L180
F81
R180
N4
F8
W4
S4
R90
F34
W2
L180
F49
S4
E4
R90
W2
F75
R90
S5
E4
L90
N3
W4
R90
N4
E3
F62
R90
E4
N2
W3
N1
R90
F75
E1
L180
S3
W1
N2
W5
N3
F70
L90
W1
S2
L270
E5
F21
S3
W3
R90
F3
N3
F85
E5
R90
F8
W2
S3
W4
F38
N5
F54
L90
W3
R90
E5
F2
S5
F79
N4
E2
R180
W2
N1
R90
F57
W4
S1
F27
E5
F31
R90
F11
S5
W4
N3
W1
S1
F93
N3
L180
E1
F63
E2
R180
F99
N3
E3
N3
W5
F66
E5
R90
S1
L90
N1
R90
W5
R90
L90
E4
R270
W3
N5
R90
S5
F8
F93
E3
N4
F48
W1
R180
N1
R90
W3
R180
F3
R180
F8
N4
E1
F34
N1
F33
N4
R90
L180
E3
F35
S5
F64
L90
E4
F30
R90
L90
E5
N4
R180
S2
W3
R90
F35
L180
E2
S3
E5
L90
N5
R90
R90
N4
E5
F34
W5
W4
L90
E2
N2
S5
F85
S5
F98
W1
S3
F7
E2
S4
F27
L180
F30
L90
W1
F87
W1
E2
E2
N3
F64
E4
F31
L270
S3
W2
F60
S2
E1
L180
F2
W3
S3
E3
R180
F12
L180
E1
R90
L180
F60
R90
E4
R180
E3
S1
E3
S1
F86
R90
E1
S4
F47
N4
E4
N4
W4
R90
S3
F81
S1
E1
L270
S2
L90
E5
F62
W4
F78
L90
F18
S5
R180
S1
R270
S3
W5
F3
N1
R90
N4
F59
N1
W4
R90
E3
N3
N4
L90
W5
S2
L90
N2
W1
L180
F49
N4
F14
L180
N2
F43
S3
F84
E3
R180
S4
W1
F90
F58
W3
F18
E5
L90
F72
W1
N1
R90
S3
F79
E4
S4
F31
N4
F66
L90
W1
N2
E4
F74
W1
N2
E5
S5
L90
E3
F71
N3
R90
N4
E2
N2
F83
L90
W4
F64
L90
W1
S2
E4
F48
S3
W5
L90
E5
S1
L180
E4
N4
F40
E4
R270
F85
E4
R90
L90
S1
R270
W1
R180
F72
S2
R90
F63
R180
F93
E4
S4
R90
W3
R90
F10
E4
F93
R180
E1
E3
R90
W1
L180
F83
W4
F41
W4
R90
F1
L90
W4
L90
N4
R180
S5
F63
S2
E4
R90
F90
E5
S2
L90
F64
R90
L90
N1
E4
F20
W3
N4
R90
W5
N1
E5
W4
R90
N1
F72
S5
F78
S2
R180
N4
L180
N5
F22
W4
R180
F19
W3
L90
E4
F27
W5
S4
E4
F34
N4
F40
N3
R90
L90
S2
W1
R90
E3
R90
N1
W4
F93
N5
L90
F7
E1
L90
W4
N3
E5
F62
R90
W4
L90
S3
E4
L270
S3
W5
S2
F30
N2
F70
S5
W1
S3
R90
E4
S5
L90
S2
R90
W1
L90
W5
F8
R90
N4
L180
N5
L90
N3
F30
W2
F39
E3
F17
W3
S1
F48
E1
R90
F35
W2
L180
S1
L90
E5
S1
R90
E2
S5
W2
N1
E3
F100
S2
E4
L90
W5
R90
F81
S4
R90
F80

31
2020/d13/ex1/ex1.py Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env python
import itertools
import math
import sys
from typing import List, Tuple
def find_first_factor(earliest: int, timings: List[int]) -> Tuple[int, int]:
timings = sorted(timings)
for t in itertools.count(earliest):
for n in timings:
if t % n == 0:
return t - earliest, n
assert False # Make Mypy happy
def solve(raw: List[str]) -> int:
return math.prod(
find_first_factor(int(raw[0]), [int(i) for i in raw[1].split(",") if i != "x"])
)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2
2020/d13/ex1/input Normal file
View file

@ -0,0 +1,2 @@
1002462
37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13

45
2020/d13/ex2/ex2.py Executable file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env python
import math
import sys
from typing import Dict, List
def run_contest(timings: List[int]) -> int:
# https://rosettacode.org/wiki/Chinese_remainder_theorem#Python_3.6
def mul_inv(a: int, b: int) -> int:
b0 = b
x0, x1 = 0, 1
if b == 1:
return 1
while a > 1:
q = a // b
a, b = b, a % b
x0, x1 = x1 - q * x0, x0
if x1 < 0:
x1 += b0
return x1
def chinese_remainder(residue_mapping: Dict[int, int]) -> int:
res = 0
prod = math.prod(residue_mapping)
for n_i, a_i in residue_mapping.items():
p = prod // n_i
res += a_i * mul_inv(p, n_i) * p
return res % prod
residues = {t: -i for (i, t) in enumerate(timings) if t > 0}
return chinese_remainder(residues)
def solve(raw: List[str]) -> int:
return run_contest([int(i) if i != "x" else -1 for i in raw[1].split(",")])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2
2020/d13/ex2/input Normal file
View file

@ -0,0 +1,2 @@
1002462
37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13

44
2020/d14/ex1/ex1.py Executable file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env python
import re
import sys
from dataclasses import dataclass
from typing import Dict, List
@dataclass
class Mask:
ones: int
zeros: int
Memory = Dict[int, int]
def solve(raw: List[str]) -> int:
mask = Mask(
0,
(2 << 36) - 1,
)
mem_pattern = re.compile("mem\\[([0-9]+)\\] = ([0-9]+)")
mask_pattern = re.compile("mask = ([01X]+)")
mem: Memory = {}
for instr in raw:
if (mem_match := mem_pattern.match(instr)) is not None:
addr, val = int(mem_match.group(1)), int(mem_match.group(2))
val |= mask.ones
val &= mask.zeros
mem[addr] = val
elif (mask_match := mask_pattern.match(instr)) is not None:
ones = int(mask_match.group(1).replace("X", "0"), 2)
zeros = int(mask_match.group(1).replace("X", "1"), 2)
mask = Mask(ones, zeros)
return sum(mem.values())
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

575
2020/d14/ex1/input Normal file
View file

@ -0,0 +1,575 @@
mask = 110100X1X01011X01X0X000111X00XX1010X
mem[29267] = 4155
mem[6177] = 494929
mem[47500] = 15063410
mask = 11110X000010XX10X11X00X11010X0X00101
mem[10164] = 73599
mem[61707] = 15191
mem[53825] = 69618638
mem[15953] = 10067309
mem[39889] = 10761258
mask = 11XXX0XX001X01101111X001000X01X10000
mem[6917] = 2088
mem[10383] = 52991144
mem[14304] = 84876
mem[6464] = 14167
mask = X11X0X00001010101XX101100X011X000XX1
mem[58256] = 51753803
mem[2919] = 21619
mask = 111100X00010101011X1XXXXX01X000001X1
mem[13063] = 6587
mem[28673] = 3893
mem[53317] = 236744
mem[64240] = 29367045
mask = XX11101X0011X01X1111X001X1X000101110
mem[59497] = 6945823
mem[44552] = 193130494
mem[15034] = 10641
mem[25467] = 17061678
mask = X11110X11X11X000110110010110011X0001
mem[22485] = 90244
mem[38996] = 221133
mem[15034] = 12927587
mem[4425] = 31960477
mem[18544] = 51522085
mask = 111100100010X0101XX1110100000XXX0001
mem[53765] = 1528530
mem[18576] = 68702
mem[6484] = 170802
mem[62813] = 857
mask = 1X1101010X1X111X110101X1010100010010
mem[34688] = 36117345
mem[12832] = 14851833
mem[12097] = 43
mem[63931] = 875829
mask = 10XXX01100101010X1X111010000101101X1
mem[33582] = 28611764
mem[53969] = 2641
mem[53107] = 99965
mem[40648] = 1834153
mem[55768] = 974
mem[52274] = 7634
mask = 111010X10010111X1111X0XXX00110110001
mem[43784] = 12232
mem[23109] = 11403
mem[18521] = 145694
mem[12479] = 621
mask = XX000011001000101111XX101X1X10101X11
mem[22233] = 30348
mem[7554] = 346199
mem[1904] = 12735
mem[23360] = 73797
mem[22803] = 62630115
mask = 1110X0X0X010X01011X10110001X00XX0110
mem[17347] = 310008019
mem[39889] = 8179468
mem[57304] = 861379
mem[2513] = 10343
mask = 1111X00100101X1X110101111111010000XX
mem[49939] = 39353857
mem[48794] = 4266
mem[16061] = 2768
mem[7728] = 103608
mem[17473] = 8980
mask = 1001XXX10X0X11X0010100001100X0110101
mem[21497] = 412878
mem[49939] = 429971
mem[3405] = 20518
mem[6160] = 51622
mem[43784] = 179922643
mask = 101100X1001X10XX1101X00XX0101000100X
mem[52378] = 1530
mem[11326] = 121760772
mem[58232] = 164870285
mem[21604] = 17658898
mem[56257] = 373
mem[37783] = 7760640
mem[3927] = 427054839
mask = 1111XXX10010X11X110101011X10XX10000X
mem[18153] = 234818
mem[56755] = 531
mem[50940] = 4428
mem[14849] = 2185318
mask = 10110001X0101010X101010X10000X110001
mem[53880] = 33275
mem[61621] = 40021
mem[10319] = 9468
mem[34607] = 1186
mem[43043] = 51628146
mem[14912] = 2626679
mem[4627] = 377
mask = 111X0X00XXX01110011X10001X1110010101
mem[39892] = 6297
mem[13182] = 4721
mem[41736] = 497649
mem[40923] = 905
mask = 1X1X00110010011X1110X0001X10011XXX00
mem[27118] = 898
mem[59800] = 499005720
mask = 11X00101001011100X01X01XX100XX010110
mem[56505] = 23945612
mem[13987] = 14200131
mem[30557] = 10396
mask = 1110000100X1X01X011111X001101011010X
mem[22942] = 642242
mem[43083] = 787
mem[55307] = 818610470
mem[13145] = 35815
mask = 00101X01001010X011111101X1001X010101
mem[34] = 928
mem[45041] = 12613
mem[20825] = 18260
mem[33068] = 34949
mem[51299] = 1228577
mask = X11X0001101X001X11010001110X00X01X11
mem[5587] = 3120
mem[49934] = 166656215
mem[12068] = 15929077
mem[51471] = 225039
mem[35781] = 703735
mem[2227] = 788305092
mem[30564] = 4758296
mask = 1111X1X000100X10X10010011XX011010110
mem[44917] = 195410918
mem[33352] = 480672
mem[18755] = 6376
mask = X1X1010000100010XXX0XXX011X011010000
mem[48717] = 6124
mem[6213] = 13466626
mem[33804] = 41450
mem[42319] = 1001042
mem[32039] = 22800
mem[37805] = 3719
mem[21650] = 5310058
mask = 1X110X0X00101X10110100111X10000X00X1
mem[64021] = 527213
mem[54049] = 2076239
mem[23361] = 10197597
mem[29280] = 28451017
mem[3136] = 46819
mem[21711] = 62402971
mask = 1X01000100X01110X101000101000XX10X01
mem[20911] = 1251
mem[3136] = 84
mem[27425] = 174128253
mem[20825] = 20910
mem[36929] = 13761934
mem[44528] = 983
mask = 1111X000001X001X11111XX1X00X0110000X
mem[516] = 6216446
mem[33582] = 140720
mem[11248] = 208955105
mem[42641] = 4364
mask = 101X1X10101X10001XXX0001111100011X11
mem[38531] = 39598
mem[46500] = 52608117
mem[43473] = 96876
mem[14304] = 59167889
mem[53240] = 15525
mask = X001100X00X01110111X1101010X00101111
mem[14918] = 2357
mem[6160] = 1208519
mem[34729] = 1611506
mem[51158] = 2346
mask = 111X00100000101011010111001110XXX1X0
mem[28673] = 331536
mem[43917] = 324
mem[45633] = 398602
mem[49398] = 1861
mem[1376] = 625904
mask = 01101X00001010100101100X101X10X00011
mem[28094] = 8805622
mem[30532] = 3723
mem[4708] = 14406
mem[9094] = 50623
mem[61707] = 73798
mem[4885] = 224
mask = 11X1000X001011X011010X01010XX10X0001
mem[7236] = 865782
mem[15953] = 487381549
mask = XX1011000010X11X010X11111100X11100XX
mem[18078] = 16242735
mem[5995] = 18850
mem[9604] = 839527
mem[47055] = 216488
mem[4059] = 554189
mem[12823] = 346
mask = 111100010010111X1X01X1110001X001X000
mem[936] = 6429561
mem[40513] = 1695095
mem[60924] = 252
mem[55142] = 557439
mask = 10111010X010X0X01XX1100111010X1X1X00
mem[38842] = 738
mem[30409] = 10094059
mem[303] = 98943
mem[8017] = 251227
mask = X1X0X00100100010X101001100110001X100
mem[57304] = 1975648
mem[56257] = 1580
mem[45571] = 14800
mask = 0XX00011001000X0X1111X11101X101X1000
mem[43189] = 4422
mem[40391] = 167654070
mask = 1110X01100100X10111XX01X1000XX01100X
mem[33804] = 1018
mem[29496] = 93900747
mem[9245] = 138506
mem[62151] = 674748
mem[4762] = 434956
mem[37596] = 103373
mem[27932] = 5730935
mask = 0111X0000010101X111X01001010101110X0
mem[36174] = 5162986
mem[33114] = 3116668
mem[64325] = 3171
mem[6917] = 5566099
mem[30076] = 176956
mem[14847] = 60238674
mask = 1110100X00100010XXX1X110000000001X01
mem[2546] = 7549354
mem[22803] = 386154
mem[28386] = 86719
mask = 11110100X00011X011X10X0011011010X100
mem[52611] = 131
mem[47628] = 266
mem[22198] = 764
mem[4444] = 406
mem[20006] = 3520555
mask = 10111X101010X000100110011100X01X1010
mem[15300] = 345854040
mem[49359] = 38235897
mem[38614] = 54370972
mem[18472] = 94915
mem[36746] = 697
mask = 11111011X011101X111X10100100000X0111
mem[29295] = 943139945
mem[9245] = 1505677
mem[14391] = 3398
mask = 1001X1X1X1001X10010100001X01XX11X101
mem[14613] = 15025
mem[58121] = 1912
mem[300] = 37310097
mask = X011001X001010XX11X1100X00XXX0011110
mem[17438] = 69372377
mem[39932] = 850
mem[53370] = 7579742
mem[49975] = 2831104
mem[37777] = 2859
mem[49238] = 508
mem[57733] = 3881
mask = 11110010001010X011X1X1X11XX00XX101X0
mem[29112] = 64162
mem[9687] = 10115647
mem[8456] = 404111433
mem[23461] = 21916957
mem[49272] = 29938
mem[20911] = 3016
mem[45508] = 27114
mask = X11010X000101X10X1X10X1XXX0110000111
mem[17094] = 1379888
mem[19615] = 633
mem[43148] = 125580
mem[12097] = 33116239
mem[34723] = 9358
mask = X111X010010X101011110X00011111000101
mem[63053] = 691425156
mem[24475] = 286162
mem[54863] = 76914
mem[58008] = 1422
mem[24141] = 657
mem[34729] = 49841
mask = 1110XXXXX0X011100X0101X1010X10001100
mem[14613] = 4510
mem[47926] = 39745
mem[8475] = 327407289
mem[22599] = 699202
mem[53880] = 822
mem[56755] = 1267566
mask = 1X1110X1101X100011X110X01X0001110XX1
mem[8272] = 301
mem[65364] = 3792396
mem[38614] = 591
mem[10929] = 4608
mem[30304] = 2186
mask = 1110000110X0001011010011110000X0X01X
mem[12247] = 1533938
mem[24376] = 12421
mem[16168] = 17660
mask = 001000000010101X11X101X00001X00XX0X0
mem[606] = 2029
mem[55307] = 598939
mem[26724] = 59403185
mask = 11X10XX000X01X101X01010110000X00000X
mem[4022] = 39755
mem[39281] = 801343
mem[46388] = 161
mem[21585] = 11357692
mem[45828] = 28056
mask = 11111X11101111001101XX11X1010X00X11X
mem[47755] = 3034
mem[42293] = 208825
mem[29700] = 38238
mem[22485] = 1319489
mask = 110100X0001X101X11010011100X000X0101
mem[3549] = 18335450
mem[58890] = 2676627
mem[58022] = 17558
mem[54581] = 2533100
mem[10929] = 280423870
mem[63555] = 2319
mem[2546] = 926
mask = 1110X011001XXX101111X1110001X110X001
mem[23536] = 4353
mem[59601] = 798347
mem[20671] = 389086
mask = 111100X000101010110101001XX1XX11X110
mem[1922] = 27551122
mem[19645] = 370473454
mem[32150] = 214932
mem[22144] = 2339
mask = 111000100110X01X1101101XX01111010X00
mem[35424] = 110774
mem[57733] = 531999
mem[45139] = 30278097
mem[21648] = 16240
mask = 1010X00100X00010111101001X0X00X10010
mem[58367] = 71950736
mem[855] = 21617593
mem[27425] = 1287663
mem[45595] = 1472271
mem[37043] = 1635315
mask = 111X00X1001X110011010010X0001100000X
mem[7355] = 208029905
mem[52551] = 6755
mem[49542] = 11911
mem[44588] = 377151
mem[64240] = 61021
mem[8017] = 3572
mask = 0X101000001011X011X101X0000X0000X011
mem[47482] = 1568110
mem[28053] = 707
mem[60195] = 1645
mask = 11110000001X101011X1101010110X00011X
mem[27869] = 17384703
mem[17643] = 2734129
mem[12802] = 3774302
mem[64154] = 916
mask = X111X00X0010110011010X01111001010XX1
mem[64313] = 102372
mem[1522] = 15753175
mem[40584] = 728098
mem[4315] = 227246865
mem[55272] = 7469
mem[15889] = 7541958
mem[2464] = 371279
mask = XX01X011X01011101101X00XX10X00110100
mem[5157] = 275
mem[12864] = 4756
mem[31054] = 1960
mem[52498] = 2797835
mem[62151] = 4302055
mask = 0X1X00X000101X1X1111010X000101X00110
mem[10919] = 612216
mem[15357] = 629148
mem[52500] = 9503
mem[17094] = 7855156
mem[6652] = 34492510
mem[10426] = 726153
mask = 010X00110010001X1111101XXX01X0X00101
mem[12974] = 9133
mem[14108] = 3766
mem[24429] = 1803969
mem[55142] = 36626772
mem[34019] = 473252
mem[33604] = 206855588
mask = XX1010X10010X01011X11X0011X01011XX11
mem[60027] = 841211
mem[21538] = 91609915
mem[6123] = 97596
mem[50346] = 1087
mem[40221] = 644
mem[8944] = 551344
mask = 111000X0001XX0100111111001100X00000X
mem[35547] = 950205
mem[3312] = 880
mem[48780] = 112556701
mem[4531] = 126242
mem[39889] = 1541
mem[24463] = 9010512
mask = 11XX101X1X101X001X0111X101000X1X0001
mem[64081] = 140604
mem[59066] = 420736
mem[48653] = 54226
mem[32039] = 128940
mem[35847] = 5
mask = 1001XX01X000111011X1X101000X0X0X1011
mem[58689] = 43170762
mem[12832] = 298144839
mem[1474] = 132921
mem[48057] = 37242
mem[50871] = 3602555
mem[56611] = 31214078
mask = 101X000100X011X01101XX10011X0XX1X011
mem[7317] = 2861082
mem[59424] = 214468
mask = 10X110111011101010110X10111001100XX1
mem[19313] = 2195784
mem[38614] = 1263318
mem[26637] = 54905795
mem[8165] = 209848
mem[2919] = 173
mem[928] = 7285
mask = 1011101XX011XX1X10111000011010X11111
mem[55792] = 11794686
mem[48675] = 377
mem[6484] = 857
mem[60951] = 523305753
mem[40488] = 713
mem[61858] = 12068
mask = 1110X1XX0010111X01011111X000X0X1011X
mem[65124] = 178147455
mem[15914] = 3503977
mem[35424] = 232628
mask = 11X0XXX100100010X1X101001XX100110001
mem[14344] = 2670
mem[20825] = 27980258
mem[2792] = 447228346
mem[29177] = 822367210
mem[30651] = 1658444
mem[14099] = 389
mask = 110001X1X010X110X101X011X100X1X10110
mem[54275] = 15249248
mem[3293] = 9475932
mem[8835] = 864371828
mem[45269] = 3632
mem[19645] = 580157
mask = 101X101XX01X10X01X1110X0110X1011011X
mem[40765] = 53494316
mem[35543] = 11261002
mem[13933] = 768
mem[38594] = 464498
mem[64240] = 22406
mask = 110100010X10111011X100X1010001X1X1X0
mem[20911] = 225
mem[12748] = 621
mem[29907] = 363502
mem[14613] = 3957288
mem[64313] = 389459
mem[21648] = 2008398
mask = 111X101X00X0X010X1110110X00011X1X011
mem[33134] = 1049991943
mem[25205] = 4126902
mask = 1X10101001101X1011X100X00X1X1101X100
mem[18755] = 713
mem[38650] = 119518
mem[33804] = 3211485
mem[14609] = 10752655
mem[59822] = 234204205
mask = 1X1XX0111X1X11001101100X110100X0X010
mem[44041] = 255408886
mem[62469] = 22090167
mem[12247] = 1760642
mask = 1110101000001X101X11010010XX110001XX
mem[30389] = 29125
mem[10833] = 1979
mask = 11111010111X1X001001111X1X1000010001
mem[20949] = 90971
mem[16774] = 9470584
mem[56713] = 73907316
mem[9264] = 36226
mem[60287] = 571
mem[25303] = 16376
mask = X1010X0XX01000X0001000X0X0010000X110
mem[59573] = 60076
mem[14516] = 1634251
mem[36459] = 843815961
mem[3293] = 265
mask = 01010100001X00101100X0X0111X11001101
mem[28480] = 437785448
mem[29724] = 28414900
mem[22867] = 14233982
mem[45019] = 1644931
mask = 111XX0100XX0101011X1011X001X11X101X0
mem[28545] = 461
mem[14609] = 3934
mem[50765] = 103069037
mem[12832] = 1926345
mem[36929] = 1633120
mem[33372] = 23156328
mask = X11X000000XX11X011X1XX0110000X000001
mem[12748] = 2069634
mem[35456] = 8101313
mem[21508] = 243298359
mask = X1X01001011X001001010110101100X10011
mem[27953] = 3450
mem[22680] = 50713870
mem[55768] = 182841527
mem[29021] = 70952
mem[59553] = 38886
mem[45283] = 84846018
mem[29849] = 66463
mask = 100XX1111X0011100X01000X010000000101
mem[53280] = 2165
mem[551] = 556704
mem[3512] = 16238
mem[2868] = 27158838
mem[23659] = 245809
mask = 1110X001X010X0101X01110100000X10111X
mem[36789] = 51664764
mem[33348] = 1689925
mem[19745] = 849985
mem[7335] = 3678
mem[25634] = 2206
mem[13782] = 1985
mask = 11110000X0100110XX11X0110100X0110001
mem[18372] = 193162
mem[5878] = 7411977
mem[30564] = 89127
mem[45210] = 64823202
mem[22016] = 3987667
mem[7092] = 370183817
mem[64313] = 2487681
mask = 10X0000100100X101X1X1101110000X0X011
mem[6160] = 9833
mem[26168] = 120117155
mem[13319] = 18180
mask = 1X01X001X0X01X1011110001100X0110X100
mem[29267] = 385
mem[13597] = 535380132
mem[58085] = 3408333
mem[46178] = 246464
mem[64848] = 140510
mem[19733] = 322520311
mask = 1101101110XX1000X001101110000000X1X0
mem[56355] = 894
mem[13795] = 13763
mem[38247] = 1412147
mem[46043] = 10668
mem[9370] = 8326048
mem[27470] = 524
mask = 111010010X1000100X01X1XX10XX0XX10000
mem[45269] = 129135
mem[33483] = 11595926
mem[9827] = 18572496
mem[27939] = 32963714
mem[48103] = 89693846
mask = X11XX111001001101101010101000X000101
mem[12666] = 61469
mem[40505] = 14463
mem[49277] = 118992
mem[16161] = 105
mem[23321] = 183700
mem[48653] = 930591910
mask = 111X00100X0X1010110100001X011X1X00X0
mem[59706] = 227615179
mem[21221] = 1424545
mem[54816] = 37682162
mem[57789] = 91718
mem[25191] = 3615219
mem[10390] = 240
mask = 1110X0XX001XX010X1110110001011010X01
mem[60974] = 5579328
mem[61131] = 337545
mem[16774] = 2030
mem[6637] = 5249

56
2020/d14/ex2/ex2.py Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env python
import itertools
import re
import sys
from dataclasses import dataclass
from typing import Dict, Iterator, List
@dataclass
class Mask:
ones: int
zeros: int
Memory = Dict[int, int]
def gen_floats(xs: int) -> Iterator[int]:
x_positions = [i for i in range(36) if (1 << i) & xs]
return (
sum(1 << x_positions[i] for i, v in enumerate(val) if v == 1)
for val in itertools.product([0, 1], repeat=len(x_positions))
)
def solve(raw: List[str]) -> int:
mask = Mask(
0,
(2 << 36) - 1,
)
mem_pattern = re.compile("mem\\[([0-9]+)\\] = ([0-9]+)")
mask_pattern = re.compile("mask = ([01X]+)")
mem: Memory = {}
for instr in raw:
if (mem_match := mem_pattern.match(instr)) is not None:
addr, val = int(mem_match.group(1)), int(mem_match.group(2))
addr |= mask.ones
xs = ~mask.ones & mask.zeros
addr &= ~xs # Put floating bits to 0
for x in gen_floats(xs):
mem[addr | x] = val
elif (mask_match := mask_pattern.match(instr)) is not None:
ones = int(mask_match.group(1).replace("X", "0"), 2)
zeros = int(mask_match.group(1).replace("X", "1"), 2)
mask = Mask(ones, zeros)
return sum(mem.values())
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

575
2020/d14/ex2/input Normal file
View file

@ -0,0 +1,575 @@
mask = 110100X1X01011X01X0X000111X00XX1010X
mem[29267] = 4155
mem[6177] = 494929
mem[47500] = 15063410
mask = 11110X000010XX10X11X00X11010X0X00101
mem[10164] = 73599
mem[61707] = 15191
mem[53825] = 69618638
mem[15953] = 10067309
mem[39889] = 10761258
mask = 11XXX0XX001X01101111X001000X01X10000
mem[6917] = 2088
mem[10383] = 52991144
mem[14304] = 84876
mem[6464] = 14167
mask = X11X0X00001010101XX101100X011X000XX1
mem[58256] = 51753803
mem[2919] = 21619
mask = 111100X00010101011X1XXXXX01X000001X1
mem[13063] = 6587
mem[28673] = 3893
mem[53317] = 236744
mem[64240] = 29367045
mask = XX11101X0011X01X1111X001X1X000101110
mem[59497] = 6945823
mem[44552] = 193130494
mem[15034] = 10641
mem[25467] = 17061678
mask = X11110X11X11X000110110010110011X0001
mem[22485] = 90244
mem[38996] = 221133
mem[15034] = 12927587
mem[4425] = 31960477
mem[18544] = 51522085
mask = 111100100010X0101XX1110100000XXX0001
mem[53765] = 1528530
mem[18576] = 68702
mem[6484] = 170802
mem[62813] = 857
mask = 1X1101010X1X111X110101X1010100010010
mem[34688] = 36117345
mem[12832] = 14851833
mem[12097] = 43
mem[63931] = 875829
mask = 10XXX01100101010X1X111010000101101X1
mem[33582] = 28611764
mem[53969] = 2641
mem[53107] = 99965
mem[40648] = 1834153
mem[55768] = 974
mem[52274] = 7634
mask = 111010X10010111X1111X0XXX00110110001
mem[43784] = 12232
mem[23109] = 11403
mem[18521] = 145694
mem[12479] = 621
mask = XX000011001000101111XX101X1X10101X11
mem[22233] = 30348
mem[7554] = 346199
mem[1904] = 12735
mem[23360] = 73797
mem[22803] = 62630115
mask = 1110X0X0X010X01011X10110001X00XX0110
mem[17347] = 310008019
mem[39889] = 8179468
mem[57304] = 861379
mem[2513] = 10343
mask = 1111X00100101X1X110101111111010000XX
mem[49939] = 39353857
mem[48794] = 4266
mem[16061] = 2768
mem[7728] = 103608
mem[17473] = 8980
mask = 1001XXX10X0X11X0010100001100X0110101
mem[21497] = 412878
mem[49939] = 429971
mem[3405] = 20518
mem[6160] = 51622
mem[43784] = 179922643
mask = 101100X1001X10XX1101X00XX0101000100X
mem[52378] = 1530
mem[11326] = 121760772
mem[58232] = 164870285
mem[21604] = 17658898
mem[56257] = 373
mem[37783] = 7760640
mem[3927] = 427054839
mask = 1111XXX10010X11X110101011X10XX10000X
mem[18153] = 234818
mem[56755] = 531
mem[50940] = 4428
mem[14849] = 2185318
mask = 10110001X0101010X101010X10000X110001
mem[53880] = 33275
mem[61621] = 40021
mem[10319] = 9468
mem[34607] = 1186
mem[43043] = 51628146
mem[14912] = 2626679
mem[4627] = 377
mask = 111X0X00XXX01110011X10001X1110010101
mem[39892] = 6297
mem[13182] = 4721
mem[41736] = 497649
mem[40923] = 905
mask = 1X1X00110010011X1110X0001X10011XXX00
mem[27118] = 898
mem[59800] = 499005720
mask = 11X00101001011100X01X01XX100XX010110
mem[56505] = 23945612
mem[13987] = 14200131
mem[30557] = 10396
mask = 1110000100X1X01X011111X001101011010X
mem[22942] = 642242
mem[43083] = 787
mem[55307] = 818610470
mem[13145] = 35815
mask = 00101X01001010X011111101X1001X010101
mem[34] = 928
mem[45041] = 12613
mem[20825] = 18260
mem[33068] = 34949
mem[51299] = 1228577
mask = X11X0001101X001X11010001110X00X01X11
mem[5587] = 3120
mem[49934] = 166656215
mem[12068] = 15929077
mem[51471] = 225039
mem[35781] = 703735
mem[2227] = 788305092
mem[30564] = 4758296
mask = 1111X1X000100X10X10010011XX011010110
mem[44917] = 195410918
mem[33352] = 480672
mem[18755] = 6376
mask = X1X1010000100010XXX0XXX011X011010000
mem[48717] = 6124
mem[6213] = 13466626
mem[33804] = 41450
mem[42319] = 1001042
mem[32039] = 22800
mem[37805] = 3719
mem[21650] = 5310058
mask = 1X110X0X00101X10110100111X10000X00X1
mem[64021] = 527213
mem[54049] = 2076239
mem[23361] = 10197597
mem[29280] = 28451017
mem[3136] = 46819
mem[21711] = 62402971
mask = 1X01000100X01110X101000101000XX10X01
mem[20911] = 1251
mem[3136] = 84
mem[27425] = 174128253
mem[20825] = 20910
mem[36929] = 13761934
mem[44528] = 983
mask = 1111X000001X001X11111XX1X00X0110000X
mem[516] = 6216446
mem[33582] = 140720
mem[11248] = 208955105
mem[42641] = 4364
mask = 101X1X10101X10001XXX0001111100011X11
mem[38531] = 39598
mem[46500] = 52608117
mem[43473] = 96876
mem[14304] = 59167889
mem[53240] = 15525
mask = X001100X00X01110111X1101010X00101111
mem[14918] = 2357
mem[6160] = 1208519
mem[34729] = 1611506
mem[51158] = 2346
mask = 111X00100000101011010111001110XXX1X0
mem[28673] = 331536
mem[43917] = 324
mem[45633] = 398602
mem[49398] = 1861
mem[1376] = 625904
mask = 01101X00001010100101100X101X10X00011
mem[28094] = 8805622
mem[30532] = 3723
mem[4708] = 14406
mem[9094] = 50623
mem[61707] = 73798
mem[4885] = 224
mask = 11X1000X001011X011010X01010XX10X0001
mem[7236] = 865782
mem[15953] = 487381549
mask = XX1011000010X11X010X11111100X11100XX
mem[18078] = 16242735
mem[5995] = 18850
mem[9604] = 839527
mem[47055] = 216488
mem[4059] = 554189
mem[12823] = 346
mask = 111100010010111X1X01X1110001X001X000
mem[936] = 6429561
mem[40513] = 1695095
mem[60924] = 252
mem[55142] = 557439
mask = 10111010X010X0X01XX1100111010X1X1X00
mem[38842] = 738
mem[30409] = 10094059
mem[303] = 98943
mem[8017] = 251227
mask = X1X0X00100100010X101001100110001X100
mem[57304] = 1975648
mem[56257] = 1580
mem[45571] = 14800
mask = 0XX00011001000X0X1111X11101X101X1000
mem[43189] = 4422
mem[40391] = 167654070
mask = 1110X01100100X10111XX01X1000XX01100X
mem[33804] = 1018
mem[29496] = 93900747
mem[9245] = 138506
mem[62151] = 674748
mem[4762] = 434956
mem[37596] = 103373
mem[27932] = 5730935
mask = 0111X0000010101X111X01001010101110X0
mem[36174] = 5162986
mem[33114] = 3116668
mem[64325] = 3171
mem[6917] = 5566099
mem[30076] = 176956
mem[14847] = 60238674
mask = 1110100X00100010XXX1X110000000001X01
mem[2546] = 7549354
mem[22803] = 386154
mem[28386] = 86719
mask = 11110100X00011X011X10X0011011010X100
mem[52611] = 131
mem[47628] = 266
mem[22198] = 764
mem[4444] = 406
mem[20006] = 3520555
mask = 10111X101010X000100110011100X01X1010
mem[15300] = 345854040
mem[49359] = 38235897
mem[38614] = 54370972
mem[18472] = 94915
mem[36746] = 697
mask = 11111011X011101X111X10100100000X0111
mem[29295] = 943139945
mem[9245] = 1505677
mem[14391] = 3398
mask = 1001X1X1X1001X10010100001X01XX11X101
mem[14613] = 15025
mem[58121] = 1912
mem[300] = 37310097
mask = X011001X001010XX11X1100X00XXX0011110
mem[17438] = 69372377
mem[39932] = 850
mem[53370] = 7579742
mem[49975] = 2831104
mem[37777] = 2859
mem[49238] = 508
mem[57733] = 3881
mask = 11110010001010X011X1X1X11XX00XX101X0
mem[29112] = 64162
mem[9687] = 10115647
mem[8456] = 404111433
mem[23461] = 21916957
mem[49272] = 29938
mem[20911] = 3016
mem[45508] = 27114
mask = X11010X000101X10X1X10X1XXX0110000111
mem[17094] = 1379888
mem[19615] = 633
mem[43148] = 125580
mem[12097] = 33116239
mem[34723] = 9358
mask = X111X010010X101011110X00011111000101
mem[63053] = 691425156
mem[24475] = 286162
mem[54863] = 76914
mem[58008] = 1422
mem[24141] = 657
mem[34729] = 49841
mask = 1110XXXXX0X011100X0101X1010X10001100
mem[14613] = 4510
mem[47926] = 39745
mem[8475] = 327407289
mem[22599] = 699202
mem[53880] = 822
mem[56755] = 1267566
mask = 1X1110X1101X100011X110X01X0001110XX1
mem[8272] = 301
mem[65364] = 3792396
mem[38614] = 591
mem[10929] = 4608
mem[30304] = 2186
mask = 1110000110X0001011010011110000X0X01X
mem[12247] = 1533938
mem[24376] = 12421
mem[16168] = 17660
mask = 001000000010101X11X101X00001X00XX0X0
mem[606] = 2029
mem[55307] = 598939
mem[26724] = 59403185
mask = 11X10XX000X01X101X01010110000X00000X
mem[4022] = 39755
mem[39281] = 801343
mem[46388] = 161
mem[21585] = 11357692
mem[45828] = 28056
mask = 11111X11101111001101XX11X1010X00X11X
mem[47755] = 3034
mem[42293] = 208825
mem[29700] = 38238
mem[22485] = 1319489
mask = 110100X0001X101X11010011100X000X0101
mem[3549] = 18335450
mem[58890] = 2676627
mem[58022] = 17558
mem[54581] = 2533100
mem[10929] = 280423870
mem[63555] = 2319
mem[2546] = 926
mask = 1110X011001XXX101111X1110001X110X001
mem[23536] = 4353
mem[59601] = 798347
mem[20671] = 389086
mask = 111100X000101010110101001XX1XX11X110
mem[1922] = 27551122
mem[19645] = 370473454
mem[32150] = 214932
mem[22144] = 2339
mask = 111000100110X01X1101101XX01111010X00
mem[35424] = 110774
mem[57733] = 531999
mem[45139] = 30278097
mem[21648] = 16240
mask = 1010X00100X00010111101001X0X00X10010
mem[58367] = 71950736
mem[855] = 21617593
mem[27425] = 1287663
mem[45595] = 1472271
mem[37043] = 1635315
mask = 111X00X1001X110011010010X0001100000X
mem[7355] = 208029905
mem[52551] = 6755
mem[49542] = 11911
mem[44588] = 377151
mem[64240] = 61021
mem[8017] = 3572
mask = 0X101000001011X011X101X0000X0000X011
mem[47482] = 1568110
mem[28053] = 707
mem[60195] = 1645
mask = 11110000001X101011X1101010110X00011X
mem[27869] = 17384703
mem[17643] = 2734129
mem[12802] = 3774302
mem[64154] = 916
mask = X111X00X0010110011010X01111001010XX1
mem[64313] = 102372
mem[1522] = 15753175
mem[40584] = 728098
mem[4315] = 227246865
mem[55272] = 7469
mem[15889] = 7541958
mem[2464] = 371279
mask = XX01X011X01011101101X00XX10X00110100
mem[5157] = 275
mem[12864] = 4756
mem[31054] = 1960
mem[52498] = 2797835
mem[62151] = 4302055
mask = 0X1X00X000101X1X1111010X000101X00110
mem[10919] = 612216
mem[15357] = 629148
mem[52500] = 9503
mem[17094] = 7855156
mem[6652] = 34492510
mem[10426] = 726153
mask = 010X00110010001X1111101XXX01X0X00101
mem[12974] = 9133
mem[14108] = 3766
mem[24429] = 1803969
mem[55142] = 36626772
mem[34019] = 473252
mem[33604] = 206855588
mask = XX1010X10010X01011X11X0011X01011XX11
mem[60027] = 841211
mem[21538] = 91609915
mem[6123] = 97596
mem[50346] = 1087
mem[40221] = 644
mem[8944] = 551344
mask = 111000X0001XX0100111111001100X00000X
mem[35547] = 950205
mem[3312] = 880
mem[48780] = 112556701
mem[4531] = 126242
mem[39889] = 1541
mem[24463] = 9010512
mask = 11XX101X1X101X001X0111X101000X1X0001
mem[64081] = 140604
mem[59066] = 420736
mem[48653] = 54226
mem[32039] = 128940
mem[35847] = 5
mask = 1001XX01X000111011X1X101000X0X0X1011
mem[58689] = 43170762
mem[12832] = 298144839
mem[1474] = 132921
mem[48057] = 37242
mem[50871] = 3602555
mem[56611] = 31214078
mask = 101X000100X011X01101XX10011X0XX1X011
mem[7317] = 2861082
mem[59424] = 214468
mask = 10X110111011101010110X10111001100XX1
mem[19313] = 2195784
mem[38614] = 1263318
mem[26637] = 54905795
mem[8165] = 209848
mem[2919] = 173
mem[928] = 7285
mask = 1011101XX011XX1X10111000011010X11111
mem[55792] = 11794686
mem[48675] = 377
mem[6484] = 857
mem[60951] = 523305753
mem[40488] = 713
mem[61858] = 12068
mask = 1110X1XX0010111X01011111X000X0X1011X
mem[65124] = 178147455
mem[15914] = 3503977
mem[35424] = 232628
mask = 11X0XXX100100010X1X101001XX100110001
mem[14344] = 2670
mem[20825] = 27980258
mem[2792] = 447228346
mem[29177] = 822367210
mem[30651] = 1658444
mem[14099] = 389
mask = 110001X1X010X110X101X011X100X1X10110
mem[54275] = 15249248
mem[3293] = 9475932
mem[8835] = 864371828
mem[45269] = 3632
mem[19645] = 580157
mask = 101X101XX01X10X01X1110X0110X1011011X
mem[40765] = 53494316
mem[35543] = 11261002
mem[13933] = 768
mem[38594] = 464498
mem[64240] = 22406
mask = 110100010X10111011X100X1010001X1X1X0
mem[20911] = 225
mem[12748] = 621
mem[29907] = 363502
mem[14613] = 3957288
mem[64313] = 389459
mem[21648] = 2008398
mask = 111X101X00X0X010X1110110X00011X1X011
mem[33134] = 1049991943
mem[25205] = 4126902
mask = 1X10101001101X1011X100X00X1X1101X100
mem[18755] = 713
mem[38650] = 119518
mem[33804] = 3211485
mem[14609] = 10752655
mem[59822] = 234204205
mask = 1X1XX0111X1X11001101100X110100X0X010
mem[44041] = 255408886
mem[62469] = 22090167
mem[12247] = 1760642
mask = 1110101000001X101X11010010XX110001XX
mem[30389] = 29125
mem[10833] = 1979
mask = 11111010111X1X001001111X1X1000010001
mem[20949] = 90971
mem[16774] = 9470584
mem[56713] = 73907316
mem[9264] = 36226
mem[60287] = 571
mem[25303] = 16376
mask = X1010X0XX01000X0001000X0X0010000X110
mem[59573] = 60076
mem[14516] = 1634251
mem[36459] = 843815961
mem[3293] = 265
mask = 01010100001X00101100X0X0111X11001101
mem[28480] = 437785448
mem[29724] = 28414900
mem[22867] = 14233982
mem[45019] = 1644931
mask = 111XX0100XX0101011X1011X001X11X101X0
mem[28545] = 461
mem[14609] = 3934
mem[50765] = 103069037
mem[12832] = 1926345
mem[36929] = 1633120
mem[33372] = 23156328
mask = X11X000000XX11X011X1XX0110000X000001
mem[12748] = 2069634
mem[35456] = 8101313
mem[21508] = 243298359
mask = X1X01001011X001001010110101100X10011
mem[27953] = 3450
mem[22680] = 50713870
mem[55768] = 182841527
mem[29021] = 70952
mem[59553] = 38886
mem[45283] = 84846018
mem[29849] = 66463
mask = 100XX1111X0011100X01000X010000000101
mem[53280] = 2165
mem[551] = 556704
mem[3512] = 16238
mem[2868] = 27158838
mem[23659] = 245809
mask = 1110X001X010X0101X01110100000X10111X
mem[36789] = 51664764
mem[33348] = 1689925
mem[19745] = 849985
mem[7335] = 3678
mem[25634] = 2206
mem[13782] = 1985
mask = 11110000X0100110XX11X0110100X0110001
mem[18372] = 193162
mem[5878] = 7411977
mem[30564] = 89127
mem[45210] = 64823202
mem[22016] = 3987667
mem[7092] = 370183817
mem[64313] = 2487681
mask = 10X0000100100X101X1X1101110000X0X011
mem[6160] = 9833
mem[26168] = 120117155
mem[13319] = 18180
mask = 1X01X001X0X01X1011110001100X0110X100
mem[29267] = 385
mem[13597] = 535380132
mem[58085] = 3408333
mem[46178] = 246464
mem[64848] = 140510
mem[19733] = 322520311
mask = 1101101110XX1000X001101110000000X1X0
mem[56355] = 894
mem[13795] = 13763
mem[38247] = 1412147
mem[46043] = 10668
mem[9370] = 8326048
mem[27470] = 524
mask = 111010010X1000100X01X1XX10XX0XX10000
mem[45269] = 129135
mem[33483] = 11595926
mem[9827] = 18572496
mem[27939] = 32963714
mem[48103] = 89693846
mask = X11XX111001001101101010101000X000101
mem[12666] = 61469
mem[40505] = 14463
mem[49277] = 118992
mem[16161] = 105
mem[23321] = 183700
mem[48653] = 930591910
mask = 111X00100X0X1010110100001X011X1X00X0
mem[59706] = 227615179
mem[21221] = 1424545
mem[54816] = 37682162
mem[57789] = 91718
mem[25191] = 3615219
mem[10390] = 240
mask = 1110X0XX001XX010X1110110001011010X01
mem[60974] = 5579328
mem[61131] = 337545
mem[16774] = 2030
mem[6637] = 5249

40
2020/d15/ex1/ex1.py Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
import itertools
import sys
from collections import defaultdict
from typing import Dict, Iterator, List
def nth(iterable: Iterator[int], n: int) -> int:
return next(itertools.islice(iterable, n, None))
def spoken(spoken: List[int]) -> Iterator[int]:
turn = 0
turns: Dict[int, List[int]] = defaultdict(list)
for last in spoken:
turn += 1
turns[last].append(turn)
yield last
while True:
if len(last_turn := turns[last]) < 2:
last = 0
else:
last = last_turn[-1] - last_turn[-2]
turn += 1
turns[last].append(turn)
yield last
def solve(nums: List[int]) -> int:
return nth(spoken(nums), 2020 - 1)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
assert len(input) == 1
print(solve([int(i) for i in input[0].split(",")]))
if __name__ == "__main__":
main()

1
2020/d15/ex1/input Normal file
View file

@ -0,0 +1 @@
0,13,1,16,6,17

40
2020/d15/ex2/ex2.py Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env python
import itertools
import sys
from collections import defaultdict
from typing import Dict, Iterator, List
def nth(iterable: Iterator[int], n: int) -> int:
return next(itertools.islice(iterable, n, None))
def spoken(spoken: List[int]) -> Iterator[int]:
turn = 0
turns: Dict[int, List[int]] = defaultdict(list)
for last in spoken:
turn += 1
turns[last].append(turn)
yield last
while True:
if len(last_turn := turns[last]) < 2:
last = 0
else:
last = last_turn[-1] - last_turn[-2]
turn += 1
turns[last].append(turn)
yield last
def solve(nums: List[int]) -> int:
return nth(spoken(nums), 30000000 - 1)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
assert len(input) == 1
print(solve([int(i) for i in input[0].split(",")]))
if __name__ == "__main__":
main()

1
2020/d15/ex2/input Normal file
View file

@ -0,0 +1 @@
0,13,1,16,6,17

59
2020/d16/ex1/ex1.py Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env python
import sys
from typing import Dict, List, Set, Tuple
Ranges = Dict[str, Set[int]]
Ticket = List[int]
def parse(raw: List[str]) -> Tuple[Ranges, List[Ticket]]:
def extract_field_info(line: str) -> Tuple[str, Set[int]]:
field, rest = line.split(":")
ranges: Set[int] = set()
for r in rest.strip().split(" or "):
lhs, rhs = r.split("-")
ranges |= set(range(int(lhs), int(rhs) + 1))
return field, ranges
def parse_tickets(line: str) -> Ticket:
return [int(i) for i in line.split(",")]
ranges: Ranges = {}
tickets: List[Ticket] = []
should_parse_tickets = False
for line in raw:
if line == "":
should_parse_tickets = True
continue
if "ticket" in line:
continue
if should_parse_tickets:
tickets.append(parse_tickets(line))
else:
field, field_ranges = extract_field_info(line)
ranges[field] = field_ranges
return ranges, tickets
def solve(raw: List[str]) -> int:
ranges, tickets = parse(raw)
sum = 0
for ticket in tickets[1:]:
for val in ticket:
if any(val in r for r in ranges.values()):
continue
sum += val
return sum
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

264
2020/d16/ex1/input Normal file
View file

@ -0,0 +1,264 @@
departure location: 44-709 or 728-964
departure station: 42-259 or 269-974
departure platform: 39-690 or 701-954
departure track: 49-909 or 924-965
departure date: 48-759 or 779-957
departure time: 38-115 or 121-965
arrival location: 32-808 or 818-949
arrival station: 45-418 or 439-949
arrival platform: 35-877 or 894-962
arrival track: 26-866 or 872-958
class: 32-727 or 736-969
duration: 35-446 or 460-968
price: 26-545 or 571-961
route: 35-207 or 223-960
row: 43-156 or 165-955
seat: 26-172 or 181-966
train: 49-582 or 606-952
type: 36-279 or 303-968
wagon: 26-657 or 672-959
zone: 36-621 or 637-963
your ticket:
83,127,131,137,113,73,139,101,67,53,107,103,59,149,109,61,79,71,97,89
nearby tickets:
539,619,928,309,835,99,521,478,54,340,849,859,376,357,524,841,221,935,806,147
231,827,907,526,238,542,181,853,303,143,116,701,206,140,927,203,443,753,151,258
445,679,816,617,82,102,197,100,239,490,488,78,707,349,689,335,847,183,144,314
476,833,232,489,937,256,87,409,223,364,978,939,398,331,153,945,513,237,934,272
492,927,578,788,808,529,739,20,201,688,405,877,228,168,361,521,400,398,618,520
332,694,481,571,523,516,395,122,844,358,232,132,315,486,899,154,269,201,831,50
907,706,927,126,133,97,217,334,745,751,580,862,526,845,680,125,96,445,863,322
498,753,844,670,150,657,853,150,377,487,152,369,500,241,360,204,142,236,948,91
578,675,491,230,332,464,258,858,508,330,492,780,494,234,839,645,160,795,896,687
814,875,617,185,490,490,501,940,224,751,609,844,442,525,640,609,336,251,532,685
684,196,757,841,580,576,18,319,150,249,676,337,155,115,652,638,475,398,789,379
445,490,199,140,88,694,184,247,307,386,198,85,905,860,484,244,532,224,681,251
172,936,701,440,779,941,639,351,238,70,787,91,259,340,58,541,815,399,238,202
715,369,504,226,138,866,783,231,580,147,82,335,533,144,530,462,836,751,473,801
932,459,242,947,653,150,618,683,198,608,88,342,948,497,675,53,681,544,315,615
422,244,791,929,799,128,374,473,148,931,381,822,318,853,147,367,531,412,242,470
464,899,490,846,381,326,271,948,396,318,653,981,310,822,502,895,78,935,78,461
231,339,79,530,680,461,863,521,839,517,379,108,395,613,644,751,823,212,206,151
526,507,403,354,931,859,787,728,247,781,643,203,847,326,506,79,65,332,91,783
571,182,753,841,338,746,254,307,896,648,726,89,314,706,943,464,444,481,465,928
184,513,335,941,303,198,537,571,409,337,497,621,350,617,98,897,850,679,794,260
235,255,393,310,188,65,943,543,94,374,500,482,122,992,656,523,704,742,331,792
315,152,320,983,493,166,754,376,619,480,149,929,330,80,529,131,150,57,251,842
54,77,540,141,61,205,273,214,745,145,166,131,93,525,500,521,223,52,237,404
300,616,784,250,852,354,327,944,675,859,673,941,789,829,234,104,842,85,742,98
110,244,95,93,529,162,82,309,142,680,65,410,531,758,511,790,333,352,926,397
496,518,828,896,52,828,805,62,470,121,853,831,346,654,684,196,535,15,251,381
231,444,530,616,795,620,78,460,947,748,757,78,706,336,82,317,186,256,216,196
520,838,365,445,928,855,418,943,195,689,176,638,151,59,82,495,58,681,737,545
172,755,782,71,514,336,383,470,168,70,168,199,307,102,793,250,739,174,368,279
897,734,446,184,254,785,499,949,903,405,401,679,356,753,354,351,842,443,207,203
60,577,746,229,105,475,640,877,848,477,545,525,793,752,313,315,318,983,537,249
474,833,611,169,61,800,759,228,321,833,303,673,513,862,76,122,803,520,67,667
504,919,413,521,514,251,785,170,656,759,510,537,579,462,794,756,687,479,864,507
949,774,866,805,357,442,183,874,934,195,511,742,756,683,396,407,637,348,866,344
687,305,781,780,821,586,945,94,87,230,353,376,849,379,510,368,709,489,113,191
275,356,277,655,529,493,541,141,132,804,620,171,382,443,483,978,737,536,532,904
357,369,142,383,802,782,722,391,905,684,226,413,379,74,792,618,351,939,580,578
368,394,514,461,445,933,677,324,318,250,863,266,855,703,781,142,460,74,753,947
935,852,127,241,309,825,481,206,642,81,375,862,330,21,496,60,677,238,532,138
258,680,336,136,640,193,372,100,227,856,495,103,92,341,356,703,568,147,311,514
412,673,398,244,397,313,378,780,107,905,318,208,172,374,464,690,379,686,538,638
660,321,894,681,515,539,486,403,469,91,675,186,386,839,197,639,411,873,69,837
845,413,996,87,314,674,362,258,783,412,341,529,519,654,526,757,899,617,909,492
127,749,682,785,735,418,112,834,934,381,613,107,748,474,84,72,514,355,942,701
541,100,75,155,645,410,612,519,976,656,854,140,61,140,401,827,466,798,385,192
332,126,836,373,545,313,379,69,345,751,348,750,746,643,763,519,943,508,679,274
642,521,55,479,54,615,323,247,736,80,979,489,97,238,759,579,363,826,91,929
227,497,467,249,808,441,906,361,815,523,206,352,383,521,798,84,360,74,680,100
96,486,465,382,796,198,500,717,462,617,245,247,649,941,946,750,408,845,637,311
379,168,181,100,507,798,928,784,174,128,830,480,113,311,379,474,361,613,909,325
130,144,649,305,273,637,112,353,528,786,944,866,931,269,381,271,153,902,552,129
520,908,58,249,842,831,756,253,21,238,645,607,902,200,439,100,112,324,374,672
614,173,149,316,132,309,484,270,249,104,542,524,350,357,244,331,507,405,793,345
943,140,784,620,818,558,780,53,894,673,500,370,109,539,372,376,505,785,909,782
900,187,113,464,991,534,368,181,463,841,747,362,945,640,153,227,241,944,833,743
863,838,340,366,230,500,643,103,772,127,88,754,611,496,791,444,440,903,75,467
649,828,617,466,188,502,315,352,866,758,919,247,835,574,750,409,468,247,359,202
371,846,121,755,474,472,176,325,153,97,949,201,65,171,908,500,277,937,90,388
929,392,539,469,843,440,947,893,347,312,128,63,754,685,947,227,679,470,945,303
731,77,872,620,88,616,104,681,204,312,115,688,386,195,676,506,87,707,519,149
278,365,780,785,874,251,114,321,499,898,729,101,637,684,167,797,826,930,615,51
319,924,819,856,202,71,102,55,838,81,231,150,656,840,354,679,744,475,344,814
926,657,378,507,927,389,680,238,185,319,475,897,132,936,685,540,16,331,508,613
681,897,228,303,835,356,523,403,314,709,382,272,370,109,470,479,923,443,896,782
677,239,501,233,180,928,351,101,373,151,321,347,445,198,112,679,828,751,680,96
840,497,237,318,490,848,248,351,413,850,945,662,460,945,439,929,126,199,330,320
647,489,508,105,648,253,270,807,201,110,537,12,336,369,581,609,190,535,676,489
534,668,686,442,938,394,798,755,190,412,505,375,101,752,490,405,875,573,417,677
231,461,260,138,611,824,333,331,406,351,229,97,756,926,678,849,488,758,230,121
82,347,442,172,652,898,687,491,392,539,538,389,257,505,334,325,840,89,918,138
517,352,192,701,848,617,804,704,344,785,58,839,351,140,394,242,144,342,179,142
166,140,226,442,183,499,166,272,839,795,908,165,901,703,262,91,358,127,872,834
788,157,156,675,876,376,473,404,709,752,373,780,324,146,169,819,807,337,514,204
190,511,822,204,495,948,123,117,932,509,148,706,66,110,861,674,637,545,486,855
119,227,439,442,808,378,929,949,313,142,359,789,503,442,908,310,315,474,395,935
367,210,531,480,142,245,833,172,320,137,468,800,827,930,199,318,904,642,516,865
538,198,113,62,362,528,787,668,936,657,184,345,895,236,385,829,522,253,758,352
315,708,796,639,162,690,688,750,366,171,509,476,708,782,637,368,934,125,73,248
617,156,576,737,521,755,932,266,939,203,690,578,853,98,414,50,759,440,819,331
593,232,442,468,578,949,383,129,800,152,77,386,935,819,925,470,305,396,308,874
102,361,319,187,226,942,493,272,247,68,475,364,398,141,821,900,56,480,814,307
650,796,98,92,687,646,128,140,168,813,203,825,851,80,136,473,581,150,865,806
263,520,275,378,406,113,59,194,759,128,522,183,498,167,185,702,652,606,133,578
707,331,737,748,820,759,257,742,856,500,318,814,507,898,244,153,470,319,532,110
488,382,380,145,126,807,359,343,606,82,750,194,607,981,409,151,860,862,339,900
873,620,230,924,345,750,62,387,802,113,97,930,63,416,750,76,657,507,260,325
111,749,114,785,477,572,248,687,500,64,925,931,132,783,795,491,998,248,754,56
115,83,245,512,638,327,108,451,826,757,675,521,342,350,102,462,348,841,874,798
941,822,582,948,500,645,393,757,214,362,103,132,181,515,227,828,827,406,375,232
647,362,660,738,497,366,803,505,335,105,75,153,313,759,501,241,62,149,748,926
123,146,613,390,742,638,907,515,334,686,411,854,933,469,174,126,169,395,842,351
830,315,59,573,843,656,523,533,528,403,259,141,523,333,876,355,880,680,134,942
234,22,808,145,529,374,142,572,344,409,607,930,858,825,804,223,534,505,466,539
684,688,940,524,357,684,844,673,381,794,895,516,308,582,380,487,731,241,797,685
196,112,331,528,533,396,489,579,266,496,77,440,650,165,399,469,475,507,364,56
354,139,945,330,742,894,782,989,87,231,54,358,51,681,350,652,936,745,134,936
804,439,935,234,944,849,186,173,254,690,326,102,149,926,115,792,829,167,508,746
388,684,243,814,80,350,637,335,442,146,474,825,477,686,578,331,269,378,472,828
826,863,520,70,279,522,801,579,500,237,696,534,242,259,932,540,182,544,72,701
886,227,369,89,612,147,488,152,511,646,104,853,352,94,741,223,858,150,383,680
792,51,440,64,838,116,195,674,70,902,829,779,682,404,808,860,619,466,807,836
652,499,177,830,104,674,377,128,787,123,153,782,230,237,526,478,273,523,92,85
418,364,405,327,502,538,539,278,372,508,245,306,325,488,548,674,97,135,944,906
409,996,83,929,461,485,829,384,171,844,933,755,780,860,491,331,473,541,874,142
390,92,141,310,747,142,653,498,203,829,946,393,142,251,360,22,804,385,240,167
874,255,324,340,562,529,366,190,100,480,109,171,947,491,188,154,680,404,275,486
945,947,61,110,500,920,875,248,352,56,475,949,876,686,745,443,171,821,348,645
705,498,139,798,369,418,666,124,227,578,530,376,607,122,613,87,101,50,930,129
475,235,549,581,610,820,206,96,901,802,128,818,413,542,151,362,401,474,76,331
506,608,462,708,980,838,582,803,56,503,83,258,384,925,171,874,152,823,170,89
517,606,475,644,105,195,846,445,323,619,498,183,310,79,493,155,90,533,259,218
63,619,373,850,902,90,153,542,269,330,94,357,797,203,909,201,776,615,606,340
501,342,74,394,94,212,401,475,877,72,519,128,148,640,859,68,525,54,358,904
875,821,377,781,823,781,398,619,945,130,930,750,802,752,704,439,1,645,337,309
533,830,474,829,98,613,896,744,512,126,248,511,113,250,66,515,585,128,877,259
201,858,793,791,828,471,859,581,899,76,836,738,259,155,816,360,474,414,277,835
5,324,784,71,677,617,745,808,184,56,478,682,578,310,390,330,656,872,305,684
508,686,519,385,245,759,766,136,898,128,332,205,276,58,60,252,906,167,737,169
799,650,674,67,181,243,155,254,785,208,934,197,835,350,76,865,516,248,837,503
361,90,874,251,310,733,155,60,69,276,325,370,330,149,62,397,519,704,823,345
186,256,497,252,75,880,516,278,172,381,61,357,358,115,858,202,512,375,836,247
465,324,828,443,518,708,781,895,122,334,161,759,517,356,616,399,65,796,127,236
792,170,109,461,141,928,758,201,101,114,739,153,108,675,938,512,177,330,580,943
92,407,385,278,92,723,333,757,936,373,90,788,388,505,738,609,826,321,153,858
350,780,492,311,414,306,702,252,257,782,837,823,137,166,988,648,186,781,613,789
83,341,408,537,607,483,948,122,349,757,144,81,945,757,758,474,370,651,947,567
110,689,77,706,383,353,395,187,399,402,186,223,816,373,112,530,908,327,531,851
492,137,785,209,610,392,791,411,523,198,377,386,225,236,344,837,491,781,393,579
233,172,271,138,875,789,512,81,63,406,479,232,122,704,895,946,448,136,684,949
351,238,909,505,96,523,192,444,491,259,313,345,100,530,116,257,532,646,103,675
642,149,898,346,487,470,896,358,493,674,275,461,503,572,443,787,839,905,499,117
306,947,308,523,334,467,127,782,389,835,448,862,895,482,614,278,252,402,641,336
232,368,805,944,138,86,143,499,644,60,320,942,89,533,489,71,782,927,327,17
141,672,108,175,844,378,843,647,223,372,140,109,705,785,407,843,795,400,182,310
253,684,377,93,409,606,688,23,476,51,709,828,860,736,156,75,483,169,441,92
519,312,95,899,115,949,818,308,119,611,206,372,643,524,63,757,89,538,783,801
577,872,902,510,51,239,278,541,576,235,780,475,758,321,350,575,117,324,83,410
932,796,508,832,894,392,314,90,58,13,478,440,942,818,145,271,736,475,181,937
113,737,758,182,145,454,332,66,52,488,545,129,500,126,509,703,306,137,534,618
928,900,799,575,417,254,903,373,803,803,263,313,365,100,894,250,842,799,929,128
69,705,638,72,321,814,610,397,926,902,67,499,122,508,74,744,825,746,183,410
926,316,324,483,348,356,544,945,865,538,380,508,76,758,506,380,326,640,118,824
832,340,786,225,704,206,508,535,843,347,326,120,620,473,650,247,100,238,309,337
677,581,526,334,677,705,266,60,367,485,646,88,252,104,752,509,908,486,684,377
55,861,490,521,265,182,339,876,575,242,782,153,673,495,256,534,360,346,233,361
446,126,228,876,991,351,271,499,239,831,618,708,935,256,704,904,129,131,227,850
219,642,394,413,129,276,843,701,619,349,242,247,608,320,824,864,894,536,701,255
544,642,256,128,379,279,307,523,256,75,410,536,357,785,806,790,663,826,642,392
311,337,896,352,315,538,786,271,370,54,129,89,946,837,71,519,715,818,76,270
871,638,385,795,238,63,645,226,388,337,128,270,679,839,846,516,314,607,616,475
94,794,188,392,490,73,144,908,504,139,182,573,844,391,947,333,528,549,782,384
758,517,808,637,347,836,105,610,643,852,55,719,581,646,74,362,396,410,141,337
949,749,745,848,187,51,350,497,165,543,929,321,245,945,272,121,396,810,198,108
407,54,341,519,926,801,73,397,606,524,385,470,413,346,670,80,279,360,901,392
794,139,837,745,834,380,701,312,463,705,151,313,682,168,866,1,703,500,476,202
544,892,621,354,924,134,736,793,338,872,346,80,823,675,121,97,801,464,508,58
370,538,474,641,171,189,342,381,94,145,999,384,383,400,645,866,513,140,618,97
230,621,616,240,675,414,933,22,362,828,618,926,486,393,895,88,110,230,528,940
483,852,446,339,512,684,582,200,896,862,979,353,319,610,145,374,581,446,750,252
157,648,683,439,460,224,357,135,279,69,899,154,75,515,321,349,115,657,156,189
414,794,652,930,397,440,655,306,484,512,342,861,344,902,100,860,513,976,66,388
405,932,488,444,745,870,528,446,657,188,863,689,475,56,708,476,325,757,336,638
456,783,396,84,237,107,443,645,106,652,304,337,110,477,134,899,145,410,709,544
334,865,677,708,642,660,343,83,945,855,899,529,704,877,675,199,639,342,337,848
490,855,851,784,119,652,489,416,349,538,705,439,736,537,751,312,152,273,307,95
696,125,500,754,90,516,681,533,902,226,97,377,57,322,312,191,384,794,109,196
195,50,197,253,339,992,502,168,402,107,757,137,247,62,275,855,245,231,645,86
638,316,191,524,699,821,898,205,102,98,375,279,376,97,82,582,233,386,347,242
177,369,248,754,803,270,927,382,305,532,854,854,614,355,746,356,484,253,388,406
844,896,376,832,385,757,755,930,376,509,353,569,255,442,166,312,498,894,394,738
362,591,803,532,678,527,517,852,345,440,832,948,403,673,96,228,861,909,840,412
484,817,196,102,476,352,232,742,359,367,609,82,207,201,520,521,233,940,384,480
906,329,207,67,510,71,98,920,857,384,77,247,571,388,121,387,147,241,894,478
390,530,97,924,187,681,120,69,151,226,239,750,945,399,389,613,334,897,463,223
345,276,484,617,229,102,580,989,155,683,639,485,545,89,348,800,940,257,137,98
68,711,59,69,646,496,410,352,94,519,947,896,465,67,76,830,481,411,95,255
704,535,780,309,314,64,63,904,509,93,408,225,189,372,503,139,146,512,4,621
277,406,273,709,461,324,923,377,645,747,56,327,820,576,60,502,487,191,754,876
364,325,755,509,677,385,235,349,945,480,641,858,142,905,933,214,306,806,97,827
4,187,466,402,929,944,125,256,705,199,130,849,741,136,234,944,650,274,682,781
318,340,499,237,348,396,682,62,131,574,708,380,278,866,927,85,267,877,830,371
776,196,576,749,353,362,934,315,476,538,272,510,396,575,93,574,498,185,741,256
50,909,410,647,920,305,655,184,233,361,391,908,258,779,530,708,655,793,92,651
677,226,140,709,312,201,443,91,657,899,111,502,464,62,365,374,195,330,670,833
555,346,608,401,256,128,318,418,353,56,187,743,231,87,133,909,113,363,319,939
204,313,485,190,620,390,820,369,737,323,197,121,488,460,655,812,529,617,185,902
749,678,375,242,514,752,325,709,736,532,143,776,269,656,510,486,865,484,305,905
942,247,779,305,361,707,817,270,323,833,440,105,242,687,201,875,334,411,132,863
484,653,224,511,322,387,229,309,470,64,186,362,202,482,277,660,645,342,320,501
608,465,234,143,369,740,363,164,928,805,189,315,154,828,147,346,690,846,621,524
825,78,355,520,840,768,58,410,304,581,464,279,572,145,521,534,908,872,755,148
71,901,640,395,718,200,860,854,834,908,371,832,277,904,441,378,780,756,927,130
489,79,794,258,54,790,792,82,246,80,513,821,97,350,846,144,572,277,695,190
139,571,742,381,506,515,679,649,822,853,532,908,23,516,132,474,132,73,857,251
61,805,355,524,851,894,691,81,905,924,898,473,652,749,460,948,512,185,414,519
505,752,239,508,817,188,345,906,198,525,340,355,688,516,247,517,476,847,542,169
649,646,898,462,539,472,396,310,148,832,303,187,362,848,402,646,853,661,477,91
612,383,369,231,229,939,351,106,820,313,401,175,654,644,342,334,235,367,675,853
794,120,754,469,399,383,613,579,360,87,418,414,390,828,864,606,345,860,309,200
746,539,316,14,800,274,641,507,335,410,745,872,947,131,227,656,900,535,802,460
945,836,325,610,376,939,616,235,311,408,322,102,743,442,697,141,825,321,534,861
252,203,78,611,824,653,348,700,946,508,864,338,98,78,611,319,439,344,791,232
508,943,13,933,83,193,149,647,786,385,739,477,707,199,486,746,169,155,466,315
472,782,945,275,53,618,340,377,390,545,849,753,375,355,468,704,856,480,157,305
338,507,476,303,271,541,135,528,790,53,565,505,249,387,678,747,860,509,466,844
140,246,64,309,196,94,834,193,136,97,471,827,251,170,713,757,738,344,460,388
847,290,440,313,534,754,481,822,754,740,316,469,538,790,793,864,325,196,575,796
645,672,342,193,646,305,781,189,139,979,316,900,749,324,478,525,753,934,256,73
613,324,781,581,56,335,524,812,74,142,229,748,873,378,895,529,316,755,147,342
95,106,310,303,345,490,736,145,544,614,127,193,93,333,15,56,463,532,861,947
366,460,388,806,540,444,96,58,442,577,620,741,685,836,209,785,53,933,787,576
522,322,739,572,618,938,686,444,756,254,482,196,333,360,799,101,639,572,768,356
127,856,860,943,658,87,115,108,862,619,675,384,581,70,526,789,403,369,938,139
475,256,471,91,840,71,183,938,316,255,582,522,840,501,145,677,700,839,866,655
744,262,389,538,839,844,194,907,228,181,478,941,418,948,329,418,329,379,643,127
237,85,72,150,574,619,678,82,658,71,411,674,273,527,856,791,834,327,87,756
390,500,270,354,74,701,567,497,611,779,146,741,328,383,877,309,90,749,279,237
379,155,70,508,530,171,906,257,376,535,778,152,439,129,235,80,803,859,743,522
527,690,385,491,249,780,618,57,798,365,409,223,924,537,903,498,874,137,720,580
536,875,477,246,114,167,55,803,609,525,670,834,244,67,54,704,753,757,127,829
653,942,643,938,214,751,80,749,749,513,645,838,866,538,145,60,275,674,673,346
914,113,304,639,310,783,851,825,685,309,69,351,875,155,152,238,353,575,78,638
822,334,935,793,146,492,861,767,529,753,277,758,843,321,468,491,340,679,83,226
444,870,341,653,852,89,651,941,309,258,645,841,606,364,649,873,138,529,259,800
898,683,464,783,897,607,99,183,483,395,219,932,706,847,737,128,754,409,259,409
608,564,144,86,523,941,226,519,97,925,333,67,383,501,226,581,106,805,481,614
171,55,392,79,501,925,189,196,366,269,996,833,531,371,110,785,354,201,759,352
374,60,400,272,54,74,353,522,494,785,811,277,69,201,744,399,341,929,940,66
190,805,131,494,806,260,753,576,131,531,896,384,607,354,791,194,149,644,904,500
68,498,742,747,57,792,9,256,508,942,354,614,110,339,325,851,826,64,64,143
443,92,847,250,516,827,247,562,71,794,224,751,498,484,279,202,513,244,641,542
379,487,709,324,906,204,613,207,553,904,319,792,805,368,168,617,840,442,488,205
249,876,640,471,542,801,744,245,127,206,808,978,823,925,513,873,347,69,931,442
818,353,391,512,102,175,402,362,94,247,682,257,493,441,73,397,123,839,575,738
135,59,606,183,743,255,528,171,387,513,473,577,66,899,139,65,410,757,371,178
100,315,606,894,345,131,199,472,123,931,646,993,493,615,611,154,182,418,106,835
227,580,210,650,201,225,374,675,362,366,269,402,127,399,808,409,504,688,205,506
83,862,749,940,760,446,483,468,223,103,378,740,379,132,753,131,329,169,197,136

106
2020/d16/ex2/ex2.py Executable file
View file

@ -0,0 +1,106 @@
#!/usr/bin/env python
import math
import sys
from typing import Dict, List, Set, Tuple
Ranges = Dict[str, Set[int]]
Ticket = List[int]
def parse(raw: List[str]) -> Tuple[Ranges, List[Ticket]]:
def extract_field_info(line: str) -> Tuple[str, Set[int]]:
field, rest = line.split(":")
ranges: Set[int] = set()
for r in rest.strip().split(" or "):
lhs, rhs = r.split("-")
ranges |= set(range(int(lhs), int(rhs) + 1))
return field, ranges
def parse_tickets(line: str) -> Ticket:
return [int(i) for i in line.split(",")]
ranges: Ranges = {}
tickets: List[Ticket] = []
should_parse_tickets = False
for line in raw:
if line == "":
should_parse_tickets = True
continue
if "ticket" in line:
continue
if should_parse_tickets:
tickets.append(parse_tickets(line))
else:
field, field_ranges = extract_field_info(line)
ranges[field] = field_ranges
return ranges, tickets
def verify_mapping(possibilites: Dict[int, Set[str]]) -> None:
for pos in possibilites.values():
assert len(pos) == 1
def cross_eliminate(possibilites: Dict[int, Set[str]]) -> None:
while True:
eliminated = False
for pos in possibilites:
if len(possibilites[pos]) != 1:
continue
for other_pos in possibilites:
if other_pos == pos:
continue
if len(possibilites[other_pos] & possibilites[pos]) == 0:
continue
eliminated = True
possibilites[other_pos] = possibilites[other_pos] - (possibilites[pos])
if not eliminated:
break
def match_ranges(ranges: Ranges, tickets: List[Ticket]) -> Dict[int, str]:
possibilites: Dict[int, Set[str]] = {
i: set(ranges.keys()) for i in range(len(ranges))
}
def whittle_down() -> None:
for t in tickets[1:]:
for i, val in enumerate(t):
for field, valid in ranges.items():
if val in valid:
continue
possibilites[i].remove(field)
whittle_down()
cross_eliminate(possibilites)
verify_mapping(possibilites)
return {i: pos.pop() for i, pos in possibilites.items()}
def solve(raw: List[str]) -> int:
ranges, tickets = parse(raw)
def valid(t: Ticket) -> bool:
for val in t:
if not any(val in r for r in ranges.values()):
return False
return True
tickets = [t for i, t in enumerate(tickets) if i == 0 or valid(t)]
mapping = match_ranges(ranges, tickets)
return math.prod(
tickets[0][i] for i, field in mapping.items() if "departure" in field
)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

264
2020/d16/ex2/input Normal file
View file

@ -0,0 +1,264 @@
departure location: 44-709 or 728-964
departure station: 42-259 or 269-974
departure platform: 39-690 or 701-954
departure track: 49-909 or 924-965
departure date: 48-759 or 779-957
departure time: 38-115 or 121-965
arrival location: 32-808 or 818-949
arrival station: 45-418 or 439-949
arrival platform: 35-877 or 894-962
arrival track: 26-866 or 872-958
class: 32-727 or 736-969
duration: 35-446 or 460-968
price: 26-545 or 571-961
route: 35-207 or 223-960
row: 43-156 or 165-955
seat: 26-172 or 181-966
train: 49-582 or 606-952
type: 36-279 or 303-968
wagon: 26-657 or 672-959
zone: 36-621 or 637-963
your ticket:
83,127,131,137,113,73,139,101,67,53,107,103,59,149,109,61,79,71,97,89
nearby tickets:
539,619,928,309,835,99,521,478,54,340,849,859,376,357,524,841,221,935,806,147
231,827,907,526,238,542,181,853,303,143,116,701,206,140,927,203,443,753,151,258
445,679,816,617,82,102,197,100,239,490,488,78,707,349,689,335,847,183,144,314
476,833,232,489,937,256,87,409,223,364,978,939,398,331,153,945,513,237,934,272
492,927,578,788,808,529,739,20,201,688,405,877,228,168,361,521,400,398,618,520
332,694,481,571,523,516,395,122,844,358,232,132,315,486,899,154,269,201,831,50
907,706,927,126,133,97,217,334,745,751,580,862,526,845,680,125,96,445,863,322
498,753,844,670,150,657,853,150,377,487,152,369,500,241,360,204,142,236,948,91
578,675,491,230,332,464,258,858,508,330,492,780,494,234,839,645,160,795,896,687
814,875,617,185,490,490,501,940,224,751,609,844,442,525,640,609,336,251,532,685
684,196,757,841,580,576,18,319,150,249,676,337,155,115,652,638,475,398,789,379
445,490,199,140,88,694,184,247,307,386,198,85,905,860,484,244,532,224,681,251
172,936,701,440,779,941,639,351,238,70,787,91,259,340,58,541,815,399,238,202
715,369,504,226,138,866,783,231,580,147,82,335,533,144,530,462,836,751,473,801
932,459,242,947,653,150,618,683,198,608,88,342,948,497,675,53,681,544,315,615
422,244,791,929,799,128,374,473,148,931,381,822,318,853,147,367,531,412,242,470
464,899,490,846,381,326,271,948,396,318,653,981,310,822,502,895,78,935,78,461
231,339,79,530,680,461,863,521,839,517,379,108,395,613,644,751,823,212,206,151
526,507,403,354,931,859,787,728,247,781,643,203,847,326,506,79,65,332,91,783
571,182,753,841,338,746,254,307,896,648,726,89,314,706,943,464,444,481,465,928
184,513,335,941,303,198,537,571,409,337,497,621,350,617,98,897,850,679,794,260
235,255,393,310,188,65,943,543,94,374,500,482,122,992,656,523,704,742,331,792
315,152,320,983,493,166,754,376,619,480,149,929,330,80,529,131,150,57,251,842
54,77,540,141,61,205,273,214,745,145,166,131,93,525,500,521,223,52,237,404
300,616,784,250,852,354,327,944,675,859,673,941,789,829,234,104,842,85,742,98
110,244,95,93,529,162,82,309,142,680,65,410,531,758,511,790,333,352,926,397
496,518,828,896,52,828,805,62,470,121,853,831,346,654,684,196,535,15,251,381
231,444,530,616,795,620,78,460,947,748,757,78,706,336,82,317,186,256,216,196
520,838,365,445,928,855,418,943,195,689,176,638,151,59,82,495,58,681,737,545
172,755,782,71,514,336,383,470,168,70,168,199,307,102,793,250,739,174,368,279
897,734,446,184,254,785,499,949,903,405,401,679,356,753,354,351,842,443,207,203
60,577,746,229,105,475,640,877,848,477,545,525,793,752,313,315,318,983,537,249
474,833,611,169,61,800,759,228,321,833,303,673,513,862,76,122,803,520,67,667
504,919,413,521,514,251,785,170,656,759,510,537,579,462,794,756,687,479,864,507
949,774,866,805,357,442,183,874,934,195,511,742,756,683,396,407,637,348,866,344
687,305,781,780,821,586,945,94,87,230,353,376,849,379,510,368,709,489,113,191
275,356,277,655,529,493,541,141,132,804,620,171,382,443,483,978,737,536,532,904
357,369,142,383,802,782,722,391,905,684,226,413,379,74,792,618,351,939,580,578
368,394,514,461,445,933,677,324,318,250,863,266,855,703,781,142,460,74,753,947
935,852,127,241,309,825,481,206,642,81,375,862,330,21,496,60,677,238,532,138
258,680,336,136,640,193,372,100,227,856,495,103,92,341,356,703,568,147,311,514
412,673,398,244,397,313,378,780,107,905,318,208,172,374,464,690,379,686,538,638
660,321,894,681,515,539,486,403,469,91,675,186,386,839,197,639,411,873,69,837
845,413,996,87,314,674,362,258,783,412,341,529,519,654,526,757,899,617,909,492
127,749,682,785,735,418,112,834,934,381,613,107,748,474,84,72,514,355,942,701
541,100,75,155,645,410,612,519,976,656,854,140,61,140,401,827,466,798,385,192
332,126,836,373,545,313,379,69,345,751,348,750,746,643,763,519,943,508,679,274
642,521,55,479,54,615,323,247,736,80,979,489,97,238,759,579,363,826,91,929
227,497,467,249,808,441,906,361,815,523,206,352,383,521,798,84,360,74,680,100
96,486,465,382,796,198,500,717,462,617,245,247,649,941,946,750,408,845,637,311
379,168,181,100,507,798,928,784,174,128,830,480,113,311,379,474,361,613,909,325
130,144,649,305,273,637,112,353,528,786,944,866,931,269,381,271,153,902,552,129
520,908,58,249,842,831,756,253,21,238,645,607,902,200,439,100,112,324,374,672
614,173,149,316,132,309,484,270,249,104,542,524,350,357,244,331,507,405,793,345
943,140,784,620,818,558,780,53,894,673,500,370,109,539,372,376,505,785,909,782
900,187,113,464,991,534,368,181,463,841,747,362,945,640,153,227,241,944,833,743
863,838,340,366,230,500,643,103,772,127,88,754,611,496,791,444,440,903,75,467
649,828,617,466,188,502,315,352,866,758,919,247,835,574,750,409,468,247,359,202
371,846,121,755,474,472,176,325,153,97,949,201,65,171,908,500,277,937,90,388
929,392,539,469,843,440,947,893,347,312,128,63,754,685,947,227,679,470,945,303
731,77,872,620,88,616,104,681,204,312,115,688,386,195,676,506,87,707,519,149
278,365,780,785,874,251,114,321,499,898,729,101,637,684,167,797,826,930,615,51
319,924,819,856,202,71,102,55,838,81,231,150,656,840,354,679,744,475,344,814
926,657,378,507,927,389,680,238,185,319,475,897,132,936,685,540,16,331,508,613
681,897,228,303,835,356,523,403,314,709,382,272,370,109,470,479,923,443,896,782
677,239,501,233,180,928,351,101,373,151,321,347,445,198,112,679,828,751,680,96
840,497,237,318,490,848,248,351,413,850,945,662,460,945,439,929,126,199,330,320
647,489,508,105,648,253,270,807,201,110,537,12,336,369,581,609,190,535,676,489
534,668,686,442,938,394,798,755,190,412,505,375,101,752,490,405,875,573,417,677
231,461,260,138,611,824,333,331,406,351,229,97,756,926,678,849,488,758,230,121
82,347,442,172,652,898,687,491,392,539,538,389,257,505,334,325,840,89,918,138
517,352,192,701,848,617,804,704,344,785,58,839,351,140,394,242,144,342,179,142
166,140,226,442,183,499,166,272,839,795,908,165,901,703,262,91,358,127,872,834
788,157,156,675,876,376,473,404,709,752,373,780,324,146,169,819,807,337,514,204
190,511,822,204,495,948,123,117,932,509,148,706,66,110,861,674,637,545,486,855
119,227,439,442,808,378,929,949,313,142,359,789,503,442,908,310,315,474,395,935
367,210,531,480,142,245,833,172,320,137,468,800,827,930,199,318,904,642,516,865
538,198,113,62,362,528,787,668,936,657,184,345,895,236,385,829,522,253,758,352
315,708,796,639,162,690,688,750,366,171,509,476,708,782,637,368,934,125,73,248
617,156,576,737,521,755,932,266,939,203,690,578,853,98,414,50,759,440,819,331
593,232,442,468,578,949,383,129,800,152,77,386,935,819,925,470,305,396,308,874
102,361,319,187,226,942,493,272,247,68,475,364,398,141,821,900,56,480,814,307
650,796,98,92,687,646,128,140,168,813,203,825,851,80,136,473,581,150,865,806
263,520,275,378,406,113,59,194,759,128,522,183,498,167,185,702,652,606,133,578
707,331,737,748,820,759,257,742,856,500,318,814,507,898,244,153,470,319,532,110
488,382,380,145,126,807,359,343,606,82,750,194,607,981,409,151,860,862,339,900
873,620,230,924,345,750,62,387,802,113,97,930,63,416,750,76,657,507,260,325
111,749,114,785,477,572,248,687,500,64,925,931,132,783,795,491,998,248,754,56
115,83,245,512,638,327,108,451,826,757,675,521,342,350,102,462,348,841,874,798
941,822,582,948,500,645,393,757,214,362,103,132,181,515,227,828,827,406,375,232
647,362,660,738,497,366,803,505,335,105,75,153,313,759,501,241,62,149,748,926
123,146,613,390,742,638,907,515,334,686,411,854,933,469,174,126,169,395,842,351
830,315,59,573,843,656,523,533,528,403,259,141,523,333,876,355,880,680,134,942
234,22,808,145,529,374,142,572,344,409,607,930,858,825,804,223,534,505,466,539
684,688,940,524,357,684,844,673,381,794,895,516,308,582,380,487,731,241,797,685
196,112,331,528,533,396,489,579,266,496,77,440,650,165,399,469,475,507,364,56
354,139,945,330,742,894,782,989,87,231,54,358,51,681,350,652,936,745,134,936
804,439,935,234,944,849,186,173,254,690,326,102,149,926,115,792,829,167,508,746
388,684,243,814,80,350,637,335,442,146,474,825,477,686,578,331,269,378,472,828
826,863,520,70,279,522,801,579,500,237,696,534,242,259,932,540,182,544,72,701
886,227,369,89,612,147,488,152,511,646,104,853,352,94,741,223,858,150,383,680
792,51,440,64,838,116,195,674,70,902,829,779,682,404,808,860,619,466,807,836
652,499,177,830,104,674,377,128,787,123,153,782,230,237,526,478,273,523,92,85
418,364,405,327,502,538,539,278,372,508,245,306,325,488,548,674,97,135,944,906
409,996,83,929,461,485,829,384,171,844,933,755,780,860,491,331,473,541,874,142
390,92,141,310,747,142,653,498,203,829,946,393,142,251,360,22,804,385,240,167
874,255,324,340,562,529,366,190,100,480,109,171,947,491,188,154,680,404,275,486
945,947,61,110,500,920,875,248,352,56,475,949,876,686,745,443,171,821,348,645
705,498,139,798,369,418,666,124,227,578,530,376,607,122,613,87,101,50,930,129
475,235,549,581,610,820,206,96,901,802,128,818,413,542,151,362,401,474,76,331
506,608,462,708,980,838,582,803,56,503,83,258,384,925,171,874,152,823,170,89
517,606,475,644,105,195,846,445,323,619,498,183,310,79,493,155,90,533,259,218
63,619,373,850,902,90,153,542,269,330,94,357,797,203,909,201,776,615,606,340
501,342,74,394,94,212,401,475,877,72,519,128,148,640,859,68,525,54,358,904
875,821,377,781,823,781,398,619,945,130,930,750,802,752,704,439,1,645,337,309
533,830,474,829,98,613,896,744,512,126,248,511,113,250,66,515,585,128,877,259
201,858,793,791,828,471,859,581,899,76,836,738,259,155,816,360,474,414,277,835
5,324,784,71,677,617,745,808,184,56,478,682,578,310,390,330,656,872,305,684
508,686,519,385,245,759,766,136,898,128,332,205,276,58,60,252,906,167,737,169
799,650,674,67,181,243,155,254,785,208,934,197,835,350,76,865,516,248,837,503
361,90,874,251,310,733,155,60,69,276,325,370,330,149,62,397,519,704,823,345
186,256,497,252,75,880,516,278,172,381,61,357,358,115,858,202,512,375,836,247
465,324,828,443,518,708,781,895,122,334,161,759,517,356,616,399,65,796,127,236
792,170,109,461,141,928,758,201,101,114,739,153,108,675,938,512,177,330,580,943
92,407,385,278,92,723,333,757,936,373,90,788,388,505,738,609,826,321,153,858
350,780,492,311,414,306,702,252,257,782,837,823,137,166,988,648,186,781,613,789
83,341,408,537,607,483,948,122,349,757,144,81,945,757,758,474,370,651,947,567
110,689,77,706,383,353,395,187,399,402,186,223,816,373,112,530,908,327,531,851
492,137,785,209,610,392,791,411,523,198,377,386,225,236,344,837,491,781,393,579
233,172,271,138,875,789,512,81,63,406,479,232,122,704,895,946,448,136,684,949
351,238,909,505,96,523,192,444,491,259,313,345,100,530,116,257,532,646,103,675
642,149,898,346,487,470,896,358,493,674,275,461,503,572,443,787,839,905,499,117
306,947,308,523,334,467,127,782,389,835,448,862,895,482,614,278,252,402,641,336
232,368,805,944,138,86,143,499,644,60,320,942,89,533,489,71,782,927,327,17
141,672,108,175,844,378,843,647,223,372,140,109,705,785,407,843,795,400,182,310
253,684,377,93,409,606,688,23,476,51,709,828,860,736,156,75,483,169,441,92
519,312,95,899,115,949,818,308,119,611,206,372,643,524,63,757,89,538,783,801
577,872,902,510,51,239,278,541,576,235,780,475,758,321,350,575,117,324,83,410
932,796,508,832,894,392,314,90,58,13,478,440,942,818,145,271,736,475,181,937
113,737,758,182,145,454,332,66,52,488,545,129,500,126,509,703,306,137,534,618
928,900,799,575,417,254,903,373,803,803,263,313,365,100,894,250,842,799,929,128
69,705,638,72,321,814,610,397,926,902,67,499,122,508,74,744,825,746,183,410
926,316,324,483,348,356,544,945,865,538,380,508,76,758,506,380,326,640,118,824
832,340,786,225,704,206,508,535,843,347,326,120,620,473,650,247,100,238,309,337
677,581,526,334,677,705,266,60,367,485,646,88,252,104,752,509,908,486,684,377
55,861,490,521,265,182,339,876,575,242,782,153,673,495,256,534,360,346,233,361
446,126,228,876,991,351,271,499,239,831,618,708,935,256,704,904,129,131,227,850
219,642,394,413,129,276,843,701,619,349,242,247,608,320,824,864,894,536,701,255
544,642,256,128,379,279,307,523,256,75,410,536,357,785,806,790,663,826,642,392
311,337,896,352,315,538,786,271,370,54,129,89,946,837,71,519,715,818,76,270
871,638,385,795,238,63,645,226,388,337,128,270,679,839,846,516,314,607,616,475
94,794,188,392,490,73,144,908,504,139,182,573,844,391,947,333,528,549,782,384
758,517,808,637,347,836,105,610,643,852,55,719,581,646,74,362,396,410,141,337
949,749,745,848,187,51,350,497,165,543,929,321,245,945,272,121,396,810,198,108
407,54,341,519,926,801,73,397,606,524,385,470,413,346,670,80,279,360,901,392
794,139,837,745,834,380,701,312,463,705,151,313,682,168,866,1,703,500,476,202
544,892,621,354,924,134,736,793,338,872,346,80,823,675,121,97,801,464,508,58
370,538,474,641,171,189,342,381,94,145,999,384,383,400,645,866,513,140,618,97
230,621,616,240,675,414,933,22,362,828,618,926,486,393,895,88,110,230,528,940
483,852,446,339,512,684,582,200,896,862,979,353,319,610,145,374,581,446,750,252
157,648,683,439,460,224,357,135,279,69,899,154,75,515,321,349,115,657,156,189
414,794,652,930,397,440,655,306,484,512,342,861,344,902,100,860,513,976,66,388
405,932,488,444,745,870,528,446,657,188,863,689,475,56,708,476,325,757,336,638
456,783,396,84,237,107,443,645,106,652,304,337,110,477,134,899,145,410,709,544
334,865,677,708,642,660,343,83,945,855,899,529,704,877,675,199,639,342,337,848
490,855,851,784,119,652,489,416,349,538,705,439,736,537,751,312,152,273,307,95
696,125,500,754,90,516,681,533,902,226,97,377,57,322,312,191,384,794,109,196
195,50,197,253,339,992,502,168,402,107,757,137,247,62,275,855,245,231,645,86
638,316,191,524,699,821,898,205,102,98,375,279,376,97,82,582,233,386,347,242
177,369,248,754,803,270,927,382,305,532,854,854,614,355,746,356,484,253,388,406
844,896,376,832,385,757,755,930,376,509,353,569,255,442,166,312,498,894,394,738
362,591,803,532,678,527,517,852,345,440,832,948,403,673,96,228,861,909,840,412
484,817,196,102,476,352,232,742,359,367,609,82,207,201,520,521,233,940,384,480
906,329,207,67,510,71,98,920,857,384,77,247,571,388,121,387,147,241,894,478
390,530,97,924,187,681,120,69,151,226,239,750,945,399,389,613,334,897,463,223
345,276,484,617,229,102,580,989,155,683,639,485,545,89,348,800,940,257,137,98
68,711,59,69,646,496,410,352,94,519,947,896,465,67,76,830,481,411,95,255
704,535,780,309,314,64,63,904,509,93,408,225,189,372,503,139,146,512,4,621
277,406,273,709,461,324,923,377,645,747,56,327,820,576,60,502,487,191,754,876
364,325,755,509,677,385,235,349,945,480,641,858,142,905,933,214,306,806,97,827
4,187,466,402,929,944,125,256,705,199,130,849,741,136,234,944,650,274,682,781
318,340,499,237,348,396,682,62,131,574,708,380,278,866,927,85,267,877,830,371
776,196,576,749,353,362,934,315,476,538,272,510,396,575,93,574,498,185,741,256
50,909,410,647,920,305,655,184,233,361,391,908,258,779,530,708,655,793,92,651
677,226,140,709,312,201,443,91,657,899,111,502,464,62,365,374,195,330,670,833
555,346,608,401,256,128,318,418,353,56,187,743,231,87,133,909,113,363,319,939
204,313,485,190,620,390,820,369,737,323,197,121,488,460,655,812,529,617,185,902
749,678,375,242,514,752,325,709,736,532,143,776,269,656,510,486,865,484,305,905
942,247,779,305,361,707,817,270,323,833,440,105,242,687,201,875,334,411,132,863
484,653,224,511,322,387,229,309,470,64,186,362,202,482,277,660,645,342,320,501
608,465,234,143,369,740,363,164,928,805,189,315,154,828,147,346,690,846,621,524
825,78,355,520,840,768,58,410,304,581,464,279,572,145,521,534,908,872,755,148
71,901,640,395,718,200,860,854,834,908,371,832,277,904,441,378,780,756,927,130
489,79,794,258,54,790,792,82,246,80,513,821,97,350,846,144,572,277,695,190
139,571,742,381,506,515,679,649,822,853,532,908,23,516,132,474,132,73,857,251
61,805,355,524,851,894,691,81,905,924,898,473,652,749,460,948,512,185,414,519
505,752,239,508,817,188,345,906,198,525,340,355,688,516,247,517,476,847,542,169
649,646,898,462,539,472,396,310,148,832,303,187,362,848,402,646,853,661,477,91
612,383,369,231,229,939,351,106,820,313,401,175,654,644,342,334,235,367,675,853
794,120,754,469,399,383,613,579,360,87,418,414,390,828,864,606,345,860,309,200
746,539,316,14,800,274,641,507,335,410,745,872,947,131,227,656,900,535,802,460
945,836,325,610,376,939,616,235,311,408,322,102,743,442,697,141,825,321,534,861
252,203,78,611,824,653,348,700,946,508,864,338,98,78,611,319,439,344,791,232
508,943,13,933,83,193,149,647,786,385,739,477,707,199,486,746,169,155,466,315
472,782,945,275,53,618,340,377,390,545,849,753,375,355,468,704,856,480,157,305
338,507,476,303,271,541,135,528,790,53,565,505,249,387,678,747,860,509,466,844
140,246,64,309,196,94,834,193,136,97,471,827,251,170,713,757,738,344,460,388
847,290,440,313,534,754,481,822,754,740,316,469,538,790,793,864,325,196,575,796
645,672,342,193,646,305,781,189,139,979,316,900,749,324,478,525,753,934,256,73
613,324,781,581,56,335,524,812,74,142,229,748,873,378,895,529,316,755,147,342
95,106,310,303,345,490,736,145,544,614,127,193,93,333,15,56,463,532,861,947
366,460,388,806,540,444,96,58,442,577,620,741,685,836,209,785,53,933,787,576
522,322,739,572,618,938,686,444,756,254,482,196,333,360,799,101,639,572,768,356
127,856,860,943,658,87,115,108,862,619,675,384,581,70,526,789,403,369,938,139
475,256,471,91,840,71,183,938,316,255,582,522,840,501,145,677,700,839,866,655
744,262,389,538,839,844,194,907,228,181,478,941,418,948,329,418,329,379,643,127
237,85,72,150,574,619,678,82,658,71,411,674,273,527,856,791,834,327,87,756
390,500,270,354,74,701,567,497,611,779,146,741,328,383,877,309,90,749,279,237
379,155,70,508,530,171,906,257,376,535,778,152,439,129,235,80,803,859,743,522
527,690,385,491,249,780,618,57,798,365,409,223,924,537,903,498,874,137,720,580
536,875,477,246,114,167,55,803,609,525,670,834,244,67,54,704,753,757,127,829
653,942,643,938,214,751,80,749,749,513,645,838,866,538,145,60,275,674,673,346
914,113,304,639,310,783,851,825,685,309,69,351,875,155,152,238,353,575,78,638
822,334,935,793,146,492,861,767,529,753,277,758,843,321,468,491,340,679,83,226
444,870,341,653,852,89,651,941,309,258,645,841,606,364,649,873,138,529,259,800
898,683,464,783,897,607,99,183,483,395,219,932,706,847,737,128,754,409,259,409
608,564,144,86,523,941,226,519,97,925,333,67,383,501,226,581,106,805,481,614
171,55,392,79,501,925,189,196,366,269,996,833,531,371,110,785,354,201,759,352
374,60,400,272,54,74,353,522,494,785,811,277,69,201,744,399,341,929,940,66
190,805,131,494,806,260,753,576,131,531,896,384,607,354,791,194,149,644,904,500
68,498,742,747,57,792,9,256,508,942,354,614,110,339,325,851,826,64,64,143
443,92,847,250,516,827,247,562,71,794,224,751,498,484,279,202,513,244,641,542
379,487,709,324,906,204,613,207,553,904,319,792,805,368,168,617,840,442,488,205
249,876,640,471,542,801,744,245,127,206,808,978,823,925,513,873,347,69,931,442
818,353,391,512,102,175,402,362,94,247,682,257,493,441,73,397,123,839,575,738
135,59,606,183,743,255,528,171,387,513,473,577,66,899,139,65,410,757,371,178
100,315,606,894,345,131,199,472,123,931,646,993,493,615,611,154,182,418,106,835
227,580,210,650,201,225,374,675,362,366,269,402,127,399,808,409,504,688,205,506
83,862,749,940,760,446,483,468,223,103,378,740,379,132,753,131,329,169,197,136

66
2020/d17/ex1/ex1.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
import itertools
import sys
from typing import Iterator, Set, Tuple
Point = Tuple[int, int, int]
Grid = Set[Point]
def update(grid: Grid) -> Grid:
def neightbours(p: Point) -> Iterator[Point]:
for dx, dy, dz in itertools.product(range(-1, 2), repeat=3):
if dx == 0 and dy == 0 and dz == 0:
continue
yield p[0] + dx, p[1] + dy, p[2] + dz
def count_neighbours(p: Point) -> int:
return sum(n in grid for n in neightbours(p))
new_grid: Grid = set()
seen: Set[Point] = set()
for p in grid:
for n in itertools.chain(neightbours(p), [p]):
if n in seen:
continue
seen |= {n}
active = n in grid
num_neighbours = count_neighbours(n)
if active and num_neighbours in [2, 3]:
new_grid |= {n}
elif active:
continue
elif num_neighbours == 3:
new_grid |= {n}
else:
continue
return new_grid
def solve(grid: Grid) -> int:
for __ in range(6):
grid = update(grid)
return len(grid)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(
solve(
{
(i, j, 0)
for i, line in enumerate(input)
for j, x in enumerate(line)
if x == "#"
}
)
)
if __name__ == "__main__":
main()

8
2020/d17/ex1/input Normal file
View file

@ -0,0 +1,8 @@
######.#
#.###.#.
###.....
#.####..
##.#.###
.######.
###.####
######.#

66
2020/d17/ex2/ex2.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
import itertools
import sys
from typing import Iterator, Set, Tuple
Point = Tuple[int, int, int, int]
Grid = Set[Point]
def update(grid: Grid) -> Grid:
def neightbours(p: Point) -> Iterator[Point]:
for dx, dy, dz, dw in itertools.product(range(-1, 2), repeat=4):
if dx == 0 and dy == 0 and dz == 0 and dw == 0:
continue
yield p[0] + dx, p[1] + dy, p[2] + dz, p[3] + dw
def count_neighbours(p: Point) -> int:
return sum(n in grid for n in neightbours(p))
new_grid: Grid = set()
seen: Set[Point] = set()
for p in grid:
for n in itertools.chain(neightbours(p), [p]):
if n in seen:
continue
seen |= {n}
active = n in grid
num_neighbours = count_neighbours(n)
if active and num_neighbours in [2, 3]:
new_grid |= {n}
elif active:
continue
elif num_neighbours == 3:
new_grid |= {n}
else:
continue
return new_grid
def solve(grid: Grid) -> int:
for __ in range(6):
grid = update(grid)
return len(grid)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(
solve(
{
(i, j, 0, 0)
for i, line in enumerate(input)
for j, x in enumerate(line)
if x == "#"
}
)
)
if __name__ == "__main__":
main()

8
2020/d17/ex2/input Normal file
View file

@ -0,0 +1,8 @@
######.#
#.###.#.
###.....
#.####..
##.#.###
.######.
###.####
######.#

72
2020/d18/ex1/ex1.py Executable file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env python
import sys
from typing import Callable, Dict, List
"""
E : G [ (+|*) G ]*
G : '(' E ')' | CONSTANT
"""
def parse_g(expr: List[str]) -> int:
top = expr.pop(0)
if top == "(":
ans = parse_e(expr)
assert expr.pop(0) == ")"
return ans
return int(top)
def parse_e(expr: List[str]) -> int:
ops: Dict[str, Callable[[int, int], int]] = {
"*": lambda lhs, rhs: lhs * rhs,
"+": lambda lhs, rhs: lhs + rhs,
}
lhs = parse_g(expr)
while len(expr) and expr[0] in ["+", "*"]:
op = expr.pop(0)
rhs = parse_g(expr)
lhs = ops[op](lhs, rhs)
return lhs
def parse_infix(input: List[str]) -> int:
"""
Parses the given string in infix notation.
"""
ans = parse_e(input)
assert len(input) == 0
return ans
def tokenize(expr: str) -> List[str]:
res = []
def split_tok(tok: str) -> None:
if "(" not in tok and ")" not in tok:
res.append(tok)
if "(" in tok:
res.append("(")
split_tok(tok[1:])
if ")" in tok:
split_tok(tok[:-1])
res.append(")")
for tok in expr.split():
split_tok(tok)
return res
def solve(raw: List[str]) -> int:
return sum(parse_infix(tokenize(expr)) for expr in raw)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

377
2020/d18/ex1/input Normal file
View file

@ -0,0 +1,377 @@
(5 * 7 * 5) * 6 * 5 + 7 + 6 * 4
(2 + 3 + (2 + 8) * 3 + (7 + 4)) * 3 + 7
2 + 4 * (2 + 2 * (9 + 2 + 6 + 3 + 6) + 4)
4 * 3
9 + (8 * 5 * 5 * 4 * (3 * 5) * 2) + 4 + 4
5 + 5 + 2 * 4 + 4
7 + 9 * 2 + 2 * 3
5 + 8 + 5 * (6 * 8 * (9 * 2 + 2 + 7 + 4 + 2) + 4 * 6) * 5
8 * 7 * 4 * 5 + 3
(9 * 9 + 9 * 7 * 4) + 9 + 5 * (5 + (8 * 8) * (2 * 8) *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2/ex2.py Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env python
import sys
from typing import Callable, Dict, List
"""
E : T [ * T ]*
T : G [ + G ]*
G : '(' E ')' | CONSTANT
"""
def parse_g(expr: List[str]) -> int:
top = expr.pop(0)
if top == "(":
ans = parse_e(expr)
assert expr.pop(0) == ")"
return ans
return int(top)
def parse_t(expr: List[str]) -> int:
lhs = parse_g(expr)
while len(expr) and expr[0] == "+":
expr.pop(0)
rhs = parse_g(expr)
lhs += rhs
return lhs
def parse_e(expr: List[str]) -> int:
lhs = parse_t(expr)
while len(expr) and expr[0] == "*":
expr.pop(0)
rhs = parse_t(expr)
lhs *= rhs
return lhs
def parse_infix(input: List[str]) -> int:
"""
Parses the given string in infix notation.
"""
ans = parse_e(input)
assert len(input) == 0
return ans
def tokenize(expr: str) -> List[str]:
res = []
def split_tok(tok: str) -> None:
if "(" not in tok and ")" not in tok:
res.append(tok)
if "(" in tok:
res.append("(")
split_tok(tok[1:])
if ")" in tok:
split_tok(tok[:-1])
res.append(")")
for tok in expr.split():
split_tok(tok)
return res
def solve(raw: List[str]) -> int:
return sum(parse_infix(tokenize(expr)) for expr in raw)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

377
2020/d18/ex2/input Normal file
View file

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

48
2020/d19/ex1/ex1.py Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env python
import itertools
import re
import sys
from typing import Dict, List
def parse_rule(raw_rules: List[str]) -> str:
parsed: Dict[int, str] = {}
rules = {int(num): rule.strip() for num, rule in (i.split(":") for i in raw_rules)}
for n, r in rules.items():
if '"' not in r:
continue
parsed[n] = r.replace('"', "")
while 0 not in parsed:
for num in parsed:
if num not in rules:
continue
rules.pop(num)
for num, r in rules.items():
nums = list(reversed(sorted(map(int, re.findall("(\\d+)", r)))))
if all(n in parsed for n in nums):
for n in nums:
r = re.sub(str(n), parsed[n], r) # Bigger numbers replaced first
r = r.replace(" ", "")
parsed[num] = "(" + r + ")"
return parsed[0]
def solve(raw: List[str]) -> int:
pattern = re.compile(parse_rule(list(itertools.takewhile(len, raw))))
return sum(
pattern.fullmatch(line) is not None for line in itertools.dropwhile(len, raw)
)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

561
2020/d19/ex1/input Normal file
View file

@ -0,0 +1,561 @@
102: 100 47 | 76 84
23: 60 47 | 73 84
132: 17 47 | 81 84
108: 55 100
18: 116 47 | 26 84
103: 84 115 | 47 81
65: 84 113 | 47 50
128: 107 47 | 125 84
14: 84 100 | 47 107
118: 47 17 | 84 57
2: 47 100 | 84 40
28: 63 84 | 74 47
22: 102 84 | 123 47
123: 84 74
19: 3 47 | 13 84
24: 74 47 | 81 84
115: 55 55
90: 92 47 | 44 84
48: 84 94 | 47 96
109: 17 84 | 100 47
92: 84 75 | 47 108
66: 38 47 | 125 84
83: 66 47 | 108 84
31: 121 84 | 77 47
29: 47 61 | 84 111
45: 47 47 | 47 84
59: 47 49 | 84 43
37: 47 30 | 84 95
36: 107 84 | 125 47
82: 74 84 | 38 47
61: 84 10 | 47 110
79: 47 28 | 84 109
33: 101 47 | 133 84
12: 45 47 | 63 84
91: 122 84 | 93 47
122: 65 47 | 52 84
21: 57 84 | 115 47
8: 42
67: 102 47 | 64 84
39: 113 84 | 81 47
41: 84 124 | 47 10
50: 47 47 | 84 84
17: 47 84 | 84 84
120: 98 84 | 78 47
113: 55 47 | 47 84
20: 84 128 | 47 104
7: 84 1 | 47 20
51: 84 113 | 47 81
56: 84 83 | 47 69
131: 84 127 | 47 97
0: 8 11
5: 47 63 | 84 125
94: 15 84 | 127 47
121: 99 47 | 27 84
119: 47 115 | 84 57
129: 47 80 | 84 131
15: 47 100 | 84 45
35: 84 50 | 47 76
95: 47 115 | 84 107
68: 127 84 | 51 47
124: 84 107
75: 50 55
57: 47 84 | 84 55
13: 47 33 | 84 129
53: 106 47 | 59 84
106: 16 84 | 118 47
89: 84 125 | 47 45
104: 45 84 | 76 47
99: 47 56 | 84 7
78: 84 74 | 47 81
64: 17 47 | 115 84
32: 50 84 | 40 47
1: 47 24 | 84 72
47: "a"
80: 114 47 | 109 84
88: 47 119 | 84 132
105: 47 125 | 84 100
6: 68 84 | 67 47
110: 76 84 | 63 47
38: 84 84 | 84 47
49: 47 63 | 84 76
26: 55 107
81: 47 84
74: 84 47
96: 84 89 | 47 117
77: 47 86 | 84 71
135: 32 84 | 2 47
133: 47 15 | 84 128
42: 19 84 | 62 47
30: 47 100 | 84 74
27: 6 47 | 91 84
63: 84 55 | 47 47
62: 84 87 | 47 23
76: 84 84
4: 84 135 | 47 54
60: 41 47 | 37 84
100: 47 47 | 84 47
85: 47 112 | 84 18
116: 125 84 | 63 47
134: 57 47 | 115 84
34: 52 47 | 25 84
40: 47 47
111: 58 84 | 126 47
3: 29 47 | 130 84
114: 17 84 | 107 47
52: 47 45 | 84 74
10: 47 100 | 84 81
98: 47 76 | 84 100
112: 84 82 | 47 103
72: 40 47 | 45 84
126: 50 84 | 113 47
107: 84 47 | 47 84
11: 42 31
55: 84 | 47
54: 12 84 | 5 47
130: 34 47 | 70 84
84: "b"
127: 81 47 | 17 84
87: 84 53 | 47 9
101: 105 84 | 14 47
9: 88 84 | 120 47
73: 47 79 | 84 22
97: 74 84 | 50 47
117: 74 47
70: 47 134 | 84 46
58: 47 50 | 84 115
125: 47 47 | 55 84
46: 47 81 | 84 17
86: 84 90 | 47 85
25: 38 84 | 63 47
69: 39 47 | 78 84
43: 47 100 | 84 125
93: 84 66 | 47 35
44: 47 21 | 84 36
16: 57 47 | 107 84
71: 48 84 | 4 47
babaaabbbababababbbbabbaabbaabaa
babaaaabaaaaababbbbaaaaa
abbabaabbaaabababaabbbbabbbbbaabbbbabababaaaabbbbababbbb
bbbabababbabbbabbbabbbbb
babaabbbababbbabaabaaaaa
abbabaabbaababbabababbbababbbabbabbabbbabbaabbbb
aaaaabaabbbbbaabbbbbbbbbbaaabbaaabbaabab
baababbabbbabbaaaaaababbaabbababbbabbbbb
aaabaaaabbabbbabbabaabbbabaabbbbaaaaabaaaabaabaaababaabbabbaaaabbbbaabbabbabaaaaaaaabaab
ababaaabababbbababaaabab
bbbbabbbbbaabaaaaaabbbbbbabbbabaabbaaababbbaaaaababaabaabaabababbabbbabbabaaabbaaabbaaaa
babaabaaababaaabaaaababa
aabaaabbaabbbabbabaabaab
bbbaabaaaabaaabbbaaabbbabbbaaabb
aaaaaaabaaababbbbbbbbbbbbaaabaabbaaabbab
bbabbabbaaaaabababaababa
babbababbbabbaababaababbaaaaabaaabbbabba
bbbbbbbababbaaaaabaaabbaabbaaaab
bbbbbaaabbbbbaaaaaabaaaabbbaaabb
babbababaababbbbbbbaaabb
abaabbaabbababaabbababba
abaaabbaaabaabbbabababba
babaaaabaaaababbabbbbaaa
bbbbbbbabaababbaaaaababbabbaabbabbbaabaababaabbbbbbaabab
aaabbabbbaabababbaabaaba
bbbababbabaabbabbbabaaaa
baabbabababaaaabbbbbbaab
bbabbbbabaababbabbbaabab
abaabbabbbabbabbabbbabba
bbbbbbbaaababaaabbaabbbabbaaabbbbabababb
aabbaaabbabbabaaaabbabaababbbaababaabababaaabbaa
aaabaababbbabbbbaaababbbbaaabbbb
aaaaaaaaaaabaaaababbabbb
bbbabbbbaabaababaabbabab
baaabaabbaaaabbbbaaaaaaa
bbbbbbbaabbabbaabaabaaaa
aaaaabaabbabbaaaaaaaaabb
aabaaabbaabbabaaabbabaabbaababaaabbbaaaaababbaabaaabbaaabbaaabaa
bababbbaaabaababbbababaabbaabaabbaaaabbabbaabababbbabbbababbabbb
abbbaababbaabaaaaababbbaaaabbbaa
aababbbaaaabaabbbbabaaaa
aaaaabbaaabaaabbbababaaa
bbbababaaabaaaabbabbabaabbababababababbbabbaaaaabbababbabbbbabbbabbbaabb
bbbabababbbabababababbbb
bbaaababbbabbbbaabbbbbaa
bbababaabaaaabbaabbbbaaa
bbbbabbababbbbaabbaaaababbababbaabaaabababbabbabbbbbbaababbbbabbbbaaaaabbbaabbba
abbabbabbbbbbaabaaaaabababaaaaabaaabbaaaabababba
bbbabaabaababaaabaabbaaa
bbababbbbaaababaaaabbabbaaabbbaa
aabbbbababaabbaabababbaa
aaabbabbbaabbbabbbbbbbbabaaaabbaaabababaabaaabab
aaaaaaababbabbabbabaaaaa
aababaaaaaababbbabbabbabaaababbbbbabbababababaaaabbabbbb
babaabbbbaaabaaabbbabbab
bbbbabbbbaabbbabbbaabbbaabbbbbaabbbbaaabbbbaabbbbaababbaaaabaaaabbabbabbabbaabbb
aaabbbabbaaabaabbaaaaabaabababab
abbababbabbbbbabbaabbbabaaababbbbbbbabaababbbbbabababbbb
bbaabbbaaaaababaaabaaaabbbbbbaabbaaaabbaabaaabaabaaaabbabbabbbaabbaaaaaa
abbabbaaaabaaaabbbbbbaabbabaababbbbabbba
bbaaaabaabbababbbbaabbaa
aabbaabaabbaaabbaaabaaaaaaababbabababbaa
baaaabbaaaaaabbbbabbababbaabbbbabbabbabbaabbaabb
babbaaaabbaabaaabbbbaaaabbbabbaaaaaaaabb
aaaaababaaabbabbababbabb
abbabaaaaaabaababbabaaab
aaabaababbaabbbaababbabb
babbabaabaababbabbabaabb
abbabbaabbabbbabababaaaa
bbabbbaaaababaaaaaabbbaa
bbbbbbbaaaaaabbabbbaabaaaaabbaaa
bbbaabaababaaabbaababbabaababaabbbababba
bbaaabbaabaabbbbbbbaababbbaabaabaaabaababaaaaabbbaaabaababaaaaabaabbbbaabaabbbaa
baabbababbaaaaababaabbabaabbbaabaabbaabbabbbaaababbaaaab
bbabaaaaaaaabababaabbababbaabbbbabbbaaababbaababaabaaaaaaaabaabb
baaaaaabbaababbaababaaaa
bbbabbbbbbaabaabbaaabbab
babbbabababaaaabaabbaaabbbabaabababbbaaabaababbbbbaababbbabbbabb
aabaaababababababaabbbababbababbbabbaabb
bbaabaaabbaabababbaababaabbabbba
bbbabaaaababaabbaabbabbbbabbaabaabbabaabbaabaabaabbaabbabaaabaaa
abbaaabbbbbbbbbbaaabbaab
baabbbbbaabbaabbaabbababbaabaaba
baaaabaaabbbbaabaabbabbbbaababbb
abbbbbbaabbbbbbbbbbbbaaaaaaabaaa
abbbbbbbbbabbbaabbbaaabaaabababa
aababbbaabbabaabbabaaaba
bbabbaabbabbabaaababbbba
aaabbbabbaabaabbbbbabbbbaaaaabbbbabbbabababbbaaa
aaabaabbaabaababaabababb
bbababaaabbbaabaabbababa
baabbbaaaaababababaabbaababbabbb
babbbaabbaaaabbaababbabb
bbababbbababbbaabbabbbabaabababaaabaaaaa
babbbbbbbbabbbababbbbaab
abaabbbbbabbbbbbaaabbaba
bbabbbaabbbbbaaabbbaaaaa
abbbbbbbbaabbbaaabbbbbbabaaaabaaaaaabbbb
aabaaabababbbbbbaaabbaab
bbbabababbbbbbabbbbbaabaabababbaaabbbbbb
aababbbaaaaaaaaaabbaaaaa
ababaababaababbbabbbbabaaabbabaaabbabbaabbaaaaaababaabba
aabbaaabaabbbaabaabaabbbaaabaaab
aabbaaabaaaaabaaaaabbbabaaabaaaababaaaaaabbbbbaaaababbaa
babbbaabaabaaabababbabaababbbaabbabaabbaabababbababaaaaa
aabbbbabababbbaaaaabaabbbaabbabaaaabababaabaaaabaaaababaabbbabbaabaaabbb
bbbbbbababbbabaababbabaabababababaababbabbbbbbbabbaaabbb
bbabababaaababbabbababba
abbbbbbabbbbbbaaabbbaabbbbabaabaaaaaaabb
aaaaabbbbaaaabbabbbabbab
aabbaaabbbbaaaabbabababbbabbaabbbbababbbbaaabbbababaabbbaabaaaaababbbaaa
ababbbabbbabbbaaababbbbbaabbabbaababbaaa
abbabbababbababbbbbbabbb
aabbaabaabbabbabbaabbaab
baabbbaaabbababbabbaaaba
baaabbbaaabbbabbbaaaaaaa
bbaaababaaaaabaabaaaabba
aabaaabbbbabbaabaaababaabbbbaabb
bbbbabbaaaabbabbaabbabab
aabaaaabbaaaaabababbabba
bababbbabaabaabbaaaabaab
ababaaabbbaabaabbbaabaaababaabbbabaabbaaaabbbaaabbbaabab
aababaaabbbbaaaaaaabbbbb
abaabbaabbbbbaaaaaaabaaa
babbbabababbaaaabaaaabab
abbbbbabbabbaaaababbaabb
bbaaaaabbbbababaaaaabaab
bbaababaaaabaabbabaabaab
bbababbaabbbbabbbaaaaabbabababba
bbabbaabbbbbabbaabababbbaabbbbbabaabbaaabbbabbbabaabbaab
abbabbaabbaaaaabbbabbbaabbbabaaabbaaabbbaaabaaab
aaababbababbabaabaabbbababbabbabbbaababaabbbabbaabaababa
baabbaabbbabbababbaaaaaabaaabbab
aabbabaabbbbbbbbbaabaaababaaaaaa
abbaabbabaaaaabaabbbabaabaaabaabaabaabbbaabaabaaaabaaaaa
baaaabbabaababbababbbababababbbb
bbabbaabbaaabbbabaaabaababbbbbbabbaaabaa
baabbbbaabbbbbbabaabbaab
baaaabbaabbababbaababbababaaaabbbbbbbabababaaaba
baabbbbbaabaabbbbbabbaaaabbaabbaabbbbbabbbbbbaba
babaabbbbbaabaaaabaababbabbbbabbbbbaaaaa
baabbababbaababaabbbaaab
bbaaaabbbaaaaaabbbabababbaabbabbbaaabbaaababaabb
abbbbbbaaababaaababbaaba
baabbabababababaaaaaababbababbbabaabbbaaabaaabab
aaaaababaabaabababbbbbbbabbbaaba
bababaaabbbaabbabaaaaabb
aabbaababbabbbbabbbaaaab
bbbbbbbbaabbbabbbabbbbba
aabaababbaabaabbbbaaaaababaaaaabbaaaaaaa
aaaaaaaaaaaaabababbbbbbabbbaabab
bbbaabaaababbbaaaabaaababbababbbabaaabbaabaaaaaa
ababbabbbbbbaabbaaabbaaabbaaabbaaaabbbba
baabababbbbbabaaababbbaabbaaababbbbaaaababbabbbb
bbaabbbaabaaabaaababaabb
bbabbbaaabbaabbbaaaabbaa
bbbabaabaaaaabaaaababaaaabaaabaaaaaaabbaabbaabbabbbbbaba
baaaabbaabbbaabaabbabbaabbbaaabaaabbbbbaaaaabaab
bbabbabbbbbbbaabbbababbbbbaabaaaaaabbaaa
abbbbbbbabaaabbbabbaaaabaaabababaabaabababbbaaaaabaaaababbababbabbbbabbb
baabbabaababbbaabbababba
bbaabbbaaaabbbbaaabaabaa
baabbabaabbbbbabaaaaabaababbbbaaabaaaaaa
baaabaaabbbababbababaaabaababbaa
aaababbabbaaaaabbaabababbbabaaba
aabbbaabaabbaaababbbaabb
bbbbbbbbbaabababaabaabaa
ababbaaaaabbbbbaaaabbaabbaaabaaabaabbaabbabbbababbbbabbabaaaaaababaaaaba
baaaaabaaaaaababaabbaaaa
aaaaaaaabbabababaaaabbaa
aababaaaababbbaabbbaaaaa
aaaaaaabbbaaabababbbaaab
aaababaaaabbbbababbaaaab
aaababaabaaaabbaabbaabab
bbaabaaaaaabaabbbabaaabbababaaba
ababaaabbaaaabbabbaabaaaabbababbaababaaababaabbbbabbabbb
aaaaaaabaaababbbbbaaaabbbbabaaaabaaabbabbaabbbab
abbabaaaabaaabbabbabbaaaababbbbbbbbaaaaa
abaaaaababbbbbababbbbaba
abaabaaaaabbbbaaaaaabaab
babababaaababaaaabaababa
bbbaaaaabbbbbbaaaabbaabb
aababaaaaaaaabaaabbbbaab
ababaaabababbbaaaaaabbab
baabbbabbbaabbbaabbbaabb
baabbbbaabbbaababbababba
bbbbabaaaaaababbbaababaa
aaaaabbabbbaabbaabaabbbaaabababababbbbba
baabaaabbbaabaabababaabb
aaabaaaaabbabbaabaabaaaa
aaabaabaabbabbabbabaabab
babaabbbbaabbbbbabaaabbabbaabaaabbababbababbbaaaababaabb
baaabaaababbabababbaaabbbaabaaabbaabaaaa
baaabaabbbababbbabbbbbabbabbaaab
abbabaaaaabbbbbababbaaaaaaaaababbabaababaabbbbbb
abbbbbbaabbbbaaababaabaaabbbbabbabbbbababbababbababaaaabbbaaaaba
aaabaabbabbbabaaabbaaaaa
bbbbaaabbbbabaaabaaabbbb
babbbaabbaabbbbbaaaabaaa
aaaaabaabaabaaabaabbaababbaababb
baababbbababbabbbbbbbaabaaaaabbababbbbbabaaaababbbbbbbbbbbaaaaabbabaaaabbababbab
baabaabababaababaaabbaaa
aababbabababaaababbabaaabbababbaabaababa
bbabbbabbabbbaababababba
abbaabbbaababaaaabbbabab
aaababbbabaabbbbbbbbabbb
aabbbbabbaaabaaaabbbaabb
abbbbbaabbbaabababaabaabababbaba
aaababaabbbbaaaababaaabbbaabbabbaaaabbaaababbaaa
bbaaaabaabbabaaaaabbaaabbbbabbab
aaabbababbbbababbbbbaaaababaaaaaababbaababaababbaababbbaaabbaaba
abbaabbbbabaabbbababbaab
baabbbbbbbaaabbbbababbbbbbaaaaaaabbbbbaaabaababa
aabbbbabbbbababbbabaaabbbabbbbbbbaaaabab
baabbbaabbabbbbababbbbaa
babbbbbbabbbbbbbaaabaabbbbbbbbbabbaaabaa
bbbabaaabbbbbaaaaaabbaab
abbbbbababaaabbaaababbbabbaaaaabaaaaabaabaaaaabb
bbabababaabbbaabaaabbbbabaaabbab
aaabbbbabbbbaaabbbbabbbbbbbbabbbaabababb
baaaabbaabbababbbabaaaaa
baababaabbaaaaabbababaabbbababbbababbbbabbabbaabbaaaabbabbaaabbbbbabbabbabbbabab
aaaaaaaaaabbbbababbbbabb
abbaaabbbaaaaaabbababaab
abaabbbbbaabbabaaaabababaabbababaaabbaab
aaaaabaabaababbaabbbbaba
bbbbbaaabbabababbaabbabaabaaaabaaabababb
aaaaabbaabbabaaaabbabbbabbbaaabbbaabaaaabbaaaaaa
aaabaaaaaaaaabbaaabaaabbbaabbbabaaaaabbbbabaaaaa
abaababbaababbbbaaabaaaabbbbbbbaabbaabaa
abaaabaabbbbbbabaabbbabbababaaba
bbabbaaabbaaaaababaaabbaaabbbabbbbbbabbaaabbabba
aaaaaaabbaababababaabbaababbaaaabaaabbab
bbbbbaaaaaababbbbaabbaab
abbaabbbbbaaaabbbbbbaaaabaabbabbaabbbaabbbaabbab
aaaabbbababaababbbbaababaababbaabbbabaababbbaabbbbaabbbaababbbaa
abbabbaaabbbaababbabaaab
aaaaaaababbaaabbbbaababb
baaabbaabaaabbaaabbbabba
babbbaabbbabbaabaabbaabaaabababa
aaaababbabababbbababaaabbbabaababbaababaaaabaabaabbabaaabbbaabaa
aaaaaaabaabbabaaabbabbaaaababbbbabbabaaabaaabaabaaaabbbaaabbbaaa
abbbbbbbbbbbabbabbbbaabb
baaabbbaabaababbaaabbaba
bbbbbbabbabbbabbaabaababbbbaabab
aaaaababbbbbabbbababbaabbbbbbabbaabbbbbbbbaaaaaa
ababaabbbababbbbbbbaaaabaabbbaaa
aaaababbbbbbabbabbaabbaa
aaabaababbbababbbabbabbb
bbababaaabaaabbaaabbaaaa
aaaaababbbaabbaaaaaaaabaabbbababbbbaabab
aabbaabbbabaabaabaaaaaaaabaababbbabbbbbaababbabbababaabaaabbbabbaabaabbaaabbbbba
bbbbaaaabbabababbbaaaaaa
abaaaaabaaaaaaabaabbaaabaaababaaaabaaaaa
babbbaabababaaabababbaab
baaaaaababababbbbaabababbbbbbaabbabaaaabaaaaaabaaababbaa
aabaaabbaababbabbabaabbbaababbabaabbbbaa
ababbbbbabbbaabababbaaba
bbababababbbaaaaabaabbabaaabbabb
bbaabaabaabbbaabbaaaaaabaabbabbbabbbbaab
baabaabbaababbbabbbbbaba
aaaaabababaaaaababababba
abababababbbabbbbababaaa
ababbbaabbabbbbabbbbbbaaabbbbabaabbabbba
babaaaaaaaabbaaabbbaabab
abaaababaaaabaaabaaaaaaabbabbbaaaababababaaaababaaaababbbbabaabbaabbbbba
aaababbbbaaaabbbaaaaaaabbbbabbbaaabbbbaa
babababaaaaababbabaabaab
bbaabbbababbabababaabaababbbbabaabbaaaaababbbbab
abababbbaabbbbababbbaaaaaaabaaab
aabaabaaaaaababaabbaaaabaabaaaaaaaababaa
aabbbaabbbbbabaababbabba
abbbaabaaaaaaaaababbbabbbbaaaababbbbbababbbaaaaa
aaabbbabbbbababbbbaabaabbaaaabab
aabbaababbabbbabbbbbbaba
abbaabbabbbbaaaaabaaaabbbaaababb
aaabababbbbbaaaabbbababb
abbbbbbbaaabaababbababababaabbbaabaabaaa
bbbabababaabbababaabbbbabaababaa
bbbabbabaaaabaaaaabbaaababababababababaaaaaabbbbaaaaabaabbaababb
aabaaabaaaaaaaababbabbbb
aabbabaabaabbabbaaabbbbaaabaabaa
bbaaaabbbbbabaaabababbbaaabaaababababaab
bbbbbbbaaabbbbbaaaaabbab
babaabbbbaaabaaabbbababbbbbaabaaabbbbaba
bbaaaabbbbbbaaaaabababaaaaabbaaabbbaabba
bbabbbababaabbbbaabaaabaaaabbaaa
baabaabbabaababbbbaabaabbaabbabbabbbbababbaaabbb
babbbabaabbbaababababbab
aabaaabbabaaaaabbbaaaabbaaabbaba
aaaaabaaabaabbbbaabbbbbb
aaaabbbabbababaabaabbbaabbbbbababababababbbaaabbaaabbabaaababbba
abaaaabbabbbbbabbbabbbababbaababbbaaabba
abababbbbaabbbbbbabbbbbbabbbbbabaaaababbababaabb
abaaabbabbababbbabaababbbaabbbbababbbaabbbaabbaa
babbbbbbbaabababbbababaaabbabbaabaabbabbaabbbaaa
aaababbababaaaabbbbaaaaa
babaaabbaabbbbbaaaaababa
aaabaaaaaabbaababaabbabababbaaaabbaabbaa
abaabbabbbaababaabbbaabababbabaabbaaaababbababaaabbbabbb
bbbbababbbaabaabbabaaabbaababbaaabaaabbb
baabbbabaaaaaaabbaabbaab
bbbaaabaaaababbbababaabbbbbbbaabbbbababb
babbaaaababbabbaabababbbababbbabaaababaa
aaabababaabbabaabbbabaaababbbbab
bbbbababbbabbbababbababbbaababaababaabba
bbbababababbbbbbabbbaaaaabaabbba
aabaaabbabbbbbaaabaababaabaaabab
bbabbabaabaaaaaababbbbaa
abaabaabaaaaabaabbbbbabababbabbbaabaabaa
bbabbbaababbbabbaabbaaabbabbabaabaaabaaababaabaabbbabbababbbbabbbabbabbabbaabbbb
aaaaabaababbababababbbbbaababbabbbabababbbbbabbb
abaaabbabbabbbaaaabababb
abbbbbababaaaaabbabaaaaa
bbbabbabaaabbaabbaaaabaababbaaab
bbbbbbbbabaabbaaaabbbaaa
baaabbbaaababbbbabbbabbbabaabaabaababaab
aaaababbbbaabbbaaaaababbbabbabba
bbabbbaaababaaabbbbbbbbabbaabaababbabbba
aaabababbabbbabaaabbabaaaaabbaba
aabaabbbbaabbbabaaabbbbabbbbabbb
bbbbbbabababaaababaabbbbaabbaaaabababbbb
abaaaabbaaabaabbbbaaababaaabbaabaabbbbbb
baabbababbbaaabaababbbba
baaabbbabababbbaabbaabab
babababaaaabaaaabbbbabbb
babbababaaabbbbabbbaabaabaabbbbbaaabbbab
baabbaabbababbababbaaaaa
bbababbbaaaaaaaabaabbbbaaaaabaaa
abbbaabbbbbbbbaabbabbbabbbbbabaaababaaab
bbaabbbababaabbbbabaaaba
baaababababaabbbbbabbaba
abababbbaababbbbabbabaabbaabbbaaabbbaabaabbbbaaa
bbaaaaaaaaabababbaabababaababbbbbbbbabaaaaabbabbbbbbbbaabaaaaabbbababbaaaaababaa
baaaaabaaaaaaaaaabbabbba
baabbbbaabaabbabbaaabbbb
abbabbabaabbabaaaabbabab
abaabbbbbaaaaababbabaaba
bbbbbaaabbaabbbaabaaabbaabaaaaabbaabababaabbabbbbabbaabb
babbbabaabaaabbaabbbbbaa
bbabbaabbabbabaabbaaaabaaaabbaab
aaaababaaabaaaaabbabbabaababaabaaabbabbb
abbaaabbbbababaabaaaabaa
baabbbbabaabaabbbaabbaab
baababbabbbabaabaaabaabbbaaabaaabbbbbaba
bbbababbaabbbabbbbbbbbaa
bbbbbbabbbabbabbabbaabbbaaabaaab
bbbababbababaaababaaabbabaababbb
baabaabbaabbabaabbbaaaab
bbaaaababbabababaaabaaaaaaabaabaabbbbaba
bbabbaaabbbbbaaabbbaabab
ababaaababbabababbaababb
aabaaaababbabbabbabbbbaa
aaaabaaabbaabbabababaaaaabbbabbb
abbbabaabbabbbaaaabaaababbabbabbbbaabaababaaabbb
bbaaaabbaabbaaabaaaaaaabaaabbbbaaabbaabaaababaaabbaaabaa
babbbabbaaabababbbabaaab
abbabbabbaabbababbabbbbaaaaabbbabbababba
abbaababbbaabbababbbabbaaabbbbbaaaabababaabababbbbaabbbaabbabaabbbbbabbaabaaaaab
babbbabaababbbabbbbabbba
baaabaabaaaaaaabbabaabba
baabaabbbaabaaabbbabbaaabaaaaaabbbbbaabb
bbababbbabaaaabbbababaaa
baababbaaaabbbbaabbababbaabbaabaabaabbbabbabaaab
bbbbbbaaabbbababbaababbbbaaabbaabbaababb
bbabbaaabaabbbaababbaabb
ababbbababbbbbbbababbabb
babababababaaaaaaaaababababbaaabbabaabab
abaaabaaabbaabbbbabbaaba
aaaababbbabbbbbbbbbaabba
babbbabaaababaaabaaababb
ababbbabbbabbabbbbababaaaaabbbaa
aaaaabbbaabbaababbbbbbbbbaaaabbbaaaaabaabbbbaabaaababbaabababbabbabbabbb
abbabaabbbabbbaaaaabaaaabbbbbaaa
bbbbabbaaabaabbbaabababb
bbbabbaabbbaabaaabaaabaabaaaaaabaabbbbaa
bbbababbbabaaaabaaabbaba
abbababbabaababbbaabbabaaaabaabbaaaabaaabbabbbbbababababbbbaabba
aaabaaaaaababbbaabbaabab
abaabbaabaaabababaaabbbababbbbab
aaaaabbbbbababbbbabaaaaa
aabaaabaaababaaaabaabaaa
aabaabababbbaaaabaabbaaa
babaabaababaabbbbbababbbaaababbaabbabaabbabbbbabbaabaaba
aabaaabaaaabaaaabbaabbbb
bbbbaabaabaaabaaaababbbabaabbaab
bbabababbbabbbbaabbbbaab
baabababbaabbbbbbaaabbbabbbabbbbbabaabbababbaaabaabababa
abbbabbbabbabbabbaaaabaabbbbbaaaabaabababaababaaaaabababaababbba
baabbabbbaabbbbaabaabbabaababbaa
abaababbaaaaabbbaabbbaabaaababbbbbaaababaaaaababbabbaabb
bbbabbbbababababaaabaaabbaabbabaabbabbbbaababaaaabbbabbbbbbabbbbaaaaababbaaaaaaa
aababbabaabababaaababbabbaaaaaaabbbbbbaabbaaabbbbbbaabbb
ababbbabaaabaababbbaaabb
abbbbbbaabbbbbbbbbababba
bbabbbbabbabbbaaabbabaababbbaaaaaabbaaaa
bbaabaababbbbbbbabaabaab
aaaaabbabbbbabbabaabbbbbbabbabaaababbabbaabbaaaa
abbaabbabbbbbbbbabababba
abababbbabbababbabbabbaabbbbaabb
baaabaaaaaaaabbabaaababb
abaabbbbbabaaaabbaaaabaa
bbaabaaabbaabaaaabbbbbaa
baabaaabbbbbbbbabbababaaabbaaaab
bbaaabababbaaabbaabaaabbaabaabbabaaaabaa
aababbbbbbabbabbbbabbbbaaabababb
abbbabaabbaaaaabaaabbaaa
abbbaaaabaaabaaaaaaaaaaabbaabbab
aaabaaaabbbbbbbaabbababbbabbbabaabbabbaabbbbaaaabbbaabbb
aabbaaabbbabbabbbbbaabaaaaaaaabaabbbaabb
babbbbbbaabbabaabaaaabab
aaaaabbbaaaaabbaaababbbaabababab
baabaabbbbbbbbbabbaabaaababaabab
aababbbbaaaabbaababaaaaabaabbbabbbababaaaabaaabbaaaabaabababbbabbabaabbabaabaaaa
aababaaaabbbababbbaabaabbbbababbbbaaabababababba
bbbbbbabbabbababaaaaabaabaabbbaabbaaabababbaaaab
abbaabbbaabbbbabbbabbaba
bbaababaabaabbbbbabababb
aabaabbbbbbbbbbababbababbbbbababbabbaaab
bbabbaabaabbaabababaaaabbabbaaaaabaaabab
babbaaaabbabbabbabbaabab
bbbababbabbababbbabbaabb
aaababbabaaaaaababbbabba
babaabaabaaababaaabaaabaaaabbabb

57
2020/d19/ex2/ex2.py Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env python
import itertools
import re
import sys
from typing import Dict, List
def parse_rule(raw_rules: List[str]) -> str:
parsed: Dict[int, str] = {}
rules = {int(num): rule.strip() for num, rule in (i.split(":") for i in raw_rules)}
for n, r in rules.items():
if '"' not in r:
continue
parsed[n] = r.replace('"', "")
while 0 not in parsed:
for num in parsed:
if num not in rules:
continue
rules.pop(num)
for num, r in rules.items():
nums = list(reversed(sorted(map(int, re.findall("(\\d+)", r)))))
if all(n in parsed for n in nums):
for n in nums:
r = re.sub(str(n), parsed[n], r) # Bigger numbers replaced first
r = r.replace(" ", "{x}" if num == 11 else "")
if num == 11:
r = "(" + r + "{x})"
r = "(" + r + ")"
if num == 8:
r = "(" + r + "+)"
parsed[num] = r
return parsed[0]
def solve(raw: List[str]) -> int:
pattern = parse_rule(list(itertools.takewhile(len, raw)))
def matches(repeats: int) -> int:
pat = re.compile(pattern.replace("x", str(repeats)))
return sum(
pat.fullmatch(line) is not None for line in itertools.dropwhile(len, raw)
)
return sum(itertools.takewhile(bool, map(matches, itertools.count(1))))
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

561
2020/d19/ex2/input Normal file
View file

@ -0,0 +1,561 @@
102: 100 47 | 76 84
23: 60 47 | 73 84
132: 17 47 | 81 84
108: 55 100
18: 116 47 | 26 84
103: 84 115 | 47 81
65: 84 113 | 47 50
128: 107 47 | 125 84
14: 84 100 | 47 107
118: 47 17 | 84 57
2: 47 100 | 84 40
28: 63 84 | 74 47
22: 102 84 | 123 47
123: 84 74
19: 3 47 | 13 84
24: 74 47 | 81 84
115: 55 55
90: 92 47 | 44 84
48: 84 94 | 47 96
109: 17 84 | 100 47
92: 84 75 | 47 108
66: 38 47 | 125 84
83: 66 47 | 108 84
31: 121 84 | 77 47
29: 47 61 | 84 111
45: 47 47 | 47 84
59: 47 49 | 84 43
37: 47 30 | 84 95
36: 107 84 | 125 47
82: 74 84 | 38 47
61: 84 10 | 47 110
79: 47 28 | 84 109
33: 101 47 | 133 84
12: 45 47 | 63 84
91: 122 84 | 93 47
122: 65 47 | 52 84
21: 57 84 | 115 47
8: 42
67: 102 47 | 64 84
39: 113 84 | 81 47
41: 84 124 | 47 10
50: 47 47 | 84 84
17: 47 84 | 84 84
120: 98 84 | 78 47
113: 55 47 | 47 84
20: 84 128 | 47 104
7: 84 1 | 47 20
51: 84 113 | 47 81
56: 84 83 | 47 69
131: 84 127 | 47 97
0: 8 11
5: 47 63 | 84 125
94: 15 84 | 127 47
121: 99 47 | 27 84
119: 47 115 | 84 57
129: 47 80 | 84 131
15: 47 100 | 84 45
35: 84 50 | 47 76
95: 47 115 | 84 107
68: 127 84 | 51 47
124: 84 107
75: 50 55
57: 47 84 | 84 55
13: 47 33 | 84 129
53: 106 47 | 59 84
106: 16 84 | 118 47
89: 84 125 | 47 45
104: 45 84 | 76 47
99: 47 56 | 84 7
78: 84 74 | 47 81
64: 17 47 | 115 84
32: 50 84 | 40 47
1: 47 24 | 84 72
47: "a"
80: 114 47 | 109 84
88: 47 119 | 84 132
105: 47 125 | 84 100
6: 68 84 | 67 47
110: 76 84 | 63 47
38: 84 84 | 84 47
49: 47 63 | 84 76
26: 55 107
81: 47 84
74: 84 47
96: 84 89 | 47 117
77: 47 86 | 84 71
135: 32 84 | 2 47
133: 47 15 | 84 128
42: 19 84 | 62 47
30: 47 100 | 84 74
27: 6 47 | 91 84
63: 84 55 | 47 47
62: 84 87 | 47 23
76: 84 84
4: 84 135 | 47 54
60: 41 47 | 37 84
100: 47 47 | 84 47
85: 47 112 | 84 18
116: 125 84 | 63 47
134: 57 47 | 115 84
34: 52 47 | 25 84
40: 47 47
111: 58 84 | 126 47
3: 29 47 | 130 84
114: 17 84 | 107 47
52: 47 45 | 84 74
10: 47 100 | 84 81
98: 47 76 | 84 100
112: 84 82 | 47 103
72: 40 47 | 45 84
126: 50 84 | 113 47
107: 84 47 | 47 84
11: 42 31
55: 84 | 47
54: 12 84 | 5 47
130: 34 47 | 70 84
84: "b"
127: 81 47 | 17 84
87: 84 53 | 47 9
101: 105 84 | 14 47
9: 88 84 | 120 47
73: 47 79 | 84 22
97: 74 84 | 50 47
117: 74 47
70: 47 134 | 84 46
58: 47 50 | 84 115
125: 47 47 | 55 84
46: 47 81 | 84 17
86: 84 90 | 47 85
25: 38 84 | 63 47
69: 39 47 | 78 84
43: 47 100 | 84 125
93: 84 66 | 47 35
44: 47 21 | 84 36
16: 57 47 | 107 84
71: 48 84 | 4 47
babaaabbbababababbbbabbaabbaabaa
babaaaabaaaaababbbbaaaaa
abbabaabbaaabababaabbbbabbbbbaabbbbabababaaaabbbbababbbb
bbbabababbabbbabbbabbbbb
babaabbbababbbabaabaaaaa
abbabaabbaababbabababbbababbbabbabbabbbabbaabbbb
aaaaabaabbbbbaabbbbbbbbbbaaabbaaabbaabab
baababbabbbabbaaaaaababbaabbababbbabbbbb
aaabaaaabbabbbabbabaabbbabaabbbbaaaaabaaaabaabaaababaabbabbaaaabbbbaabbabbabaaaaaaaabaab
ababaaabababbbababaaabab
bbbbabbbbbaabaaaaaabbbbbbabbbabaabbaaababbbaaaaababaabaabaabababbabbbabbabaaabbaaabbaaaa
babaabaaababaaabaaaababa
aabaaabbaabbbabbabaabaab
bbbaabaaaabaaabbbaaabbbabbbaaabb
aaaaaaabaaababbbbbbbbbbbbaaabaabbaaabbab
bbabbabbaaaaabababaababa
babbababbbabbaababaababbaaaaabaaabbbabba
bbbbbbbababbaaaaabaaabbaabbaaaab
bbbbbaaabbbbbaaaaaabaaaabbbaaabb
babbababaababbbbbbbaaabb
abaabbaabbababaabbababba
abaaabbaaabaabbbabababba
babaaaabaaaababbabbbbaaa
bbbbbbbabaababbaaaaababbabbaabbabbbaabaababaabbbbbbaabab
aaabbabbbaabababbaabaaba
bbbababbabaabbabbbabaaaa
baabbabababaaaabbbbbbaab
bbabbbbabaababbabbbaabab
abaabbabbbabbabbabbbabba
bbbbbbbaaababaaabbaabbbabbaaabbbbabababb
aabbaaabbabbabaaaabbabaababbbaababaabababaaabbaa
aaabaababbbabbbbaaababbbbaaabbbb
aaaaaaaaaaabaaaababbabbb
bbbabbbbaabaababaabbabab
baaabaabbaaaabbbbaaaaaaa
bbbbbbbaabbabbaabaabaaaa
aaaaabaabbabbaaaaaaaaabb
aabaaabbaabbabaaabbabaabbaababaaabbbaaaaababbaabaaabbaaabbaaabaa
bababbbaaabaababbbababaabbaabaabbaaaabbabbaabababbbabbbababbabbb
abbbaababbaabaaaaababbbaaaabbbaa
aababbbaaaabaabbbbabaaaa
aaaaabbaaabaaabbbababaaa
bbbababaaabaaaabbabbabaabbababababababbbabbaaaaabbababbabbbbabbbabbbaabb
bbbabababbbabababababbbb
bbaaababbbabbbbaabbbbbaa
bbababaabaaaabbaabbbbaaa
bbbbabbababbbbaabbaaaababbababbaabaaabababbabbabbbbbbaababbbbabbbbaaaaabbbaabbba
abbabbabbbbbbaabaaaaabababaaaaabaaabbaaaabababba
bbbabaabaababaaabaabbaaa
bbababbbbaaababaaaabbabbaaabbbaa
aabbbbababaabbaabababbaa
aaabbabbbaabbbabbbbbbbbabaaaabbaaabababaabaaabab
aaaaaaababbabbabbabaaaaa
aababaaaaaababbbabbabbabaaababbbbbabbababababaaaabbabbbb
babaabbbbaaabaaabbbabbab
bbbbabbbbaabbbabbbaabbbaabbbbbaabbbbaaabbbbaabbbbaababbaaaabaaaabbabbabbabbaabbb
aaabbbabbaaabaabbaaaaabaabababab
abbababbabbbbbabbaabbbabaaababbbbbbbabaababbbbbabababbbb
bbaabbbaaaaababaaabaaaabbbbbbaabbaaaabbaabaaabaabaaaabbabbabbbaabbaaaaaa
abbabbaaaabaaaabbbbbbaabbabaababbbbabbba
bbaaaabaabbababbbbaabbaa
aabbaabaabbaaabbaaabaaaaaaababbabababbaa
baaaabbaaaaaabbbbabbababbaabbbbabbabbabbaabbaabb
babbaaaabbaabaaabbbbaaaabbbabbaaaaaaaabb
aaaaababaaabbabbababbabb
abbabaaaaaabaababbabaaab
aaabaababbaabbbaababbabb
babbabaabaababbabbabaabb
abbabbaabbabbbabababaaaa
bbabbbaaaababaaaaaabbbaa
bbbbbbbaaaaaabbabbbaabaaaaabbaaa
bbbaabaababaaabbaababbabaababaabbbababba
bbaaabbaabaabbbbbbbaababbbaabaabaaabaababaaaaabbbaaabaababaaaaabaabbbbaabaabbbaa
baabbababbaaaaababaabbabaabbbaabaabbaabbabbbaaababbaaaab
bbabaaaaaaaabababaabbababbaabbbbabbbaaababbaababaabaaaaaaaabaabb
baaaaaabbaababbaababaaaa
bbbabbbbbbaabaabbaaabbab
babbbabababaaaabaabbaaabbbabaabababbbaaabaababbbbbaababbbabbbabb
aabaaababababababaabbbababbababbbabbaabb
bbaabaaabbaabababbaababaabbabbba
bbbabaaaababaabbaabbabbbbabbaabaabbabaabbaabaabaabbaabbabaaabaaa
abbaaabbbbbbbbbbaaabbaab
baabbbbbaabbaabbaabbababbaabaaba
baaaabaaabbbbaabaabbabbbbaababbb
abbbbbbaabbbbbbbbbbbbaaaaaaabaaa
abbbbbbbbbabbbaabbbaaabaaabababa
aababbbaabbabaabbabaaaba
bbabbaabbabbabaaababbbba
aaabbbabbaabaabbbbbabbbbaaaaabbbbabbbabababbbaaa
aaabaabbaabaababaabababb
bbababaaabbbaabaabbababa
baabbbaaaaababababaabbaababbabbb
babbbaabbaaaabbaababbabb
bbababbbababbbaabbabbbabaabababaaabaaaaa
babbbbbbbbabbbababbbbaab
abaabbbbbabbbbbbaaabbaba
bbabbbaabbbbbaaabbbaaaaa
abbbbbbbbaabbbaaabbbbbbabaaaabaaaaaabbbb
aabaaabababbbbbbaaabbaab
bbbabababbbbbbabbbbbaabaabababbaaabbbbbb
aababbbaaaaaaaaaabbaaaaa
ababaababaababbbabbbbabaaabbabaaabbabbaabbaaaaaababaabba
aabbaaabaabbbaabaabaabbbaaabaaab
aabbaaabaaaaabaaaaabbbabaaabaaaababaaaaaabbbbbaaaababbaa
babbbaabaabaaabababbabaababbbaabbabaabbaabababbababaaaaa
aabbbbabababbbaaaaabaabbbaabbabaaaabababaabaaaabaaaababaabbbabbaabaaabbb
bbbbbbababbbabaababbabaabababababaababbabbbbbbbabbaaabbb
bbabababaaababbabbababba
abbbbbbabbbbbbaaabbbaabbbbabaabaaaaaaabb
aaaaabbbbaaaabbabbbabbab
aabbaaabbbbaaaabbabababbbabbaabbbbababbbbaaabbbababaabbbaabaaaaababbbaaa
ababbbabbbabbbaaababbbbbaabbabbaababbaaa
abbabbababbababbbbbbabbb
aabbaabaabbabbabbaabbaab
baabbbaaabbababbabbaaaba
baaabbbaaabbbabbbaaaaaaa
bbaaababaaaaabaabaaaabba
aabaaabbbbabbaabaaababaabbbbaabb
bbbbabbaaaabbabbaabbabab
aabaaaabbaaaaabababbabba
bababbbabaabaabbaaaabaab
ababaaabbbaabaabbbaabaaababaabbbabaabbaaaabbbaaabbbaabab
aababaaabbbbaaaaaaabbbbb
abaabbaabbbbbaaaaaaabaaa
babbbabababbaaaabaaaabab
abbbbbabbabbaaaababbaabb
bbaaaaabbbbababaaaaabaab
bbaababaaaabaabbabaabaab
bbababbaabbbbabbbaaaaabbabababba
bbabbaabbbbbabbaabababbbaabbbbbabaabbaaabbbabbbabaabbaab
abbabbaabbaaaaabbbabbbaabbbabaaabbaaabbbaaabaaab
aaababbababbabaabaabbbababbabbabbbaababaabbbabbaabaababa
baabbaabbbabbababbaaaaaabaaabbab
aabbabaabbbbbbbbbaabaaababaaaaaa
abbaabbabaaaaabaabbbabaabaaabaabaabaabbbaabaabaaaabaaaaa
baaaabbabaababbababbbababababbbb
bbabbaabbaaabbbabaaabaababbbbbbabbaaabaa
baabbbbaabbbbbbabaabbaab
baaaabbaabbababbaababbababaaaabbbbbbbabababaaaba
baabbbbbaabaabbbbbabbaaaabbaabbaabbbbbabbbbbbaba
babaabbbbbaabaaaabaababbabbbbabbbbbaaaaa
baabbababbaababaabbbaaab
bbaaaabbbaaaaaabbbabababbaabbabbbaaabbaaababaabb
abbbbbbaaababaaababbaaba
baabbabababababaaaaaababbababbbabaabbbaaabaaabab
aaaaababaabaabababbbbbbbabbbaaba
bababaaabbbaabbabaaaaabb
aabbaababbabbbbabbbaaaab
bbbbbbbbaabbbabbbabbbbba
aabaababbaabaabbbbaaaaababaaaaabbaaaaaaa
aaaaaaaaaaaaabababbbbbbabbbaabab
bbbaabaaababbbaaaabaaababbababbbabaaabbaabaaaaaa
ababbabbbbbbaabbaaabbaaabbaaabbaaaabbbba
baabababbbbbabaaababbbaabbaaababbbbaaaababbabbbb
bbaabbbaabaaabaaababaabb
bbabbbaaabbaabbbaaaabbaa
bbbabaabaaaaabaaaababaaaabaaabaaaaaaabbaabbaabbabbbbbaba
baaaabbaabbbaabaabbabbaabbbaaabaaabbbbbaaaaabaab
bbabbabbbbbbbaabbbababbbbbaabaaaaaabbaaa
abbbbbbbabaaabbbabbaaaabaaabababaabaabababbbaaaaabaaaababbababbabbbbabbb
baabbabaababbbaabbababba
bbaabbbaaaabbbbaaabaabaa
baabbabaabbbbbabaaaaabaababbbbaaabaaaaaa
baaabaaabbbababbababaaabaababbaa
aaababbabbaaaaabbaabababbbabaaba
aabbbaabaabbaaababbbaabb
bbbbbbbbbaabababaabaabaa
ababbaaaaabbbbbaaaabbaabbaaabaaabaabbaabbabbbababbbbabbabaaaaaababaaaaba
baaaaabaaaaaababaabbaaaa
aaaaaaaabbabababaaaabbaa
aababaaaababbbaabbbaaaaa
aaaaaaabbbaaabababbbaaab
aaababaaaabbbbababbaaaab
aaababaabaaaabbaabbaabab
bbaabaaaaaabaabbbabaaabbababaaba
ababaaabbaaaabbabbaabaaaabbababbaababaaababaabbbbabbabbb
aaaaaaabaaababbbbbaaaabbbbabaaaabaaabbabbaabbbab
abbabaaaabaaabbabbabbaaaababbbbbbbbaaaaa
abaaaaababbbbbababbbbaba
abaabaaaaabbbbaaaaaabaab
babababaaababaaaabaababa
bbbaaaaabbbbbbaaaabbaabb
aababaaaaaaaabaaabbbbaab
ababaaabababbbaaaaaabbab
baabbbabbbaabbbaabbbaabb
baabbbbaabbbaababbababba
bbbbabaaaaaababbbaababaa
aaaaabbabbbaabbaabaabbbaaabababababbbbba
baabaaabbbaabaabababaabb
aaabaaaaabbabbaabaabaaaa
aaabaabaabbabbabbabaabab
babaabbbbaabbbbbabaaabbabbaabaaabbababbababbbaaaababaabb
baaabaaababbabababbaaabbbaabaaabbaabaaaa
baaabaabbbababbbabbbbbabbabbaaab
abbabaaaaabbbbbababbaaaaaaaaababbabaababaabbbbbb
abbbbbbaabbbbaaababaabaaabbbbabbabbbbababbababbababaaaabbbaaaaba
aaabaabbabbbabaaabbaaaaa
bbbbaaabbbbabaaabaaabbbb
babbbaabbaabbbbbaaaabaaa
aaaaabaabaabaaabaabbaababbaababb
baababbbababbabbbbbbbaabaaaaabbababbbbbabaaaababbbbbbbbbbbaaaaabbabaaaabbababbab
baabaabababaababaaabbaaa
aababbabababaaababbabaaabbababbaabaababa
bbabbbabbabbbaababababba
abbaabbbaababaaaabbbabab
aaababbbabaabbbbbbbbabbb
aabbbbabbaaabaaaabbbaabb
abbbbbaabbbaabababaabaabababbaba
aaababaabbbbaaaababaaabbbaabbabbaaaabbaaababbaaa
bbaaaabaabbabaaaaabbaaabbbbabbab
aaabbababbbbababbbbbaaaababaaaaaababbaababaababbaababbbaaabbaaba
abbaabbbbabaabbbababbaab
baabbbbbbbaaabbbbababbbbbbaaaaaaabbbbbaaabaababa
aabbbbabbbbababbbabaaabbbabbbbbbbaaaabab
baabbbaabbabbbbababbbbaa
babbbbbbabbbbbbbaaabaabbbbbbbbbabbaaabaa
bbbabaaabbbbbaaaaaabbaab
abbbbbababaaabbaaababbbabbaaaaabaaaaabaabaaaaabb
bbabababaabbbaabaaabbbbabaaabbab
aaabbbbabbbbaaabbbbabbbbbbbbabbbaabababb
baaaabbaabbababbbabaaaaa
baababaabbaaaaabbababaabbbababbbababbbbabbabbaabbaaaabbabbaaabbbbbabbabbabbbabab
aaaaaaaaaabbbbababbbbabb
abbaaabbbaaaaaabbababaab
abaabbbbbaabbabaaaabababaabbababaaabbaab
aaaaabaabaababbaabbbbaba
bbbbbaaabbabababbaabbabaabaaaabaaabababb
aaaaabbaabbabaaaabbabbbabbbaaabbbaabaaaabbaaaaaa
aaabaaaaaaaaabbaaabaaabbbaabbbabaaaaabbbbabaaaaa
abaababbaababbbbaaabaaaabbbbbbbaabbaabaa
abaaabaabbbbbbabaabbbabbababaaba
bbabbaaabbaaaaababaaabbaaabbbabbbbbbabbaaabbabba
aaaaaaabbaababababaabbaababbaaaabaaabbab
bbbbbaaaaaababbbbaabbaab
abbaabbbbbaaaabbbbbbaaaabaabbabbaabbbaabbbaabbab
aaaabbbababaababbbbaababaababbaabbbabaababbbaabbbbaabbbaababbbaa
abbabbaaabbbaababbabaaab
aaaaaaababbaaabbbbaababb
baaabbaabaaabbaaabbbabba
babbbaabbbabbaabaabbaabaaabababa
aaaababbabababbbababaaabbbabaababbaababaaaabaabaabbabaaabbbaabaa
aaaaaaabaabbabaaabbabbaaaababbbbabbabaaabaaabaabaaaabbbaaabbbaaa
abbbbbbbbbbbabbabbbbaabb
baaabbbaabaababbaaabbaba
bbbbbbabbabbbabbaabaababbbbaabab
aaaaababbbbbabbbababbaabbbbbbabbaabbbbbbbbaaaaaa
ababaabbbababbbbbbbaaaabaabbbaaa
aaaababbbbbbabbabbaabbaa
aaabaababbbababbbabbabbb
bbababaaabaaabbaaabbaaaa
aaaaababbbaabbaaaaaaaabaabbbababbbbaabab
aabbaabbbabaabaabaaaaaaaabaababbbabbbbbaababbabbababaabaaabbbabbaabaabbaaabbbbba
bbbbaaaabbabababbbaaaaaa
abaaaaabaaaaaaabaabbaaabaaababaaaabaaaaa
babbbaabababaaabababbaab
baaaaaababababbbbaabababbbbbbaabbabaaaabaaaaaabaaababbaa
aabaaabbaababbabbabaabbbaababbabaabbbbaa
ababbbbbabbbaabababbaaba
bbababababbbaaaaabaabbabaaabbabb
bbaabaabaabbbaabbaaaaaabaabbabbbabbbbaab
baabaabbaababbbabbbbbaba
aaaaabababaaaaababababba
abababababbbabbbbababaaa
ababbbaabbabbbbabbbbbbaaabbbbabaabbabbba
babaaaaaaaabbaaabbbaabab
abaaababaaaabaaabaaaaaaabbabbbaaaababababaaaababaaaababbbbabaabbaabbbbba
aaababbbbaaaabbbaaaaaaabbbbabbbaaabbbbaa
babababaaaaababbabaabaab
bbaabbbababbabababaabaababbbbabaabbaaaaababbbbab
abababbbaabbbbababbbaaaaaaabaaab
aabaabaaaaaababaabbaaaabaabaaaaaaaababaa
aabbbaabbbbbabaababbabba
abbbaabaaaaaaaaababbbabbbbaaaababbbbbababbbaaaaa
aaabbbabbbbababbbbaabaabbaaaabab
aabbaababbabbbabbbbbbaba
abbaabbabbbbaaaaabaaaabbbaaababb
aaabababbbbbaaaabbbababb
abbbbbbbaaabaababbababababaabbbaabaabaaa
bbbabababaabbababaabbbbabaababaa
bbbabbabaaaabaaaaabbaaababababababababaaaaaabbbbaaaaabaabbaababb
aabaaabaaaaaaaababbabbbb
aabbabaabaabbabbaaabbbbaaabaabaa
bbaaaabbbbbabaaabababbbaaabaaababababaab
bbbbbbbaaabbbbbaaaaabbab
babaabbbbaaabaaabbbababbbbbaabaaabbbbaba
bbaaaabbbbbbaaaaabababaaaaabbaaabbbaabba
bbabbbababaabbbbaabaaabaaaabbaaa
baabaabbabaababbbbaabaabbaabbabbabbbbababbaaabbb
babbbabaabbbaababababbab
aabaaabbabaaaaabbbaaaabbaaabbaba
aaaaabaaabaabbbbaabbbbbb
aaaabbbabbababaabaabbbaabbbbbababababababbbaaabbaaabbabaaababbba
abaaaabbabbbbbabbbabbbababbaababbbaaabba
abababbbbaabbbbbbabbbbbbabbbbbabaaaababbababaabb
abaaabbabbababbbabaababbbaabbbbababbbaabbbaabbaa
babbbbbbbaabababbbababaaabbabbaabaabbabbaabbbaaa
aaababbababaaaabbbbaaaaa
babaaabbaabbbbbaaaaababa
aaabaaaaaabbaababaabbabababbaaaabbaabbaa
abaabbabbbaababaabbbaabababbabaabbaaaababbababaaabbbabbb
bbbbababbbaabaabbabaaabbaababbaaabaaabbb
baabbbabaaaaaaabbaabbaab
bbbaaabaaaababbbababaabbbbbbbaabbbbababb
babbaaaababbabbaabababbbababbbabaaababaa
aaabababaabbabaabbbabaaababbbbab
bbbbababbbabbbababbababbbaababaababaabba
bbbababababbbbbbabbbaaaaabaabbba
aabaaabbabbbbbaaabaababaabaaabab
bbabbabaabaaaaaababbbbaa
abaabaabaaaaabaabbbbbabababbabbbaabaabaa
bbabbbaababbbabbaabbaaabbabbabaabaaabaaababaabaabbbabbababbbbabbbabbabbabbaabbbb
aaaaabaababbababababbbbbaababbabbbabababbbbbabbb
abaaabbabbabbbaaaabababb
abbbbbababaaaaabbabaaaaa
bbbabbabaaabbaabbaaaabaababbaaab
bbbbbbbbabaabbaaaabbbaaa
baaabbbaaababbbbabbbabbbabaabaabaababaab
aaaababbbbaabbbaaaaababbbabbabba
bbabbbaaababaaabbbbbbbbabbaabaababbabbba
aaabababbabbbabaaabbabaaaaabbaba
aabaabbbbaabbbabaaabbbbabbbbabbb
bbbbbbabababaaababaabbbbaabbaaaabababbbb
abaaaabbaaabaabbbbaaababaaabbaabaabbbbbb
baabbababbbaaabaababbbba
baaabbbabababbbaabbaabab
babababaaaabaaaabbbbabbb
babbababaaabbbbabbbaabaabaabbbbbaaabbbab
baabbaabbababbababbaaaaa
bbababbbaaaaaaaabaabbbbaaaaabaaa
abbbaabbbbbbbbaabbabbbabbbbbabaaababaaab
bbaabbbababaabbbbabaaaba
baaababababaabbbbbabbaba
abababbbaababbbbabbabaabbaabbbaaabbbaabaabbbbaaa
bbaaaaaaaaabababbaabababaababbbbbbbbabaaaaabbabbbbbbbbaabaaaaabbbababbaaaaababaa
baaaaabaaaaaaaaaabbabbba
baabbbbaabaabbabbaaabbbb
abbabbabaabbabaaaabbabab
abaabbbbbaaaaababbabaaba
bbbbbaaabbaabbbaabaaabbaabaaaaabbaabababaabbabbbbabbaabb
babbbabaabaaabbaabbbbbaa
bbabbaabbabbabaabbaaaabaaaabbaab
aaaababaaabaaaaabbabbabaababaabaaabbabbb
abbaaabbbbababaabaaaabaa
baabbbbabaabaabbbaabbaab
baababbabbbabaabaaabaabbbaaabaaabbbbbaba
bbbababbaabbbabbbbbbbbaa
bbbbbbabbbabbabbabbaabbbaaabaaab
bbbababbababaaababaaabbabaababbb
baabaabbaabbabaabbbaaaab
bbaaaababbabababaaabaaaaaaabaabaabbbbaba
bbabbaaabbbbbaaabbbaabab
ababaaababbabababbaababb
aabaaaababbabbabbabbbbaa
aaaabaaabbaabbabababaaaaabbbabbb
abbbabaabbabbbaaaabaaababbabbabbbbaabaababaaabbb
bbaaaabbaabbaaabaaaaaaabaaabbbbaaabbaabaaababaaabbaaabaa
babbbabbaaabababbbabaaab
abbabbabbaabbababbabbbbaaaaabbbabbababba
abbaababbbaabbababbbabbaaabbbbbaaaabababaabababbbbaabbbaabbabaabbbbbabbaabaaaaab
babbbabaababbbabbbbabbba
baaabaabaaaaaaabbabaabba
baabaabbbaabaaabbbabbaaabaaaaaabbbbbaabb
bbababbbabaaaabbbababaaa
baababbaaaabbbbaabbababbaabbaabaabaabbbabbabaaab
bbbbbbaaabbbababbaababbbbaaabbaabbaababb
bbabbaaabaabbbaababbaabb
ababbbababbbbbbbababbabb
babababababaaaaaaaaababababbaaabbabaabab
abaaabaaabbaabbbbabbaaba
aaaababbbabbbbbbbbbaabba
babbbabaaababaaabaaababb
ababbbabbbabbabbbbababaaaaabbbaa
aaaaabbbaabbaababbbbbbbbbaaaabbbaaaaabaabbbbaabaaababbaabababbabbabbabbb
abbabaabbbabbbaaaaabaaaabbbbbaaa
bbbbabbaaabaabbbaabababb
bbbabbaabbbaabaaabaaabaabaaaaaabaabbbbaa
bbbababbbabaaaabaaabbaba
abbababbabaababbbaabbabaaaabaabbaaaabaaabbabbbbbababababbbbaabba
aaabaaaaaababbbaabbaabab
abaabbaabaaabababaaabbbababbbbab
aaaaabbbbbababbbbabaaaaa
aabaaabaaababaaaabaabaaa
aabaabababbbaaaabaabbaaa
babaabaababaabbbbbababbbaaababbaabbabaabbabbbbabbaabaaba
aabaaabaaaabaaaabbaabbbb
bbbbaabaabaaabaaaababbbabaabbaab
bbabababbbabbbbaabbbbaab
baabababbaabbbbbbaaabbbabbbabbbbbabaabbababbaaabaabababa
abbbabbbabbabbabbaaaabaabbbbbaaaabaabababaababaaaaabababaababbba
baabbabbbaabbbbaabaabbabaababbaa
abaababbaaaaabbbaabbbaabaaababbbbbaaababaaaaababbabbaabb
bbbabbbbababababaaabaaabbaabbabaabbabbbbaababaaaabbbabbbbbbabbbbaaaaababbaaaaaaa
aababbabaabababaaababbabbaaaaaaabbbbbbaabbaaabbbbbbaabbb
ababbbabaaabaababbbaaabb
abbbbbbaabbbbbbbbbababba
bbabbbbabbabbbaaabbabaababbbaaaaaabbaaaa
bbaabaababbbbbbbabaabaab
aaaaabbabbbbabbabaabbbbbbabbabaaababbabbaabbaaaa
abbaabbabbbbbbbbabababba
abababbbabbababbabbabbaabbbbaabb
baaabaaaaaaaabbabaaababb
abaabbbbbabaaaabbaaaabaa
bbaabaaabbaabaaaabbbbbaa
baabaaabbbbbbbbabbababaaabbaaaab
bbaaabababbaaabbaabaaabbaabaabbabaaaabaa
aababbbbbbabbabbbbabbbbaaabababb
abbbabaabbaaaaabaaabbaaa
abbbaaaabaaabaaaaaaaaaaabbaabbab
aaabaaaabbbbbbbaabbababbbabbbabaabbabbaabbbbaaaabbbaabbb
aabbaaabbbabbabbbbbaabaaaaaaaabaabbbaabb
babbbbbbaabbabaabaaaabab
aaaaabbbaaaaabbaaababbbaabababab
baabaabbbbbbbbbabbaabaaababaabab
aababbbbaaaabbaababaaaaabaabbbabbbababaaaabaaabbaaaabaabababbbabbabaabbabaabaaaa
aababaaaabbbababbbaabaabbbbababbbbaaabababababba
bbbbbbabbabbababaaaaabaabaabbbaabbaaabababbaaaab
abbaabbbaabbbbabbbabbaba
bbaababaabaabbbbbabababb
aabaabbbbbbbbbbababbababbbbbababbabbaaab
bbabbaabaabbaabababaaaabbabbaaaaabaaabab
babbaaaabbabbabbabbaabab
bbbababbabbababbbabbaabb
aaababbabaaaaaababbbabba
babaabaabaaababaaabaaabaaaabbabb

128
2020/d20/ex1/ex1.py Executable file
View file

@ -0,0 +1,128 @@
#!/usr/bin/env python
import functools
import itertools
import math
import sys
from collections import defaultdict
from copy import deepcopy
from typing import Dict, Iterator, List, Set, Tuple
Tile = List[List[str]]
Tiles = Dict[int, Tile]
def parse(raw: str) -> Tiles:
def parse_tile(raw: List[str]) -> Tile:
return [[line[i] for i in range(len(line))] for line in raw]
res = {}
for lines in map(lambda s: s.splitlines(), raw.split("\n\n")):
if len(lines) == 0:
continue
nums = int(lines[0][5:-1])
res[nums] = parse_tile(lines[1:])
return res
def rotations(tile: Tile) -> Iterator[Tile]:
yield tile
for __ in range(3):
prev = deepcopy(tile)
for i in range(len(tile)):
for j in range(len(tile[i])):
prev[i][j] = tile[len(tile) - j - 1][i]
tile = prev
yield tile
def flips(tile: Tile) -> Iterator[Tile]:
yield tile
yield tile[::-1]
yield [line[::-1] for line in tile]
yield [line[::-1] for line in tile[::-1]]
def transforms(tile: Tile) -> List[Tile]:
# Can't use a set with lists...
res: List[Tile] = functools.reduce(
lambda l, it: l + [it] if not any(it == other for other in l) else l,
itertools.chain.from_iterable(map(rotations, flips(tile))),
[],
)
return res
def borders(tile: Tile) -> Iterator[str]:
# They should match on same axis (i.e: go clockwise and counter-clockwise)
return map(
lambda s: "".join(s),
[
tile[0],
[line[-1] for line in tile],
tile[-1],
[line[0] for line in tile],
],
)
Transforms = Dict[int, List[Tile]]
Tiling = List[List[Tuple[int, int]]] # Which tile, and which transform
def build_tiling(tiles: Tiles) -> Tuple[Transforms, Tiling]:
transform_mapping = {num: transforms(tile) for num, tile in tiles.items()}
trans_borders: Dict[int, Dict[int, List[str]]] = defaultdict(dict)
for num, trans in transform_mapping.items():
for i, t in enumerate(trans):
trans_borders[num][i] = list(borders(t))
length = math.isqrt(len(tiles))
tiling = [[(-1, -1)] * length for __ in range(length)]
def rec(x: int = 0, y: int = 0, used: Set[int] = set()) -> bool:
if x == length:
return True
for num, borders in trans_borders.items():
if num in used:
continue
used |= {num}
for trans, border in borders.items():
top, __, __, left = border
if y > 0:
nid, ntrans = tiling[x][y - 1]
__, right, __, __ = trans_borders[nid][ntrans]
if left != right:
continue
if x > 0:
nid, ntrans = tiling[x - 1][y]
__, __, bottom, __ = trans_borders[nid][ntrans]
if top != bottom:
continue
tiling[x][y] = num, trans
next_x, next_y = (x, y + 1) if y < (length - 1) else (x + 1, 0)
if rec(next_x, next_y, used):
return True
used -= {num}
tiling[x][y] = (-1, -1)
return False
assert rec()
return transform_mapping, tiling
def solve(tiles: Tiles) -> int:
transforms, tiling = build_tiling(tiles)
return tiling[0][0][0] * tiling[0][-1][0] * tiling[-1][0][0] * tiling[-1][-1][0]
def main() -> None:
input = parse(sys.stdin.read())
print(solve(input))
if __name__ == "__main__":
main()

1728
2020/d20/ex1/input Normal file

File diff suppressed because it is too large Load diff

185
2020/d20/ex2/ex2.py Executable file
View file

@ -0,0 +1,185 @@
#!/usr/bin/env python
import functools
import itertools
import math
import sys
from collections import defaultdict
from copy import deepcopy
from typing import Dict, Iterator, List, Set, Tuple
Tile = List[List[str]]
Tiles = Dict[int, Tile]
def parse(raw: str) -> Tiles:
def parse_tile(raw: List[str]) -> Tile:
return [[line[i] for i in range(len(line))] for line in raw]
res = {}
for lines in map(lambda s: s.splitlines(), raw.split("\n\n")):
if len(lines) == 0:
continue
nums = int(lines[0][5:-1])
res[nums] = parse_tile(lines[1:])
return res
def rotations(tile: Tile) -> Iterator[Tile]:
yield tile
for __ in range(3):
tile = [
[tile[j][i] for j in range(len(tile))]
for i in range(len(tile[0]) - 1, -1, -1)
]
yield tile
def flips(tile: Tile) -> Iterator[Tile]:
yield tile
yield tile[::-1]
yield [line[::-1] for line in tile]
yield [line[::-1] for line in tile[::-1]]
def transforms(tile: Tile) -> List[Tile]:
# Can't use a set with lists...
res: List[Tile] = functools.reduce(
lambda l, it: l + [it] if not any(it == other for other in l) else l,
itertools.chain.from_iterable(map(rotations, flips(tile))),
[],
)
return res
def borders(tile: Tile) -> Iterator[str]:
# They should match on same axis (i.e: go clockwise and counter-clockwise)
return map(
lambda s: "".join(s),
[
tile[0],
[line[-1] for line in tile],
tile[-1],
[line[0] for line in tile],
],
)
Transforms = Dict[int, List[Tile]]
Tiling = List[List[Tuple[int, int]]] # Which tile, and which transform
def build_tiling(tiles: Tiles) -> Tuple[Transforms, Tiling]:
transform_mapping = {num: transforms(tile) for num, tile in tiles.items()}
trans_borders: Dict[int, Dict[int, List[str]]] = defaultdict(dict)
for num, trans in transform_mapping.items():
for i, t in enumerate(trans):
trans_borders[num][i] = list(borders(t))
length = math.isqrt(len(tiles))
tiling = [[(-1, -1)] * length for __ in range(length)]
def rec(x: int = 0, y: int = 0, used: Set[int] = set()) -> bool:
if x == length:
return True
for num, borders in trans_borders.items():
if num in used:
continue
used |= {num}
for trans, border in borders.items():
top, __, __, left = border
if y > 0:
nid, ntrans = tiling[x][y - 1]
__, right, __, __ = trans_borders[nid][ntrans]
if left != right:
continue
if x > 0:
nid, ntrans = tiling[x - 1][y]
__, __, bottom, __ = trans_borders[nid][ntrans]
if top != bottom:
continue
tiling[x][y] = num, trans
next_x, next_y = (x, y + 1) if y < (length - 1) else (x + 1, 0)
if rec(next_x, next_y, used):
return True
used -= {num}
tiling[x][y] = (-1, -1)
return False
assert rec()
return transform_mapping, tiling
def trim(trans: Transforms, tiling: Tiling) -> Tile:
def trim_tile(tile: Tile) -> Tile:
return [line[1:-1] for line in tile[1:-1]]
def tiling_to_tile(tiling: List[List[Tile]]) -> Tile:
res: Tile = []
for i in range(len(tiling) * len(tiling[0][0])):
res.append([])
tile_line_idx = i % len(tiling[0][0])
for j in range(len(tiling[0]) * len(tiling[0][0][0])):
tile = tiling[i // len(tiling[0][0])][j // len(tiling[0][0][0])]
tile_row_idx = j % len(tiling[0][0][0])
res[-1].append(tile[tile_line_idx][tile_row_idx])
return res
tiles = [[trim_tile(trans[num][id]) for num, id in line] for line in tiling]
return tiling_to_tile(tiles)
def find_monster(image: Tile, monster: Tile) -> Iterator[Tuple[int, int]]:
def monster_at(x: int, y: int) -> bool:
for i in range(len(monster)):
for j in range(len(monster[0])):
if monster[i][j] == " ":
continue
if image[x + i][y + j] != "#":
return False
return True
# Returns upper left corner if found
for i in range(len(image) - len(monster)):
for j in range(len(image[0]) - len(monster[0])):
if monster_at(i, j):
yield i, j
def remove_monster(image: Tile, monster: Tile, x: int, y: int) -> None:
for i in range(len(monster)):
for j in range(len(monster[0])):
if monster[i][j] == " ":
continue
image[x + i][y + j] = " "
def solve(tiles: Tiles) -> int:
image = trim(*build_tiling(tiles))
monster = [
[char for char in line]
for line in (
" # ",
"# ## ## ###",
" # # # # # # ",
)
]
monsters = transforms(monster)
for monster in monsters:
for coords in find_monster(image, monster):
remove_monster(image, monster, *coords)
return sum(sum(char == "#" for char in line) for line in image)
def main() -> None:
input = parse(sys.stdin.read())
print(solve(input))
if __name__ == "__main__":
main()

1728
2020/d20/ex2/input Normal file

File diff suppressed because it is too large Load diff

64
2020/d21/ex1/ex1.py Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env python
import functools
import re
import sys
from collections import defaultdict
from copy import deepcopy
from typing import Dict, List, Set, Tuple
def parse(raw: List[str]) -> Tuple[List[Set[str]], List[Set[str]]]:
def parse_ingredients(line: str) -> Set[str]:
pos = line.find(" (contains ")
if pos != -1:
line = line[:pos]
return set(line.split())
def parse_allergens(line: str) -> Set[str]:
pos = line.find("(contains ")
if pos == -1:
return set()
return set(re.findall("([^ ]+)[,\\)]", line))
ingredients = []
allergens = []
for line in raw:
ingredients.append(parse_ingredients(line))
allergens.append(parse_allergens(line))
return ingredients, allergens
def find_allergens(
ingredients: List[Set[str]], allergens: List[Set[str]]
) -> Dict[str, Set[str]]:
all_ingredients = functools.reduce(lambda lhs, rhs: lhs | rhs, ingredients)
possibilities: Dict[str, Set[str]] = defaultdict(lambda: deepcopy(all_ingredients))
for ing, all in zip(ingredients, allergens):
for allergen in all:
possibilities[allergen] &= set(ing)
return dict(possibilities)
def solve(raw: List[str]) -> int:
ingredients, allergens = parse(raw)
possibilities = functools.reduce(
lambda lhs, rhs: lhs | rhs, find_allergens(ingredients, allergens).values()
)
return sum(
bool(ingredient not in possibilities) for i in ingredients for ingredient in i
)
def main() -> None:
input = [line.strip() for line in sys.stdin]
print(solve(input))
if __name__ == "__main__":
main()

40
2020/d21/ex1/input Normal file
View file

@ -0,0 +1,40 @@
zdmhtpg mlcvjc kgdvd htxvfq lxgxp kqxz pfhfb fnkdvt ccn vhbjp hqhnh xcljh ndnlm shc ncrn nrdtprm skrxt qrdpc dcvtrq gdmv nxcrg hhxch mv dscm qzln zjlz qkbm dmjzc fjqv jqlp zcxthb sdclrlb bbtn jrspd lqbcg gdljd mvtkk zbhp hcc ntbqk lvft glj fsr hnh nvnx dvjrrkv fdqp lctltv hjn mknsj gtsslgk (contains sesame, shellfish, dairy)
gtdb nxcrg fzl gtsslgk sgdlhb fzckq mknsj kscd dgdn svzfl mlcvjc ntbqk ctkjrt gdmv tkvddn rzhktt zgcf jfm gzhlbn kphbtmkx mgbv pkrdz fsr drj lqgn tgkgj ndnlm zczht tlv qkbm ccn hhxch lgjsd dvjrrkv qfgbx rqxfdd hrtd ktsnt jmt kgfld mxm knfx kshg nhlxntg zdmhtpg qpp mv ssk tgxvz brjcp skrxt xjksh fsxf tpdc crjddsgj hcrsbr bgc jqlp dmjzc hxgdp xcljh xjqkbq hnh bsgnsc gqkf bzlnnv jjmmn gbmv zdqd zbhp (contains dairy)
hxgdp nkgzzg tgxvz tgkgj hqhnh fdjrml gnnzj fsxj zbhp rqxfdd ndnlm fsr nrgn hhxch gnq sgqrvd sm qjktms jjmmn xcljh qzln jqlp nxcrg bsgnsc jxftql lxgxp kgfld jmt ntbqk kvqq fnkdvt gppfld flg kscd jjdgtt nvnx vhbjp nhlxntg zkhpc bgjcg tpdc jkgf tnvtm rnln mgbv nrdtprm cntfq brhmkh rnsqjkq mv dvjrrkv crjddsgj mxm nqbjlf pkrdz xvzlpx dmjzc brjcp hcrsbr nkcl skrxt zfqhnt rglsgs pfhfb nsnzxsc ncrn fzckq rzhktt dcvtrq zgcf qgl (contains soy, wheat, sesame)
sgqrvd dvjrrkv qszr brhmkh znzx tkvddn mgbv kgpbh gtdb gdmv zjkt zdqd mhqxk cntfq hrtd sgdlhb lxgxp zbhp bgjs hxgdp rfcl lvft qgl ndvnj glj ptcnh xjqkbq zkhpc bgc rnln xntpsg xvzlpx zfqhnt xxbnf ntbqk tgkxxjm ncksb flg nrgn kqxz hkdls gqkf fjqv qpp krhmfb fdjrml tmlm tpdc rpqss qzln ckzg xcljh jdcbc kgfld ndnlm kvhbj svzfl jfm nrlbfc tkxxdnh fsr qjn lqbcg sdclrlb nxcrg gnq vchxzh rzhktt tvgcv (contains shellfish)
pfhfb rpqss bzlnnv vchxzh ctkjrt hjn ckzg hpsrqbl nzxs zcxthb jmt lqbcg ndvnj qbvxrbs dvjrrkv jvgbct zjkt ndnlm nrgn mxm xcljh rzhktt fnkdvt hcc knfx tgkxxjm hqhnh bhghks kgfld tkqp qgl tkvddn gzhlbn rglsgs jjdgtt kvqq gfq zmnflgt fsr qjktms ssk jdcbc kshg dgdn jfm gzthtlg mkmcq tpdc nxcrg mgbv xjqkbq qkbm qpp rnln zbhp chjqncr sm jxftql xjksh tnvtm gbmv tgxvz zczht tkxxdnh kssncfd ptcnh bdfmncs mvtkk rfcl zkhpc qjn xxbnf gdmv fzl lxgxp mhqxk (contains soy, dairy)
xjqkbq xvzlpx nqbjlf qbvxrbs gtsslgk bqjqf sdclrlb ccn qpp nsnzxsc zmnflgt pkrdz ndnlm bsgnsc zgcf zbhp tgkgj jfm lvft nrgn xcljh shc bpvmb ltjt jjdgtt dvjrrkv ckzg mgbv sm hxgdp fsxf nhlxntg kqxz kvqq gzthtlg pfhfb htxvfq nvnx jxftql lgjsd sgqrvd skrxt cntfq glj bgjs mxm bbxsn rpgrk tmlm fsr rqxfdd bgjcg qkbm fdqp hpsrqbl gppfld vchxzh svjp qjktms rnsqjkq nxcrg mv tgxvz krhmfb nxcsxc zcxthb hcrsbr qjn tnvtm qrdpc lvtj qfgbx fjqv rpqss nkgzzg (contains fish, wheat, sesame)
jdcbc prgj rnln zdqd zbhp cntfq mgbv gfq dgdn sm gdmv hkdls hnvhqczc ltjt ckzg skkt tkvddn lsll ndnlm flg nxcrg kgpbh zjlz dvjrrkv zgcf mhqxk gnq qgl ccn hcc hvrrhc bgc rpqss gqkf hqhnh nxbn bsgnsc lqgn gzthtlg xcljh jxftql nrdtprm bdfmncs bhghks kgfld zczht hrtd lqbcg rqxfdd bbtn dmjzc fsr mkmcq zkhpc (contains sesame)
nqbjlf dcvtrq cntfq sdclrlb kvhbj skkt jvgbct xjqkbq knfx lsll zdmhtpg hnh fnkdvt gtdb tgxvz xjksh gzthtlg bhghks qpp zgcf ptcnh mvtkk pfhfb jjmmn ktsnt kpzbxfp tgkgj glj rfcl fsr fsxf lqgn gppfld ssk mlcvjc mhqxk kqxz kshg jjdgtt tvgcv xcljh qszr prgj gfzjc jmt qrdpc hhxch bgc mgbv zbhp kssncfd nhlxntg hkdls bgjs gfq nxcrg hcc fdqp lpm jrspd bsdc nrgn dscm bzlnnv bpvmb qjn nkgzzg rglsgs fjqv xvzlpx xxbnf qjktms xcsxh lqbcg bdfmncs qbvxrbs nkcl skrxt hxgdp ndnlm vhbjp nxcsxc flg nxbn kgpbh (contains soy, wheat, peanuts)
zjlz jdcbc nkcl rpqss gqkf lsll flg zbhp ltjt jmt fzckq rnln mknsj ccn qkbm chjqncr lfgh bsdc bzlnnv bbtn fsr skrxt kvhbj hpsrqbl kgdvd lpm dvjrrkv ptcnh tnvtm sgdlhb rfcl gtdb tvgcv rpgrk mkmcq hvrrhc qjktms bsgnsc zsggkm pvnr shc zcxthb lhcm bqjqf fzl rnsqjkq lqgn brhmkh jkgf mv xntpsg mgbv fdjrml dgdn mhqxk ktsnt xcljh qfgbx tkvddn xjksh lqbcg pkrdz brjcp bbxsn (contains fish, peanuts)
xjcvt kgfld gbmv fsxj bqjqf qgl rnln hcrsbr nxbn zcxthb zfqhnt skrxt tgkxxjm dscm hkdls dvjrrkv lvtj gdljd zmnflgt pkrdz xcljh bsgnsc zjkt zkhpc xxbnf tpdc znzx tgkgj qszr bbxsn qfgbx rzhktt rfcl xcsxh ctkjrt bgjs mhqxk mgbv qrdpc ktsnt jjmmn fmcnhq tkxxdnh jrspd qkbm qpp qbvxrbs kshg prgjph skkt mvtkk ncksb hpsrqbl kphbtmkx dgdn ncrn fnkdvt dcvtrq mv nrdtprm kvqq zdqd gzhlbn drj vchxzh fsr nrlbfc zsggkm tlv bgc sgqrvd lctltv mlcvjc lsll hnnmrxh lfgh bgjcg ntbqk htxvfq rnsqjkq hrtd bhghks gtsslgk dftg lqbcg jqlp zbhp qjn bdfmncs (contains peanuts, sesame)
zkhpc lpm fdqp kpzbxfp hkdls mlcvjc bgjs qckqc ndnlm skrxt zdmhtpg dgdn nkgzzg qjn tvgcv brjcp bsdc kshg kgdvd xcljh crjddsgj jvgbct glj xjksh xvzlpx shc mxm gzhlbn ctkjrt ckzg fsr rnsqjkq mgbv rpgrk zdqd rnln gdljd dcvtrq fjqv fmcnhq svzfl fdjrml hrtd dmjzc nxcsxc sgdlhb mhqxk jdcbc qzln dscm zbhp bbxsn fnkdvt kgpbh zjkt tgkxxjm lhcm ptcnh skkt jqlp mv nrdtprm gtdb htxvfq cntfq tnvtm lqbcg (contains soy, nuts)
ntbqk ccn pkrdz krhmfb hkdls kgpbh bhghks bqjqf hpsrqbl bpvmb fzckq nhlxntg pfhfb xcljh bzlnnv nkgzzg cntfq zbhp jqlp ndnlm tlv qbvxrbs nrdtprm gdmv ssk mgbv gdljd dvjrrkv bsgnsc tpdc rnsqjkq znzx flg fsr zlfm zjkt nvnx glj knfx lqbcg hjn (contains wheat, sesame)
qjn sgdlhb rnsqjkq gdljd dvjrrkv nkcl jxftql kssncfd jvgbct kgfld bgc nxcsxc ndnlm nrdtprm kpzbxfp fsxf gnq vhbjp nvnx hvrrhc tgxvz nsnzxsc tvgcv xvzlpx prgjph kqxz fsr hnnmrxh lqbcg hkdls glj ctkjrt zdmhtpg qszr nhlxntg gqkf tlv hxgdp nrgn ndvnj qckqc xntpsg ltjt rnln zbhp gdmv xxbnf hhxch fnkdvt knfx xcljh kgdvd bdfmncs gfq lpm mkmcq skrxt hnvhqczc krhmfb dftg gtsslgk gzthtlg flg zgcf zkhpc brhmkh pvpfn ssk dgdn bsdc jdcbc (contains fish, sesame, dairy)
bpvmb jvgbct nrgn zbhp dvjrrkv bqjqf mkmcq xcljh fsxf mknsj kssncfd lqbcg skrxt tvgcv xbdhth tkvddn nrdtprm mhqxk chjqncr ndnlm lctltv hnnmrxh rpgrk ccn rnln jdcbc gdljd dmjzc svjp lsll bdfmncs rnsqjkq qgl prgjph hqhnh xjqkbq jjmmn hcrsbr xcsxh drj cntfq fsr bsgnsc rfcl pvnr flg tgkxxjm zczht shc (contains soy, shellfish, sesame)
mlcvjc prgj xntpsg pfhfb gtsslgk nrgn kvqq lhcm fmcnhq qgl nrdtprm hcrsbr tgkxxjm lctltv fnkdvt hjn tvgcv prgjph zjlz rpqss bzlnnv zbhp dftg mkmcq tnvtm rqxfdd mknsj fsr xjqkbq pkrdz dscm gdljd nxcrg sm svjp ndnlm zlfm bgjcg rglsgs lvft mhqxk kpzbxfp lpm rnsqjkq ccn skrxt gqkf mxm gzthtlg dmjzc flg tkqp bgjs qpp bsgnsc cntfq skkt gtdb lqbcg xcljh gnnzj hqhnh jjdgtt gfzjc zgcf brhmkh sgqrvd dvjrrkv (contains shellfish, sesame)
dvjrrkv ccn lqbcg lctltv jvgbct tkqp hxgdp lhcm zsggkm bgc qjktms zjkt nvnx nxcsxc kqxz skrxt bhghks gzthtlg chjqncr htxvfq mv rnsqjkq sgdlhb crjddsgj rglsgs nrgn ndvnj ltjt hhxch xcljh hrtd fmcnhq nkgzzg dscm ncrn zbhp mgbv prgj pfhfb tgkgj hpsrqbl kscd lxgxp bbxsn gdmv tgkxxjm glj nzxs tpdc fsr tmlm lgjsd bsgnsc qjn rqxfdd hqhnh cntfq (contains fish)
hpsrqbl brjcp qpp shc tgkxxjm bbtn xcljh gbmv znzx jkgf zcxthb jjmmn zczht bgc lvtj drj rzhktt tkxxdnh tlv dcvtrq nsnzxsc hkdls tvgcv dvjrrkv qkbm knfx zjkt mhqxk bpvmb ckzg bgjs gfzjc bhghks gtdb nzxs gnnzj sm jjdgtt zjlz rnln xjqkbq ctkjrt xvzlpx xntpsg htxvfq tmlm zdqd lqbcg fsr ndnlm rfcl kgdvd skrxt mgbv hhxch mknsj hxgdp fjqv ssk qszr hqhnh xcsxh chjqncr dmjzc crjddsgj prgjph dscm sgdlhb hjn cntfq bsgnsc qjn nvnx sdclrlb jqlp ncksb (contains sesame)
fnkdvt nxcrg sgdlhb kshg glj jvgbct tlv lgjsd qbvxrbs tgkxxjm xcsxh jfm fdjrml mgbv kvqq xbdhth fsr rpgrk qkbm hjn rfcl dftg tkxxdnh mhqxk nsnzxsc zgcf dvjrrkv fzckq prgjph lqbcg skrxt bgc hpsrqbl lsll tmlm bgjcg gtdb nvnx qszr lxgxp zbhp hcc tgxvz xjqkbq nxbn fdqp zdqd xxbnf fsxf ltjt ptcnh xcljh tkqp tkvddn nrlbfc jqlp jrspd (contains fish, peanuts)
nzxs ckzg nrlbfc nsnzxsc xbdhth pvpfn tvgcv tmlm mvtkk ncksb mhqxk ltjt zbhp fjqv rfcl tkqp lpm gzthtlg hkdls hcrsbr qckqc bhghks qgl kvhbj nkcl jmt lhcm bgjcg flg nqbjlf kvqq kqxz xcljh nrgn pvnr bzlnnv lqgn gnnzj bdfmncs ccn lvtj xjcvt dvjrrkv jjmmn qrdpc ntbqk sgqrvd kscd hcc cntfq gnq tgkgj jxftql jrspd fzl fsr lqbcg qkbm mgbv brjcp bgjs gtdb drj qjktms bqjqf hxgdp skkt prgj kssncfd xntpsg hhxch fsxf hqhnh qpp nxcsxc jvgbct qjn lfgh ndnlm mknsj zjkt mlcvjc lgjsd (contains shellfish)
qgl rnsqjkq hnnmrxh lsll nkcl fsr qjktms ndnlm krhmfb rpgrk xcljh jfm lfgh xntpsg skkt gdmv dvjrrkv zbhp kphbtmkx lhcm vhbjp mgbv zsggkm fsxf ccn nrgn nrdtprm bpvmb znzx bbtn dgdn bhghks zjkt svzfl jjmmn tlv bsgnsc bgc qkbm skrxt bgjcg fdqp ltjt rfcl bgjs rnln gtsslgk zjlz (contains wheat)
nhlxntg hqhnh qfgbx kssncfd zkhpc bdfmncs zcxthb drj sgqrvd lqgn rqxfdd hvrrhc prgj tgkgj nrdtprm skrxt jxftql fsr xcljh qpp shc zbhp qjktms zsggkm ccn chjqncr znzx pkrdz prgjph ntbqk ndnlm nrgn kgdvd tkxxdnh tpdc dvjrrkv qzln knfx nkgzzg rnsqjkq kpzbxfp bbtn tkqp mgbv rzhktt lhcm rglsgs fdqp fmcnhq gzthtlg nvnx ssk bhghks kvhbj hhxch tlv fnkdvt htxvfq zfqhnt xvzlpx lpm qszr hnnmrxh hcrsbr jqlp nsnzxsc (contains dairy, peanuts, wheat)
gfzjc hhxch rzhktt gtdb ssk zbhp zfqhnt jkgf tkqp dvjrrkv kgpbh mknsj bsdc lgjsd mgbv zcxthb hrtd nqbjlf mlcvjc hxgdp tgxvz gqkf fmcnhq tpdc lxgxp hcrsbr znzx zlfm fjqv kvqq nhlxntg zjlz brjcp zkhpc skrxt nrlbfc jdcbc qfgbx svzfl fzckq kgfld prgj gzhlbn lhcm qkbm fsxj hqhnh kscd vhbjp fsr lsll qbvxrbs gfq tnvtm lqbcg nkcl ndnlm sgqrvd xjqkbq (contains wheat, shellfish, fish)
gdmv bbxsn kvqq hnvhqczc lqbcg xjqkbq jvgbct mlcvjc gfq jrspd lxgxp jkgf tkvddn bsgnsc lqgn xcljh fsxf qjktms dscm mgbv fsr ndvnj nrdtprm jjmmn xvzlpx nkgzzg rnln nxcsxc zjkt sdclrlb nhlxntg kphbtmkx gnq zbhp fzckq zlfm hvrrhc zsggkm xcsxh ntbqk skkt jdcbc bgc bsdc prgj shc nzxs bpvmb hcc ncrn xjcvt nrlbfc jqlp ktsnt nvnx gnnzj tkqp nxbn ndnlm sgdlhb bqjqf kqxz qzln zjlz tkxxdnh bdfmncs kpzbxfp hrtd fzl skrxt sgqrvd zdmhtpg dftg fnkdvt lgjsd mv (contains nuts, fish)
nxcrg jqlp xcljh nkcl qjn rpgrk xbdhth vhbjp kqxz zfqhnt nrdtprm ltjt tkxxdnh rqxfdd fdqp bsdc gzhlbn bpvmb ndnlm bbtn skrxt jdcbc fmcnhq pkrdz zsggkm rzhktt ccn gbmv ncrn rglsgs dmjzc sgdlhb prgjph lpm zcxthb dftg qjktms pvnr hnnmrxh kssncfd bdfmncs bhghks lhcm lgjsd ssk bgc fsr gfzjc rnsqjkq zbhp lqbcg krhmfb mkmcq zlfm brhmkh xntpsg hnh bsgnsc dvjrrkv tvgcv sm fdjrml prgj hhxch tpdc fsxf nkgzzg nzxs gnq tmlm (contains dairy)
nrlbfc nxcsxc jvgbct dvjrrkv prgjph gqkf ndnlm lhcm mvtkk xcsxh gtsslgk mgbv kgpbh zbhp qbvxrbs kshg gfq ktsnt bbxsn hjn jfm jxftql jmt xbdhth xcljh zmnflgt kgfld nrgn fnkdvt fdqp skrxt svzfl bgjcg sgqrvd ssk svjp sgdlhb vchxzh kgdvd dgdn xntpsg tpdc zjlz zgcf rnsqjkq zlfm chjqncr tmlm dftg tgxvz jkgf lpm hcc qjn tkxxdnh lqbcg kscd lctltv pvnr ntbqk lsll qszr mv hvrrhc fjqv (contains wheat)
vhbjp fsxj jxftql tkxxdnh nzxs fnkdvt fmcnhq lgjsd chjqncr xcljh brjcp hrtd kssncfd ssk mgbv xvzlpx bgjs rpgrk kgfld gbmv ndvnj ccn rnsqjkq xjksh ncrn brhmkh lxgxp qzln zdmhtpg tkvddn lsll nrgn pvpfn lqgn nxbn lvtj dvjrrkv dscm bsdc hqhnh mxm fsr nrdtprm skrxt nhlxntg tpdc mkmcq bqjqf lhcm hxgdp jkgf hkdls fsxf jmt fzl kshg xjcvt lqbcg jdcbc flg rnln ktsnt zbhp gqkf kphbtmkx rglsgs (contains wheat, sesame, dairy)
fmcnhq prgjph jdcbc gtsslgk xcljh fsr zdqd hnh bzlnnv krhmfb mknsj nrdtprm kgpbh lpm tnvtm zbhp fzckq xcsxh lvft hqhnh hcrsbr jfm bsgnsc qfgbx mgbv lsll qjn hrtd tkvddn sdclrlb dscm lxgxp jjdgtt kqxz zjlz tlv xjksh fdqp ptcnh rglsgs dvjrrkv flg ntbqk bsdc xjqkbq gdljd jmt zjkt gdmv fjqv nxcrg zczht bbxsn nkgzzg zmnflgt skrxt ndnlm brhmkh glj zfqhnt tkxxdnh gqkf (contains peanuts, shellfish)
svzfl bdfmncs mlcvjc xjksh fsr shc ssk mknsj tkqp znzx hqhnh zdqd jjmmn svjp ndnlm lctltv tkvddn bzlnnv jrspd kssncfd zjlz pvpfn fdjrml tgkgj nrgn nvnx bqjqf hpsrqbl hnh rnln zjkt fdqp zlfm xjcvt gbmv tkxxdnh kgdvd mgbv dftg jdcbc fnkdvt tvgcv pkrdz zkhpc lqbcg jmt kvhbj nxcrg nsnzxsc gzhlbn zbhp gdljd skrxt skkt mv qjktms dvjrrkv (contains shellfish)
zjlz gzthtlg vchxzh zfqhnt dftg bdfmncs ndnlm dvjrrkv vhbjp shc znzx fdqp fsr svjp nrdtprm tgkxxjm zbhp nxcsxc ndvnj jjdgtt qjktms mhqxk skrxt rglsgs pvpfn xvzlpx jfm prgjph mlcvjc fmcnhq gppfld tvgcv qszr pvnr bsdc bqjqf jxftql hpsrqbl qjn zkhpc qzln crjddsgj lsll bgjcg fdjrml tgxvz ssk lpm brhmkh zczht zcxthb jrspd ltjt lxgxp lqbcg xcljh dgdn gdljd rfcl rqxfdd tpdc (contains nuts, sesame, dairy)
qjn nrgn pvpfn bsgnsc xxbnf jvgbct pfhfb lqbcg zsggkm xbdhth lvtj xcljh tlv lsll lqgn nrlbfc qckqc hrtd shc sgdlhb zcxthb ssk bdfmncs hkdls tnvtm nxbn jfm hnnmrxh dvjrrkv skrxt jdcbc ndvnj jjdgtt jjmmn gtdb hjn tmlm gdljd ndnlm nhlxntg hnh kpzbxfp bgjs fsr jqlp qjktms zczht rnsqjkq zbhp vhbjp brjcp (contains wheat)
hqhnh fsr zbhp nrgn zlfm ndvnj nkgzzg kgdvd ssk qckqc sdclrlb ptcnh bpvmb brhmkh dvjrrkv rpqss fnkdvt lfgh gdljd tvgcv nxcsxc dmjzc fmcnhq qzln sgdlhb qjn zmnflgt vchxzh tkvddn xcljh dgdn bgjs hhxch pfhfb lqbcg kscd lhcm nrlbfc pkrdz htxvfq skrxt znzx ntbqk hkdls ktsnt bzlnnv rnsqjkq ndnlm sgqrvd tlv hcc zjlz gzthtlg jkgf svzfl tkxxdnh pvpfn nxbn ccn gzhlbn rqxfdd qfgbx rnln bqjqf qrdpc kgfld hnvhqczc gnq knfx tmlm nvnx zdqd zsggkm hjn jqlp gqkf bgjcg fdjrml (contains shellfish, dairy, sesame)
dmjzc qgl jjmmn mgbv qjktms qszr zlfm kgfld qkbm xjksh hnvhqczc xjcvt fsxj hjn fjqv rglsgs zbhp ccn kshg bsdc pvnr bgjcg nvnx hnnmrxh cntfq rpgrk gqkf shc nxbn qrdpc jrspd ktsnt brjcp dvjrrkv tgkxxjm jkgf kgpbh kgdvd zfqhnt lfgh ncksb nrdtprm vchxzh fsxf zdqd kphbtmkx skrxt flg gtsslgk zgcf tvgcv dftg lpm nxcrg dgdn xcljh qfgbx nzxs gbmv sgdlhb gdmv jdcbc fsr zjlz ctkjrt xntpsg hcc tkqp ptcnh gdljd rfcl znzx hpsrqbl xjqkbq jfm lqbcg nqbjlf mlcvjc tgkgj xbdhth zkhpc kscd nkgzzg svzfl sm jvgbct htxvfq rnsqjkq hnh mkmcq (contains wheat, sesame)
rnsqjkq zsggkm jqlp zdmhtpg bpvmb svjp pkrdz fsxf tkxxdnh zczht dcvtrq ndnlm cntfq jfm nkgzzg rqxfdd nrlbfc bzlnnv mkmcq fjqv tpdc hnh gtdb nxbn bbxsn mgbv pvpfn ncrn qfgbx sgqrvd knfx xjcvt brhmkh tvgcv gqkf prgjph qgl nvnx hqhnh dvjrrkv lfgh mknsj qzln jxftql kscd gtsslgk kpzbxfp hjn xcsxh gnq dmjzc xjksh tgkxxjm gzthtlg rzhktt zjlz kphbtmkx fsr fdqp sm bbtn lqbcg crjddsgj shc zbhp rglsgs nkcl hxgdp rfcl kgfld qrdpc skrxt gdljd znzx drj mlcvjc (contains shellfish, nuts, dairy)
svzfl fsxj jjmmn chjqncr lqbcg mxm zkhpc rqxfdd gnq kshg zczht gdljd ndvnj fzl rfcl dftg qbvxrbs qfgbx ndnlm mlcvjc mgbv bgjcg bpvmb vhbjp htxvfq lpm nrdtprm hnvhqczc gppfld brjcp jkgf rnsqjkq fzckq rglsgs dmjzc skrxt nsnzxsc kssncfd xcljh zbhp tgkgj kphbtmkx dgdn fsr knfx zdqd jqlp zfqhnt svjp (contains dairy)
nrlbfc bgc hhxch lsll qfgbx bsdc hqhnh tnvtm gnnzj gtdb dmjzc fsr lqbcg hrtd kvqq lgjsd jjmmn xjksh ncksb jvgbct vchxzh ndnlm htxvfq zkhpc fsxj ctkjrt lxgxp gdljd mgbv sdclrlb hnh kscd gzhlbn zdqd flg ncrn ckzg vhbjp mv jfm ptcnh gbmv sm kphbtmkx hcrsbr rpqss skrxt kgpbh kssncfd lvft bgjcg zczht bgjs nrdtprm xcljh bpvmb qckqc nzxs kqxz gdmv bzlnnv ndvnj jxftql hkdls jkgf xjqkbq hnvhqczc lfgh prgj mlcvjc pfhfb zbhp dgdn qrdpc nvnx prgjph bdfmncs nxcsxc tmlm jqlp tkqp sgdlhb fnkdvt qjn fzckq bsgnsc qbvxrbs (contains shellfish, peanuts, dairy)
bzlnnv zcxthb ndnlm jrspd lctltv mvtkk zjkt hqhnh fjqv gppfld zbhp sgdlhb knfx qfgbx hkdls jqlp pkrdz jxftql kvqq zkhpc gbmv fdjrml sgqrvd fmcnhq dcvtrq hnnmrxh tpdc kscd skrxt bsdc qzln xcljh lqbcg pvnr rpqss qckqc shc rnsqjkq dvjrrkv qrdpc znzx mgbv ssk gtsslgk bgjcg kqxz pvpfn hnvhqczc ptcnh bpvmb bbxsn hrtd hvrrhc gnq bgjs nxbn nxcsxc tkvddn qgl ndvnj (contains shellfish, nuts, wheat)
tgkgj kgpbh brhmkh bbxsn rnln mgbv bpvmb pvpfn rqxfdd hrtd kpzbxfp gtdb bbtn dgdn gfzjc kshg ltjt flg nrgn qrdpc chjqncr jrspd nrdtprm crjddsgj bdfmncs bhghks ncksb hkdls zlfm dvjrrkv gtsslgk sgqrvd sgdlhb xntpsg zbhp dcvtrq lxgxp gfq kphbtmkx lqbcg bqjqf qjn zkhpc xbdhth qzln bgjcg jkgf ncrn nxbn znzx nxcsxc brjcp nqbjlf zdmhtpg tgxvz fsr nrlbfc prgjph gppfld qkbm xcljh rzhktt ndvnj ndnlm fjqv hvrrhc (contains peanuts, dairy, soy)
tpdc nkcl nqbjlf ncksb crjddsgj prgj htxvfq gtdb bzlnnv nvnx hkdls fzl dvjrrkv sdclrlb tkqp xcsxh bqjqf hrtd dscm pfhfb svjp rqxfdd hvrrhc nrdtprm mgbv xjqkbq zkhpc zczht rfcl fsr rnsqjkq zbhp nhlxntg ndnlm jqlp bsdc hjn ntbqk gtsslgk brjcp rzhktt tlv tgkxxjm knfx ssk xjksh nxcrg dmjzc kgpbh nrgn lvtj svzfl shc mlcvjc lgjsd gbmv kvqq mhqxk nxcsxc gzhlbn tmlm zcxthb zfqhnt qpp xcljh lctltv hcc kscd fjqv mxm qrdpc zdmhtpg kvhbj skrxt qszr ptcnh xvzlpx zgcf dcvtrq bbtn zlfm jjdgtt jxftql fdqp xntpsg (contains fish, shellfish, sesame)
fsr dvjrrkv ckzg zjlz cntfq hcc nqbjlf svzfl ssk vchxzh nkcl zbhp mgbv hcrsbr fsxj xcsxh ccn rpgrk bhghks qckqc ptcnh gdljd hxgdp qkbm mvtkk rnsqjkq rnln prgjph gppfld dftg mlcvjc gtsslgk bgjcg bgc jdcbc zczht lctltv gfzjc svjp xvzlpx sdclrlb skrxt qfgbx nxcrg dcvtrq shc sgqrvd tgkgj kphbtmkx fzckq bqjqf crjddsgj nhlxntg jqlp gzthtlg zgcf ctkjrt zmnflgt bbtn drj ndnlm rpqss lvft xcljh (contains shellfish)
pkrdz ndvnj znzx xjksh zbhp hrtd kscd kgdvd ctkjrt zsggkm fzl zjkt zdmhtpg xcsxh tkqp lqbcg kssncfd bbxsn bzlnnv mgbv kgpbh krhmfb nsnzxsc ssk prgjph fmcnhq lfgh bgjcg fsr bbtn brjcp kqxz nxcrg skrxt rfcl kvqq brhmkh qbvxrbs hpsrqbl lgjsd kphbtmkx nzxs ndnlm bsgnsc mv xvzlpx ncksb nrgn rpqss tmlm nkcl dvjrrkv tnvtm lpm xbdhth sgqrvd lxgxp ktsnt mkmcq nhlxntg (contains fish, shellfish, nuts)

81
2020/d21/ex2/ex2.py Executable file
View file

@ -0,0 +1,81 @@
#!/usr/bin/env python
import functools
import re
import sys
from collections import defaultdict
from copy import deepcopy
from typing import Dict, List, Set, Tuple
def parse(raw: List[str]) -> Tuple[List[Set[str]], List[Set[str]]]:
def parse_ingredients(line: str) -> Set[str]:
pos = line.find(" (contains ")
if pos != -1:
line = line[:pos]
return set(line.split())
def parse_allergens(line: str) -> Set[str]:
pos = line.find("(contains ")
if pos == -1:
return set()
return set(re.findall("([^ ]+)[,\\)]", line))
ingredients = []
allergens = []
for line in raw:
ingredients.append(parse_ingredients(line))
allergens.append(parse_allergens(line))
return ingredients, allergens
def find_allergens(
ingredients: List[Set[str]], allergens: List[Set[str]]
) -> Dict[str, Set[str]]:
all_ingredients = functools.reduce(lambda lhs, rhs: lhs | rhs, ingredients)
possibilities: Dict[str, Set[str]] = defaultdict(lambda: deepcopy(all_ingredients))
for ing, all in zip(ingredients, allergens):
for allergen in all:
possibilities[allergen] &= set(ing)
return dict(possibilities)
def cross_eliminate(possibilities: Dict[str, Set[str]]) -> None:
while True:
eliminated = False
for pos in possibilities:
if len(possibilities[pos]) != 1:
continue
for other_pos in possibilities:
if other_pos == pos:
continue
if len(possibilities[other_pos] & possibilities[pos]) == 0:
continue
eliminated = True
possibilities[other_pos] -= possibilities[pos]
if not eliminated:
break
def solve(raw: List[str]) -> str:
ingredients, allergens = parse(raw)
possibilities = find_allergens(ingredients, allergens)
cross_eliminate(possibilities)
matches = [
(ingredient.pop(), allergen) for allergen, ingredient in possibilities.items()
]
matches.sort(key=lambda tup: tup[1])
return ",".join(ingredient for ingredient, __ in matches)
def main() -> None:
input = [line.strip() for line in sys.stdin]
print(solve(input))
if __name__ == "__main__":
main()

40
2020/d21/ex2/input Normal file
View file

@ -0,0 +1,40 @@
zdmhtpg mlcvjc kgdvd htxvfq lxgxp kqxz pfhfb fnkdvt ccn vhbjp hqhnh xcljh ndnlm shc ncrn nrdtprm skrxt qrdpc dcvtrq gdmv nxcrg hhxch mv dscm qzln zjlz qkbm dmjzc fjqv jqlp zcxthb sdclrlb bbtn jrspd lqbcg gdljd mvtkk zbhp hcc ntbqk lvft glj fsr hnh nvnx dvjrrkv fdqp lctltv hjn mknsj gtsslgk (contains sesame, shellfish, dairy)
gtdb nxcrg fzl gtsslgk sgdlhb fzckq mknsj kscd dgdn svzfl mlcvjc ntbqk ctkjrt gdmv tkvddn rzhktt zgcf jfm gzhlbn kphbtmkx mgbv pkrdz fsr drj lqgn tgkgj ndnlm zczht tlv qkbm ccn hhxch lgjsd dvjrrkv qfgbx rqxfdd hrtd ktsnt jmt kgfld mxm knfx kshg nhlxntg zdmhtpg qpp mv ssk tgxvz brjcp skrxt xjksh fsxf tpdc crjddsgj hcrsbr bgc jqlp dmjzc hxgdp xcljh xjqkbq hnh bsgnsc gqkf bzlnnv jjmmn gbmv zdqd zbhp (contains dairy)
hxgdp nkgzzg tgxvz tgkgj hqhnh fdjrml gnnzj fsxj zbhp rqxfdd ndnlm fsr nrgn hhxch gnq sgqrvd sm qjktms jjmmn xcljh qzln jqlp nxcrg bsgnsc jxftql lxgxp kgfld jmt ntbqk kvqq fnkdvt gppfld flg kscd jjdgtt nvnx vhbjp nhlxntg zkhpc bgjcg tpdc jkgf tnvtm rnln mgbv nrdtprm cntfq brhmkh rnsqjkq mv dvjrrkv crjddsgj mxm nqbjlf pkrdz xvzlpx dmjzc brjcp hcrsbr nkcl skrxt zfqhnt rglsgs pfhfb nsnzxsc ncrn fzckq rzhktt dcvtrq zgcf qgl (contains soy, wheat, sesame)
sgqrvd dvjrrkv qszr brhmkh znzx tkvddn mgbv kgpbh gtdb gdmv zjkt zdqd mhqxk cntfq hrtd sgdlhb lxgxp zbhp bgjs hxgdp rfcl lvft qgl ndvnj glj ptcnh xjqkbq zkhpc bgc rnln xntpsg xvzlpx zfqhnt xxbnf ntbqk tgkxxjm ncksb flg nrgn kqxz hkdls gqkf fjqv qpp krhmfb fdjrml tmlm tpdc rpqss qzln ckzg xcljh jdcbc kgfld ndnlm kvhbj svzfl jfm nrlbfc tkxxdnh fsr qjn lqbcg sdclrlb nxcrg gnq vchxzh rzhktt tvgcv (contains shellfish)
pfhfb rpqss bzlnnv vchxzh ctkjrt hjn ckzg hpsrqbl nzxs zcxthb jmt lqbcg ndvnj qbvxrbs dvjrrkv jvgbct zjkt ndnlm nrgn mxm xcljh rzhktt fnkdvt hcc knfx tgkxxjm hqhnh bhghks kgfld tkqp qgl tkvddn gzhlbn rglsgs jjdgtt kvqq gfq zmnflgt fsr qjktms ssk jdcbc kshg dgdn jfm gzthtlg mkmcq tpdc nxcrg mgbv xjqkbq qkbm qpp rnln zbhp chjqncr sm jxftql xjksh tnvtm gbmv tgxvz zczht tkxxdnh kssncfd ptcnh bdfmncs mvtkk rfcl zkhpc qjn xxbnf gdmv fzl lxgxp mhqxk (contains soy, dairy)
xjqkbq xvzlpx nqbjlf qbvxrbs gtsslgk bqjqf sdclrlb ccn qpp nsnzxsc zmnflgt pkrdz ndnlm bsgnsc zgcf zbhp tgkgj jfm lvft nrgn xcljh shc bpvmb ltjt jjdgtt dvjrrkv ckzg mgbv sm hxgdp fsxf nhlxntg kqxz kvqq gzthtlg pfhfb htxvfq nvnx jxftql lgjsd sgqrvd skrxt cntfq glj bgjs mxm bbxsn rpgrk tmlm fsr rqxfdd bgjcg qkbm fdqp hpsrqbl gppfld vchxzh svjp qjktms rnsqjkq nxcrg mv tgxvz krhmfb nxcsxc zcxthb hcrsbr qjn tnvtm qrdpc lvtj qfgbx fjqv rpqss nkgzzg (contains fish, wheat, sesame)
jdcbc prgj rnln zdqd zbhp cntfq mgbv gfq dgdn sm gdmv hkdls hnvhqczc ltjt ckzg skkt tkvddn lsll ndnlm flg nxcrg kgpbh zjlz dvjrrkv zgcf mhqxk gnq qgl ccn hcc hvrrhc bgc rpqss gqkf hqhnh nxbn bsgnsc lqgn gzthtlg xcljh jxftql nrdtprm bdfmncs bhghks kgfld zczht hrtd lqbcg rqxfdd bbtn dmjzc fsr mkmcq zkhpc (contains sesame)
nqbjlf dcvtrq cntfq sdclrlb kvhbj skkt jvgbct xjqkbq knfx lsll zdmhtpg hnh fnkdvt gtdb tgxvz xjksh gzthtlg bhghks qpp zgcf ptcnh mvtkk pfhfb jjmmn ktsnt kpzbxfp tgkgj glj rfcl fsr fsxf lqgn gppfld ssk mlcvjc mhqxk kqxz kshg jjdgtt tvgcv xcljh qszr prgj gfzjc jmt qrdpc hhxch bgc mgbv zbhp kssncfd nhlxntg hkdls bgjs gfq nxcrg hcc fdqp lpm jrspd bsdc nrgn dscm bzlnnv bpvmb qjn nkgzzg rglsgs fjqv xvzlpx xxbnf qjktms xcsxh lqbcg bdfmncs qbvxrbs nkcl skrxt hxgdp ndnlm vhbjp nxcsxc flg nxbn kgpbh (contains soy, wheat, peanuts)
zjlz jdcbc nkcl rpqss gqkf lsll flg zbhp ltjt jmt fzckq rnln mknsj ccn qkbm chjqncr lfgh bsdc bzlnnv bbtn fsr skrxt kvhbj hpsrqbl kgdvd lpm dvjrrkv ptcnh tnvtm sgdlhb rfcl gtdb tvgcv rpgrk mkmcq hvrrhc qjktms bsgnsc zsggkm pvnr shc zcxthb lhcm bqjqf fzl rnsqjkq lqgn brhmkh jkgf mv xntpsg mgbv fdjrml dgdn mhqxk ktsnt xcljh qfgbx tkvddn xjksh lqbcg pkrdz brjcp bbxsn (contains fish, peanuts)
xjcvt kgfld gbmv fsxj bqjqf qgl rnln hcrsbr nxbn zcxthb zfqhnt skrxt tgkxxjm dscm hkdls dvjrrkv lvtj gdljd zmnflgt pkrdz xcljh bsgnsc zjkt zkhpc xxbnf tpdc znzx tgkgj qszr bbxsn qfgbx rzhktt rfcl xcsxh ctkjrt bgjs mhqxk mgbv qrdpc ktsnt jjmmn fmcnhq tkxxdnh jrspd qkbm qpp qbvxrbs kshg prgjph skkt mvtkk ncksb hpsrqbl kphbtmkx dgdn ncrn fnkdvt dcvtrq mv nrdtprm kvqq zdqd gzhlbn drj vchxzh fsr nrlbfc zsggkm tlv bgc sgqrvd lctltv mlcvjc lsll hnnmrxh lfgh bgjcg ntbqk htxvfq rnsqjkq hrtd bhghks gtsslgk dftg lqbcg jqlp zbhp qjn bdfmncs (contains peanuts, sesame)
zkhpc lpm fdqp kpzbxfp hkdls mlcvjc bgjs qckqc ndnlm skrxt zdmhtpg dgdn nkgzzg qjn tvgcv brjcp bsdc kshg kgdvd xcljh crjddsgj jvgbct glj xjksh xvzlpx shc mxm gzhlbn ctkjrt ckzg fsr rnsqjkq mgbv rpgrk zdqd rnln gdljd dcvtrq fjqv fmcnhq svzfl fdjrml hrtd dmjzc nxcsxc sgdlhb mhqxk jdcbc qzln dscm zbhp bbxsn fnkdvt kgpbh zjkt tgkxxjm lhcm ptcnh skkt jqlp mv nrdtprm gtdb htxvfq cntfq tnvtm lqbcg (contains soy, nuts)
ntbqk ccn pkrdz krhmfb hkdls kgpbh bhghks bqjqf hpsrqbl bpvmb fzckq nhlxntg pfhfb xcljh bzlnnv nkgzzg cntfq zbhp jqlp ndnlm tlv qbvxrbs nrdtprm gdmv ssk mgbv gdljd dvjrrkv bsgnsc tpdc rnsqjkq znzx flg fsr zlfm zjkt nvnx glj knfx lqbcg hjn (contains wheat, sesame)
qjn sgdlhb rnsqjkq gdljd dvjrrkv nkcl jxftql kssncfd jvgbct kgfld bgc nxcsxc ndnlm nrdtprm kpzbxfp fsxf gnq vhbjp nvnx hvrrhc tgxvz nsnzxsc tvgcv xvzlpx prgjph kqxz fsr hnnmrxh lqbcg hkdls glj ctkjrt zdmhtpg qszr nhlxntg gqkf tlv hxgdp nrgn ndvnj qckqc xntpsg ltjt rnln zbhp gdmv xxbnf hhxch fnkdvt knfx xcljh kgdvd bdfmncs gfq lpm mkmcq skrxt hnvhqczc krhmfb dftg gtsslgk gzthtlg flg zgcf zkhpc brhmkh pvpfn ssk dgdn bsdc jdcbc (contains fish, sesame, dairy)
bpvmb jvgbct nrgn zbhp dvjrrkv bqjqf mkmcq xcljh fsxf mknsj kssncfd lqbcg skrxt tvgcv xbdhth tkvddn nrdtprm mhqxk chjqncr ndnlm lctltv hnnmrxh rpgrk ccn rnln jdcbc gdljd dmjzc svjp lsll bdfmncs rnsqjkq qgl prgjph hqhnh xjqkbq jjmmn hcrsbr xcsxh drj cntfq fsr bsgnsc rfcl pvnr flg tgkxxjm zczht shc (contains soy, shellfish, sesame)
mlcvjc prgj xntpsg pfhfb gtsslgk nrgn kvqq lhcm fmcnhq qgl nrdtprm hcrsbr tgkxxjm lctltv fnkdvt hjn tvgcv prgjph zjlz rpqss bzlnnv zbhp dftg mkmcq tnvtm rqxfdd mknsj fsr xjqkbq pkrdz dscm gdljd nxcrg sm svjp ndnlm zlfm bgjcg rglsgs lvft mhqxk kpzbxfp lpm rnsqjkq ccn skrxt gqkf mxm gzthtlg dmjzc flg tkqp bgjs qpp bsgnsc cntfq skkt gtdb lqbcg xcljh gnnzj hqhnh jjdgtt gfzjc zgcf brhmkh sgqrvd dvjrrkv (contains shellfish, sesame)
dvjrrkv ccn lqbcg lctltv jvgbct tkqp hxgdp lhcm zsggkm bgc qjktms zjkt nvnx nxcsxc kqxz skrxt bhghks gzthtlg chjqncr htxvfq mv rnsqjkq sgdlhb crjddsgj rglsgs nrgn ndvnj ltjt hhxch xcljh hrtd fmcnhq nkgzzg dscm ncrn zbhp mgbv prgj pfhfb tgkgj hpsrqbl kscd lxgxp bbxsn gdmv tgkxxjm glj nzxs tpdc fsr tmlm lgjsd bsgnsc qjn rqxfdd hqhnh cntfq (contains fish)
hpsrqbl brjcp qpp shc tgkxxjm bbtn xcljh gbmv znzx jkgf zcxthb jjmmn zczht bgc lvtj drj rzhktt tkxxdnh tlv dcvtrq nsnzxsc hkdls tvgcv dvjrrkv qkbm knfx zjkt mhqxk bpvmb ckzg bgjs gfzjc bhghks gtdb nzxs gnnzj sm jjdgtt zjlz rnln xjqkbq ctkjrt xvzlpx xntpsg htxvfq tmlm zdqd lqbcg fsr ndnlm rfcl kgdvd skrxt mgbv hhxch mknsj hxgdp fjqv ssk qszr hqhnh xcsxh chjqncr dmjzc crjddsgj prgjph dscm sgdlhb hjn cntfq bsgnsc qjn nvnx sdclrlb jqlp ncksb (contains sesame)
fnkdvt nxcrg sgdlhb kshg glj jvgbct tlv lgjsd qbvxrbs tgkxxjm xcsxh jfm fdjrml mgbv kvqq xbdhth fsr rpgrk qkbm hjn rfcl dftg tkxxdnh mhqxk nsnzxsc zgcf dvjrrkv fzckq prgjph lqbcg skrxt bgc hpsrqbl lsll tmlm bgjcg gtdb nvnx qszr lxgxp zbhp hcc tgxvz xjqkbq nxbn fdqp zdqd xxbnf fsxf ltjt ptcnh xcljh tkqp tkvddn nrlbfc jqlp jrspd (contains fish, peanuts)
nzxs ckzg nrlbfc nsnzxsc xbdhth pvpfn tvgcv tmlm mvtkk ncksb mhqxk ltjt zbhp fjqv rfcl tkqp lpm gzthtlg hkdls hcrsbr qckqc bhghks qgl kvhbj nkcl jmt lhcm bgjcg flg nqbjlf kvqq kqxz xcljh nrgn pvnr bzlnnv lqgn gnnzj bdfmncs ccn lvtj xjcvt dvjrrkv jjmmn qrdpc ntbqk sgqrvd kscd hcc cntfq gnq tgkgj jxftql jrspd fzl fsr lqbcg qkbm mgbv brjcp bgjs gtdb drj qjktms bqjqf hxgdp skkt prgj kssncfd xntpsg hhxch fsxf hqhnh qpp nxcsxc jvgbct qjn lfgh ndnlm mknsj zjkt mlcvjc lgjsd (contains shellfish)
qgl rnsqjkq hnnmrxh lsll nkcl fsr qjktms ndnlm krhmfb rpgrk xcljh jfm lfgh xntpsg skkt gdmv dvjrrkv zbhp kphbtmkx lhcm vhbjp mgbv zsggkm fsxf ccn nrgn nrdtprm bpvmb znzx bbtn dgdn bhghks zjkt svzfl jjmmn tlv bsgnsc bgc qkbm skrxt bgjcg fdqp ltjt rfcl bgjs rnln gtsslgk zjlz (contains wheat)
nhlxntg hqhnh qfgbx kssncfd zkhpc bdfmncs zcxthb drj sgqrvd lqgn rqxfdd hvrrhc prgj tgkgj nrdtprm skrxt jxftql fsr xcljh qpp shc zbhp qjktms zsggkm ccn chjqncr znzx pkrdz prgjph ntbqk ndnlm nrgn kgdvd tkxxdnh tpdc dvjrrkv qzln knfx nkgzzg rnsqjkq kpzbxfp bbtn tkqp mgbv rzhktt lhcm rglsgs fdqp fmcnhq gzthtlg nvnx ssk bhghks kvhbj hhxch tlv fnkdvt htxvfq zfqhnt xvzlpx lpm qszr hnnmrxh hcrsbr jqlp nsnzxsc (contains dairy, peanuts, wheat)
gfzjc hhxch rzhktt gtdb ssk zbhp zfqhnt jkgf tkqp dvjrrkv kgpbh mknsj bsdc lgjsd mgbv zcxthb hrtd nqbjlf mlcvjc hxgdp tgxvz gqkf fmcnhq tpdc lxgxp hcrsbr znzx zlfm fjqv kvqq nhlxntg zjlz brjcp zkhpc skrxt nrlbfc jdcbc qfgbx svzfl fzckq kgfld prgj gzhlbn lhcm qkbm fsxj hqhnh kscd vhbjp fsr lsll qbvxrbs gfq tnvtm lqbcg nkcl ndnlm sgqrvd xjqkbq (contains wheat, shellfish, fish)
gdmv bbxsn kvqq hnvhqczc lqbcg xjqkbq jvgbct mlcvjc gfq jrspd lxgxp jkgf tkvddn bsgnsc lqgn xcljh fsxf qjktms dscm mgbv fsr ndvnj nrdtprm jjmmn xvzlpx nkgzzg rnln nxcsxc zjkt sdclrlb nhlxntg kphbtmkx gnq zbhp fzckq zlfm hvrrhc zsggkm xcsxh ntbqk skkt jdcbc bgc bsdc prgj shc nzxs bpvmb hcc ncrn xjcvt nrlbfc jqlp ktsnt nvnx gnnzj tkqp nxbn ndnlm sgdlhb bqjqf kqxz qzln zjlz tkxxdnh bdfmncs kpzbxfp hrtd fzl skrxt sgqrvd zdmhtpg dftg fnkdvt lgjsd mv (contains nuts, fish)
nxcrg jqlp xcljh nkcl qjn rpgrk xbdhth vhbjp kqxz zfqhnt nrdtprm ltjt tkxxdnh rqxfdd fdqp bsdc gzhlbn bpvmb ndnlm bbtn skrxt jdcbc fmcnhq pkrdz zsggkm rzhktt ccn gbmv ncrn rglsgs dmjzc sgdlhb prgjph lpm zcxthb dftg qjktms pvnr hnnmrxh kssncfd bdfmncs bhghks lhcm lgjsd ssk bgc fsr gfzjc rnsqjkq zbhp lqbcg krhmfb mkmcq zlfm brhmkh xntpsg hnh bsgnsc dvjrrkv tvgcv sm fdjrml prgj hhxch tpdc fsxf nkgzzg nzxs gnq tmlm (contains dairy)
nrlbfc nxcsxc jvgbct dvjrrkv prgjph gqkf ndnlm lhcm mvtkk xcsxh gtsslgk mgbv kgpbh zbhp qbvxrbs kshg gfq ktsnt bbxsn hjn jfm jxftql jmt xbdhth xcljh zmnflgt kgfld nrgn fnkdvt fdqp skrxt svzfl bgjcg sgqrvd ssk svjp sgdlhb vchxzh kgdvd dgdn xntpsg tpdc zjlz zgcf rnsqjkq zlfm chjqncr tmlm dftg tgxvz jkgf lpm hcc qjn tkxxdnh lqbcg kscd lctltv pvnr ntbqk lsll qszr mv hvrrhc fjqv (contains wheat)
vhbjp fsxj jxftql tkxxdnh nzxs fnkdvt fmcnhq lgjsd chjqncr xcljh brjcp hrtd kssncfd ssk mgbv xvzlpx bgjs rpgrk kgfld gbmv ndvnj ccn rnsqjkq xjksh ncrn brhmkh lxgxp qzln zdmhtpg tkvddn lsll nrgn pvpfn lqgn nxbn lvtj dvjrrkv dscm bsdc hqhnh mxm fsr nrdtprm skrxt nhlxntg tpdc mkmcq bqjqf lhcm hxgdp jkgf hkdls fsxf jmt fzl kshg xjcvt lqbcg jdcbc flg rnln ktsnt zbhp gqkf kphbtmkx rglsgs (contains wheat, sesame, dairy)
fmcnhq prgjph jdcbc gtsslgk xcljh fsr zdqd hnh bzlnnv krhmfb mknsj nrdtprm kgpbh lpm tnvtm zbhp fzckq xcsxh lvft hqhnh hcrsbr jfm bsgnsc qfgbx mgbv lsll qjn hrtd tkvddn sdclrlb dscm lxgxp jjdgtt kqxz zjlz tlv xjksh fdqp ptcnh rglsgs dvjrrkv flg ntbqk bsdc xjqkbq gdljd jmt zjkt gdmv fjqv nxcrg zczht bbxsn nkgzzg zmnflgt skrxt ndnlm brhmkh glj zfqhnt tkxxdnh gqkf (contains peanuts, shellfish)
svzfl bdfmncs mlcvjc xjksh fsr shc ssk mknsj tkqp znzx hqhnh zdqd jjmmn svjp ndnlm lctltv tkvddn bzlnnv jrspd kssncfd zjlz pvpfn fdjrml tgkgj nrgn nvnx bqjqf hpsrqbl hnh rnln zjkt fdqp zlfm xjcvt gbmv tkxxdnh kgdvd mgbv dftg jdcbc fnkdvt tvgcv pkrdz zkhpc lqbcg jmt kvhbj nxcrg nsnzxsc gzhlbn zbhp gdljd skrxt skkt mv qjktms dvjrrkv (contains shellfish)
zjlz gzthtlg vchxzh zfqhnt dftg bdfmncs ndnlm dvjrrkv vhbjp shc znzx fdqp fsr svjp nrdtprm tgkxxjm zbhp nxcsxc ndvnj jjdgtt qjktms mhqxk skrxt rglsgs pvpfn xvzlpx jfm prgjph mlcvjc fmcnhq gppfld tvgcv qszr pvnr bsdc bqjqf jxftql hpsrqbl qjn zkhpc qzln crjddsgj lsll bgjcg fdjrml tgxvz ssk lpm brhmkh zczht zcxthb jrspd ltjt lxgxp lqbcg xcljh dgdn gdljd rfcl rqxfdd tpdc (contains nuts, sesame, dairy)
qjn nrgn pvpfn bsgnsc xxbnf jvgbct pfhfb lqbcg zsggkm xbdhth lvtj xcljh tlv lsll lqgn nrlbfc qckqc hrtd shc sgdlhb zcxthb ssk bdfmncs hkdls tnvtm nxbn jfm hnnmrxh dvjrrkv skrxt jdcbc ndvnj jjdgtt jjmmn gtdb hjn tmlm gdljd ndnlm nhlxntg hnh kpzbxfp bgjs fsr jqlp qjktms zczht rnsqjkq zbhp vhbjp brjcp (contains wheat)
hqhnh fsr zbhp nrgn zlfm ndvnj nkgzzg kgdvd ssk qckqc sdclrlb ptcnh bpvmb brhmkh dvjrrkv rpqss fnkdvt lfgh gdljd tvgcv nxcsxc dmjzc fmcnhq qzln sgdlhb qjn zmnflgt vchxzh tkvddn xcljh dgdn bgjs hhxch pfhfb lqbcg kscd lhcm nrlbfc pkrdz htxvfq skrxt znzx ntbqk hkdls ktsnt bzlnnv rnsqjkq ndnlm sgqrvd tlv hcc zjlz gzthtlg jkgf svzfl tkxxdnh pvpfn nxbn ccn gzhlbn rqxfdd qfgbx rnln bqjqf qrdpc kgfld hnvhqczc gnq knfx tmlm nvnx zdqd zsggkm hjn jqlp gqkf bgjcg fdjrml (contains shellfish, dairy, sesame)
dmjzc qgl jjmmn mgbv qjktms qszr zlfm kgfld qkbm xjksh hnvhqczc xjcvt fsxj hjn fjqv rglsgs zbhp ccn kshg bsdc pvnr bgjcg nvnx hnnmrxh cntfq rpgrk gqkf shc nxbn qrdpc jrspd ktsnt brjcp dvjrrkv tgkxxjm jkgf kgpbh kgdvd zfqhnt lfgh ncksb nrdtprm vchxzh fsxf zdqd kphbtmkx skrxt flg gtsslgk zgcf tvgcv dftg lpm nxcrg dgdn xcljh qfgbx nzxs gbmv sgdlhb gdmv jdcbc fsr zjlz ctkjrt xntpsg hcc tkqp ptcnh gdljd rfcl znzx hpsrqbl xjqkbq jfm lqbcg nqbjlf mlcvjc tgkgj xbdhth zkhpc kscd nkgzzg svzfl sm jvgbct htxvfq rnsqjkq hnh mkmcq (contains wheat, sesame)
rnsqjkq zsggkm jqlp zdmhtpg bpvmb svjp pkrdz fsxf tkxxdnh zczht dcvtrq ndnlm cntfq jfm nkgzzg rqxfdd nrlbfc bzlnnv mkmcq fjqv tpdc hnh gtdb nxbn bbxsn mgbv pvpfn ncrn qfgbx sgqrvd knfx xjcvt brhmkh tvgcv gqkf prgjph qgl nvnx hqhnh dvjrrkv lfgh mknsj qzln jxftql kscd gtsslgk kpzbxfp hjn xcsxh gnq dmjzc xjksh tgkxxjm gzthtlg rzhktt zjlz kphbtmkx fsr fdqp sm bbtn lqbcg crjddsgj shc zbhp rglsgs nkcl hxgdp rfcl kgfld qrdpc skrxt gdljd znzx drj mlcvjc (contains shellfish, nuts, dairy)
svzfl fsxj jjmmn chjqncr lqbcg mxm zkhpc rqxfdd gnq kshg zczht gdljd ndvnj fzl rfcl dftg qbvxrbs qfgbx ndnlm mlcvjc mgbv bgjcg bpvmb vhbjp htxvfq lpm nrdtprm hnvhqczc gppfld brjcp jkgf rnsqjkq fzckq rglsgs dmjzc skrxt nsnzxsc kssncfd xcljh zbhp tgkgj kphbtmkx dgdn fsr knfx zdqd jqlp zfqhnt svjp (contains dairy)
nrlbfc bgc hhxch lsll qfgbx bsdc hqhnh tnvtm gnnzj gtdb dmjzc fsr lqbcg hrtd kvqq lgjsd jjmmn xjksh ncksb jvgbct vchxzh ndnlm htxvfq zkhpc fsxj ctkjrt lxgxp gdljd mgbv sdclrlb hnh kscd gzhlbn zdqd flg ncrn ckzg vhbjp mv jfm ptcnh gbmv sm kphbtmkx hcrsbr rpqss skrxt kgpbh kssncfd lvft bgjcg zczht bgjs nrdtprm xcljh bpvmb qckqc nzxs kqxz gdmv bzlnnv ndvnj jxftql hkdls jkgf xjqkbq hnvhqczc lfgh prgj mlcvjc pfhfb zbhp dgdn qrdpc nvnx prgjph bdfmncs nxcsxc tmlm jqlp tkqp sgdlhb fnkdvt qjn fzckq bsgnsc qbvxrbs (contains shellfish, peanuts, dairy)
bzlnnv zcxthb ndnlm jrspd lctltv mvtkk zjkt hqhnh fjqv gppfld zbhp sgdlhb knfx qfgbx hkdls jqlp pkrdz jxftql kvqq zkhpc gbmv fdjrml sgqrvd fmcnhq dcvtrq hnnmrxh tpdc kscd skrxt bsdc qzln xcljh lqbcg pvnr rpqss qckqc shc rnsqjkq dvjrrkv qrdpc znzx mgbv ssk gtsslgk bgjcg kqxz pvpfn hnvhqczc ptcnh bpvmb bbxsn hrtd hvrrhc gnq bgjs nxbn nxcsxc tkvddn qgl ndvnj (contains shellfish, nuts, wheat)
tgkgj kgpbh brhmkh bbxsn rnln mgbv bpvmb pvpfn rqxfdd hrtd kpzbxfp gtdb bbtn dgdn gfzjc kshg ltjt flg nrgn qrdpc chjqncr jrspd nrdtprm crjddsgj bdfmncs bhghks ncksb hkdls zlfm dvjrrkv gtsslgk sgqrvd sgdlhb xntpsg zbhp dcvtrq lxgxp gfq kphbtmkx lqbcg bqjqf qjn zkhpc xbdhth qzln bgjcg jkgf ncrn nxbn znzx nxcsxc brjcp nqbjlf zdmhtpg tgxvz fsr nrlbfc prgjph gppfld qkbm xcljh rzhktt ndvnj ndnlm fjqv hvrrhc (contains peanuts, dairy, soy)
tpdc nkcl nqbjlf ncksb crjddsgj prgj htxvfq gtdb bzlnnv nvnx hkdls fzl dvjrrkv sdclrlb tkqp xcsxh bqjqf hrtd dscm pfhfb svjp rqxfdd hvrrhc nrdtprm mgbv xjqkbq zkhpc zczht rfcl fsr rnsqjkq zbhp nhlxntg ndnlm jqlp bsdc hjn ntbqk gtsslgk brjcp rzhktt tlv tgkxxjm knfx ssk xjksh nxcrg dmjzc kgpbh nrgn lvtj svzfl shc mlcvjc lgjsd gbmv kvqq mhqxk nxcsxc gzhlbn tmlm zcxthb zfqhnt qpp xcljh lctltv hcc kscd fjqv mxm qrdpc zdmhtpg kvhbj skrxt qszr ptcnh xvzlpx zgcf dcvtrq bbtn zlfm jjdgtt jxftql fdqp xntpsg (contains fish, shellfish, sesame)
fsr dvjrrkv ckzg zjlz cntfq hcc nqbjlf svzfl ssk vchxzh nkcl zbhp mgbv hcrsbr fsxj xcsxh ccn rpgrk bhghks qckqc ptcnh gdljd hxgdp qkbm mvtkk rnsqjkq rnln prgjph gppfld dftg mlcvjc gtsslgk bgjcg bgc jdcbc zczht lctltv gfzjc svjp xvzlpx sdclrlb skrxt qfgbx nxcrg dcvtrq shc sgqrvd tgkgj kphbtmkx fzckq bqjqf crjddsgj nhlxntg jqlp gzthtlg zgcf ctkjrt zmnflgt bbtn drj ndnlm rpqss lvft xcljh (contains shellfish)
pkrdz ndvnj znzx xjksh zbhp hrtd kscd kgdvd ctkjrt zsggkm fzl zjkt zdmhtpg xcsxh tkqp lqbcg kssncfd bbxsn bzlnnv mgbv kgpbh krhmfb nsnzxsc ssk prgjph fmcnhq lfgh bgjcg fsr bbtn brjcp kqxz nxcrg skrxt rfcl kvqq brhmkh qbvxrbs hpsrqbl lgjsd kphbtmkx nzxs ndnlm bsgnsc mv xvzlpx ncksb nrgn rpqss tmlm nkcl dvjrrkv tnvtm lpm xbdhth sgqrvd lxgxp ktsnt mkmcq nhlxntg (contains fish, shellfish, nuts)

43
2020/d22/ex1/ex1.py Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python
import itertools
import sys
from collections import deque
from typing import Deque, List, Tuple
Deck = Deque[int]
def parse_decks(raw: List[str]) -> Tuple[Deck, Deck]:
deck_1 = deque(int(n) for n in itertools.takewhile(len, raw[1:]))
deck_2 = deque(
int(n) for n in itertools.islice(itertools.dropwhile(len, raw[1:]), 2, None)
)
return deck_1, deck_2
def play(deck_1: Deck, deck_2: Deck) -> Tuple[int, Deck]:
while len(deck_1) and len(deck_2):
left, right = deck_1.popleft(), deck_2.popleft()
if left > right:
deck_1.extend((left, right))
else:
deck_2.extend((right, left))
return (1, deck_1) if len(deck_1) else (2, deck_2)
def solve(raw: List[str]) -> int:
__, deck = play(*parse_decks(raw))
score = sum((i) * val for i, val in enumerate(reversed(deck), 1))
return score
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

53
2020/d22/ex1/input Normal file
View file

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

57
2020/d22/ex2/ex2.py Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env python
import itertools
import sys
from collections import deque
from typing import Deque, List, Set, Tuple
Deck = Deque[int]
def parse_decks(raw: List[str]) -> Tuple[Deck, Deck]:
deck_1 = deque(int(n) for n in itertools.takewhile(len, raw[1:]))
deck_2 = deque(
int(n) for n in itertools.islice(itertools.dropwhile(len, raw[1:]), 2, None)
)
return deck_1, deck_2
def play(deck_1: Deck, deck_2: Deck) -> Tuple[int, Deck]:
prev: Set[Tuple[Tuple[int, ...], Tuple[int, ...]]] = set()
while len(deck_1) and len(deck_2):
state = (tuple(deck_1), tuple(deck_2))
if state in prev:
return 1, deck_1
prev |= {state}
left, right = deck_1.popleft(), deck_2.popleft()
if left <= len(deck_1) and right <= len(deck_2):
winner, __ = play(deque(list(deck_1)[:left]), deque(list(deck_2)[:right]))
if winner == 1:
deck_1.extend((left, right))
else:
deck_2.extend((right, left))
elif left > right:
deck_1.extend((left, right))
else:
deck_2.extend((right, left))
return (1, deck_1) if len(deck_1) else (2, deck_2)
def solve(raw: List[str]) -> int:
__, deck = play(*parse_decks(raw))
score = sum((i) * val for i, val in enumerate(reversed(deck), 1))
return score
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

53
2020/d22/ex2/input Normal file
View file

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

58
2020/d23/ex1/ex1.py Executable file
View file

@ -0,0 +1,58 @@
#!/usr/bin/env python
import itertools
import sys
from typing import List, Tuple
def solve(circle: List[int]) -> int:
def to_links(circle: List[int]) -> List[int]:
links = [-1 for __ in range(len(circle) + 1)]
cyclic = itertools.cycle(circle)
next(cyclic) # Advance it by one
for prev, cur in zip(circle, cyclic):
links[prev] = cur
return links
def step(links: List[int], current: int) -> int:
cup0 = links[current]
cup1 = links[cup0]
cup2 = links[cup1]
links[current] = links[cup2] # Remove 3-tuple from the linked-list
# Find destination
dest = (current - 1) if current > 1 else (len(links) - 1)
while dest in (cup0, cup1, cup2):
dest = (dest - 1) if dest > 1 else (len(links) - 1)
# Update our links
links[cup2], links[dest] = links[dest], cup0
return links[current] # What's the next value in the cycle ?
def to_answer(links: List[int]) -> int:
next = links[1]
res = 0
while next != 1:
res = res * 10 + next
next = links[next]
return res
current = circle[0]
links = to_links(circle)
for __ in range(100):
current = step(links, current)
return to_answer(links)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
assert len(input) == 1
print(solve([int(c) for c in input[0]]))
if __name__ == "__main__":
main()

1
2020/d23/ex1/input Normal file
View file

@ -0,0 +1 @@
598162734

55
2020/d23/ex2/ex2.py Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env python
import itertools
import sys
from typing import List, Tuple
def solve(circle: List[int]) -> int:
def to_links(circle: List[int]) -> List[int]:
links = [-1 for __ in range(len(circle) + 1)]
cyclic = itertools.cycle(circle)
next(cyclic) # Advance it by one
for prev, cur in zip(circle, cyclic):
links[prev] = cur
return links
def step(links: List[int], current: int) -> int:
cup0 = links[current]
cup1 = links[cup0]
cup2 = links[cup1]
links[current] = links[cup2] # Remove 3-tuple from the linked-list
# Find destination
dest = (current - 1) if current > 1 else (len(links) - 1)
while dest in (cup0, cup1, cup2):
dest = (dest - 1) if dest > 1 else (len(links) - 1)
# Update our links
links[cup2], links[dest] = links[dest], cup0
return links[current] # What's the next value in the cycle ?
def to_answer(links: List[int]) -> int:
next = links[1]
return next * links[next]
current = circle[0]
circle += [i + 1 for i in range(max(circle), 1000000)]
links = to_links(circle)
for __ in range(10000000):
current = step(links, current)
return to_answer(links)
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
assert len(input) == 1
print(solve([int(c) for c in input[0]]))
if __name__ == "__main__":
main()

1
2020/d23/ex2/input Normal file
View file

@ -0,0 +1 @@
598162734

49
2020/d24/ex1/ex1.py Executable file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env python
import sys
from collections import defaultdict
from typing import Dict, List, Tuple
Offset = Tuple[int, int]
DELTAS = {
"nw": (0, -1),
"ne": (1, -1),
"e": (1, 0),
"se": (0, 1),
"sw": (-1, 1),
"w": (-1, 0),
}
def to_offset(path: str) -> Offset:
offset = 0, 0
i = 0
while i < len(path):
direction = path[i]
i += 1
if direction in ["s", "n"]:
direction += path[i]
i += 1
x, y = offset
dx, dy = DELTAS[direction]
offset = x + dx, y + dy
return offset
def solve(raw: List[str]) -> int:
blacks: Dict[Offset, bool] = defaultdict(bool)
for offset in map(to_offset, raw):
blacks[offset] = not blacks[offset]
return sum(blacks.values())
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

471
2020/d24/ex1/input Normal file
View file

@ -0,0 +1,471 @@
swswswswneswswwwswnewswswweswnwsww
nwwewenenwnenwnwnwnwneswnwswnwnwswswnw
seneswwwswwnenwnenwswswswswsewseeww
esenesenesesesewseseswnesesweesesesese
seseseeseenesewseenwsesewswwsesenwse
eswenewnenenewneneneneenenenenwnene
nwseeseseeseseseseewseesenwseeesese
nwnwswswswweneseswwswwneswswswswswsw
senenenwnenewneneneseswneeeenenenew
eswnwnesenwnwnenwnwnwnwwnwsenwwswswenw
wswneswswseesewswseswswswnenesenenwswswne
seswseswneswswswwnwswwswseneswswswswsee
neseseswnwesesesesewswsesenesenesesesw
wwswwwsweswwwww
seswwnwneenwswneenwewneneneseenee
eswseenweswewseneeeeseeswnwnwse
swsweswswswnweswswneswwswnwswwwswswswsw
nwwnwnwnwnwnwnwnwwswwnweneswwenwnw
sewswwwwwwwweswwwwneswwnwswnw
nwneeneeneneseneseneneneneneneswnenwnene
swnenenweeneeeseswweneenenenenene
nwnwnwsenwewsesenwenwwwswwnwnesenw
swnwswswswswswsewseswnewneseswswswneesw
wwweswwswwsewswswwwwnwwesewwne
swswsweneswswswenwswnewnwswwneswseswswe
nwnesewwnwwnwwwsew
enwwwnenwnewwwwswwseeswewe
neswseswswsenwseswnwseswse
senwseneneneneneeseneswnenenenenwnenwnw
swseneswwseenwsenwneneswnewnenewene
ewwwwwwwewwwnwswwwwwwwne
eswswenwsenwnwsenenw
nwneseewseswwsewswnwnwnwwwwnewww
nwwwwwwwwewnwwswnew
neeeseeesewseeeeeeeewe
wweswnenwwnewnwnwwwewsewnwwsew
swwswwwswwewwswswnwsweswnwwwww
eseswneenwneenweseenweeseeeenw
neneswneneneneneneneneneswnenwnwnw
nwnwwnwewwswwnwwwnwsewnwwenwnw
seswswswnwswwwwswwswneswwseswnw
nwseswenwwneneneseswneenwnenenwnenwnenw
nwnenenenesewwnenwnwnesenwnwnwnwnenwnwnw
wseeeneseeeseseesesenwseseswsesese
sweseswnwseseseswseswseseseswswswse
ewwwswswsenwewnewwwenwwwnwww
nwwsewnwnwnwneswwnwesewnwwnwnwnwnwne
nenwnwnwnenenwnenwnwswswnwneenenwnwnwne
esenwneswsesesweeeeweseseeseseswnw
swswswswwsesweseswswswsw
swsweneswwseswswswwswsenewswwswseswnene
nenenewnwnenenwenwnesenwneseswnwnwnwne
nenenenewneeseneneswneneneswsenenenwne
nenenwnenwswwnweesenwsenwnwnwseswnwnwnw
seseeenwsenwswsesenwseeseeseeseswese
swneeseseneswswnwswnwwwwswswnee
seeseseseneseseswsewseenenwwneseswse
wswseseenwwswnewenwswswwwnewwsw
nenewswnwnenwnwneeneswseeneswnenwnenesene
nwswsenweweseeneseesesesesesesesee
seneswswwesenenwswseswnwseseseseseswne
wwnwwweswnwnwwweneseewnwsesenw
swswneneneneenewnesenewweenweswne
eseneseneseenenewwswseweenweenenene
nwwnwwnwsenwnwnwnwwnwwnww
swweswsewewwwwwwwwwwnewne
swswnewseseseesenewseesesesesesenwese
swswnenwnenwnwnwnwnenenenwnwwnenwseene
wnwwwwnwnwwnwwnwnwwwnwnwsenwe
nwseswwwnenwwwwesewwwwwwwnenwnw
nwswswnwswwswwnenenwnwnwnwnewnenw
seswswswnwswswswswswswswswswswswsw
neneseeneswnwnenwnwsenwnenenewne
wwwwwnenwnwnweswwnwsewwwesese
swwswswwwwseswswenwnewswwswweswnw
swwswseswswseeswswswewswswnwswswese
nwnwewsenenwnesewwwwswnwnenwswsee
seseseenwwswseneneseswswnwnewswnwsenwse
wwswwnwwwwsewwwenewnwswnwwwe
swwwwswwswwswneseswswswwnewswwse
nenenwneeswnenesweneneneeneneswsewesw
seswswswseswswswswsweenwswswwseswwsw
swswswsewneseesenwseseswseswswswnwsesw
nwwnewnwnwswnwnwswnwsenwwnwenwnenww
wswwnwwwswwwwswe
eewneeeeneeswsee
wseneseeseewseseseswsewse
wwswnwnwwnewnwsewenenwswwewswwne
seneesesesesewswswwnwseswswseseswseswsw
ewnweeeseneseeseseeneseswwwee
wwwwswwsewwwwewwwwwswnwwne
swsewswswswseswseseeswsenwseswswswsenw
nenenenenesenenenenenenewenewneswsene
newnewewwnwnwnwsewwswnwwwwesww
neseeeneneeewnee
wsenwwnwenwnwwnwnwnwwnwnwwnw
nweswenwseseswwseeenwseenwswsesewsw
wwwswwwwsewwwwwwwwne
nenwnwnwnenwnwnwnenwwnwnwnwnwnwe
eeeeeweneeseeeesweeeeew
seneseeeeewewnweseeseseseeseese
swenenenenwesweewneeeneneeeeeee
wnenwseswnwwwsenwnwwnwnwwnwwnwnwnwnw
sewwwswnwwnwwwswwnewwewwwsw
swwwwswswwswswwwswnew
esweeneeswenwnweesweneeeeswee
eenweeseneeeeeeeeeseeenenwsw
nwneswweeneseswnwswnweeesesesenwe
neneneeswnwnwnwnenenwnenene
wseewseeseseneswsenwsenewsesweseswswse
eseswneneseneenenewswwnwnenenesenenenw
seswsesesweseswseswseswwsw
nwnenenenenwnenenwsenenwwsenewnenenene
eneneneneswnenenenenenenenwneneneswnwnw
neneeneneenwnenenesweneneewsweneene
swnwnwneswnwnwseenwnwnenwenewnwnwnwwnw
swswwnwwswnwwseswewswneseneswewneswe
neswswnewwswswwwswwsewww
nwneeenwswnwsenwnwnwnwnenwswnwnwsenwnw
neeswnwnwwnwseswesweneswnw
swnenwenwnwnwnwsesenwswnwnwnwnwnwnwnwnw
swseswswnenwwwwseswwwwsw
seswneseswseswswswsewesenwsenesewsesw
eseeneswseenwewseewneeeene
swnenenenenenenewwneneswnenenesenesenw
swnenwnenwnwenenenwnenenwnwnene
eswneenwwnwwwneewneneneswneseswee
neseneseneewneeeweewnwneeseee
nesenenenenwnwnenwswnwnenwnenenwnw
seswsesesenwseeeeseseeesesewseenw
eneswsewneeswnenweswneeswnewwswseene
eeseseseswneswseseeeeeeeeewne
wwwseswnenwwnwnwenenwnw
sesenesweeeeeweeeweeenwwe
wsewnwwsewwewwnew
esesenwnwwwneswwswsenwnwnwseswneswwew
nenwwnwnwnwswwenwwwenwwwnwnwwnw
seeeneeneeseeswnenenwsweweewee
swswswwswswswswwswswwswneswswsw
nweseneweseeswwnwwswswnw
wnwsweswseswswswswseswne
swnenenwneenenenenenenenenenenenene
swswswswswseswswwswswswwnwwenwnwseswesw
wswwswswwswswsweswewswwswnwnesw
neneeewneneeswnewneneeseseswewnw
seseswseeesenwsesweseneseeseeesese
nenenenwnesewneswneneseneenewnene
neneneneneneswwneneneneneesenenenenene
swswswnwswnwswsweeswswseswswswswswswnw
sweeseseneeeseeswnewnwnwwewsee
neswsenwnewwnwwwwwwswweseenenww
nwwwwnwwwsewnwwswnewwwnewww
nwswsweswswneswseswswswswwneseswwnesww
wsewwnwwwwswnewwwwsewswwwsw
nwwwwwsenewneewwseenewwsesw
nwnenwwnwwnwwnenenwnenwenesenwenwne
nwnenwnwsewnenwsenwnenenwnwnenenenwnene
wswswwwenwswenesewwnenwe
wseswneeswneseenwnwsenwswewwweswesw
swnwseseeeeewseswnwseneseswsenwsesene
sweneswnwnwswsweneswnwswneswneswsweswsw
eeeswnwswneeneenewswnewneneeee
senwwnenwenwnwwsenwnwnwnenw
esesenweseeeeseseeesesese
seeeeseneseseeeswseeeeseewsene
wneswwwwswswwwewwnesesenwwwse
wnwnwwwsenwnwswnwnwnenewnwnwwnwwnw
senewsesesesesesesesesesesese
eenweswneeenee
nwnenwwnwnwnwnwwwseenwnwnwwnwnwnwswnw
esweneseeneeneeneneneneneswnenewnee
nwwwwswwewnwnwww
neneeneewneeneneneswnwnesenenenenwnesene
wneswsesenewswwwwwwwnwswwwseww
wesenesewswsenwswneswswseswneesesese
sesesenwswsewnwsenwswseswesenenwseeseew
wwnwswwneswwweswwwwwwwswww
nenenwnesewwswswewsenwswnewwswew
wwwnwwwnenwwwwwnwswnwnw
nenwswneneneenenenenwnenwnwnwnenwnw
swenwswewswswswewnwwswnewswseswne
swsenweeseswenwseseswsenwsesewseswswse
eeeweswnwnenenweeswneeeseneeee
swwswneseswnwseneswnewswweseswnwww
swswswswnenwswswseswseswswswneswwseswsw
enwsewsweeseseseneweeseswesenwese
nesenweneneneneneswnwnwnenwnenwnenwnene
seswseeenwsesenweseseseseseneseeseeswse
senenwsewnwnwnenwewnwswwneswnwnwsweenw
neeewnenweseseseeswnesweneneewwse
eeenwswswseneweseneenweneneneew
swswneneswnenenenwnenwnenenenwnwnwwnwe
swsweswwswswswwnwwwweswswswwswnw
wewwewwwwnwswswwwwswwswsww
swwnwwswnweseswnwswseweenewwww
neswswswseswswseswswswseswwswswswsesenw
eneeneneneewneneneeneneenesew
nwnwnwnwnwnwnwsenwenenenwnwnwnwwnwnwswne
weneswnwsenewseseswseeseene
eseseweneenwnweseeseseneneweswswe
swswswswseswswsenwnwseswseeswswsweswnw
sweswwsweswswwswswsweswswwnwswnwenw
eeeseseeenwsewswesesewsenwsenesw
seneswseseseseneseseseweesesesw
ewnwnwwnenwwnwwnenwwnwsewwnwswww
senweeswseswneweesesesesewnwnwsee
wseseseseseseeneseese
neswneswewnwswwwwwwwswwwseewnwse
sewwsesesewnwswswswseeneeesesewse
sweswwneseneswswswswnwswnesene
eesweeenenweeneeeswenwneeeene
eseseeneweeseeeeneenwneeenwne
neneneneneswneenenwnewneneneneswnenenenee
nwnesewwswswseswnwwneswswwswwsesesw
eeneeswesenwewenwneneeeseenwesw
nenwneneneneswnenenenwnwnenw
wwseewnewwneenwwnwswsewseenwse
wsenwwnwwswwwwwswnweewnenwsee
nweseswseseseeeseeseeseeesenwsese
neneswseesewesenenenwneswwswnewswswsenw
wwneseenwwsenwnwnwneswswewnwswwnwne
eneneeneneeneesw
nwnenenwenwnwseeenwwswnwnenwnenewnw
swsweswswsewewswswnwnwwsewwe
swseneswswswswswswsesewswswseseswswnesw
eseseesenwsenwseseeeweesesweeene
neswnwsewsweseswseseswsesesenwnwneseseswse
eeneeeseeseenwneeneeeeeewne
nenwswewnwsweneswwenwswneseseneenew
weeswwwwnenwswnwsenewnwswwnwnwenw
wwnewswswswwnwseswwwswswwwnwsew
newsenwwneswwnwwnwswseeswseswsenwww
swswwsweneswwwnwnee
nwswswswswswswswswnwnwswenwseswswseeswsw
nwnwnwnewswwswnwnwnenwsenweenwnwnwnese
nwenwseseseswswswswswswenwseswnwewswswse
swneswwewsenwnwnweeenenweeseese
nwwwwwswnwesenwwnee
nwnwwwwnwwnwnwsenw
nwseseseswswneseswswnwseseswsweswsweswsw
enweswnweswnweneeeneneneeeswee
sesenwseswnwswswnenesesesesweseseesesw
swseswsewnwnwwneswswswseswswneseswwsw
nenwnenwnwnwnwnesenwnwnwnwswnene
swwenweesenesweesenweseeeeee
swnewsesenwswesweeneneesewnw
swneweswsenwnenesese
nwnweseeseseseswseewseseenenwsee
neswswneseeeeenenwwneeenenwneseneene
swswswsesesesenwsesesenwseswsesese
nwswnwenwnwnwnwnwnwnwnwnwnwsenwnw
eeneesweeeeeeseswnweeneneewe
eeenweseseeeswnwwnwnenwswnewsenenw
neswswswswseseesweswsenwsesenwnwswswsesew
eseeeseenweseeeeseese
swwwswwswwswwsewwswswnwsww
swswwsenwswwswswswswwwswew
eeeseeeseswewneeswneee
sweseswswenwnwwswswnwnenwwseewwwsee
wwnwwwwnwnwwwwewwenewnwswww
sewneswnwseeneswwwnewnwenewseswwnw
seswswswswwswswswnwsweswswswswseswswe
seswswswswswnwneswnwswswsesesenese
eenweseeeseeeeneneeeweseesw
swnwseswswnweneswenwnewenenwnwswnenese
wweenewnwsewnwwnwnenwswseweesw
wwseneeneneneneseenwwswsewwesee
wwsenewwswswwwswwwwswsw
nwwswwwnwwwnenwnwwnwnenwwswwnesw
eneseeweseesesesweewnwenwwswe
eneneeeweneeseeeenesenenenwne
neeneeeeesweseweeeeeewee
swsewnesenweenwenwnwneseseswnwnenene
sewseswseseswseseseswswesenwneswsesese
nwwwnewsewswswwnwseewwwsenewne
enwneseeeeswswneeenwnweeewwsw
wnwswswswswswsweswsw
nenenenwnesenwnenwnwswwswnene
swseseseseenwesenwsesewseesewnwseenw
eswenwsweeeenwneswseeeenwwnee
sweeswswwswswnwwnwswseseeswsesw
nweenwswsesenwneswnweeeeseseswswsenw
wnewseenwnwswneseeeeswnenwneene
nwsewnwnwnenwnwnwswenwnwnwnwwnwnwnwse
swswswswswswswnwswswswswseeswnwseswswsw
senwseswseeseneseewnwnweeseesesesesese
eeseeeenweeeneeeeneeeew
seswsenwswseesesenwswsesweswneseswsesese
nwwnenwnwwwnwwwsenwwnwnwsewnwnewsew
swneswswswswnwwswswswseswswsweswseenw
swwnenwnwneneenenenwnenwnenenenwnwne
ewneswsenwnwenenenwswseeesewnwsww
wswswenwwnenwnwseeswwnweswswnweeswse
nwnwnwsewnwnwnwenwswwsewnwenwnwwnw
neneswneneneneneneeneenenwnenewnwneenesw
eeeseseeweeeeenee
nwnwnwswsenenwenwnwnwnwswnwnwsenwnwsweene
wwsewwwwswwnewwnewwswwswwsw
nesesewwneseneseweeenwsweenwswwse
eeenweesweeewweeeeneeeee
eseswnwwsenwswneswsesweseneeneneswwwsw
wnwnwnwnwewnwnwseenwwnww
enwsenwseseeneseeseseseeswnwseesesee
neneseseseeswswwseswnesesewswnwnwwee
neenwnwnwnenwsenwnwnwsenwnenenwnwneneswnwnw
senewnwnenweeewnenwnenenwswnwnenwswnwne
seseswseswsesesesesenesewseesesesesew
nenenenwwnwneeneenwswnwnenwnwnenewnee
wwwwwseswneewnewneswnwewswsenw
nwnenwnwnwnwenwnwnenenwnwsenwnwwwnwne
wswwsenewnenenesewneneseseseewnewsw
nwnwsenwnwnwnenwnwnwnwnwnwnwnw
nwswswnwnenenwenenewneeeneswswnenwwnene
sesenwnwenwnwwnwnwnwnwnwnwnwsenwneswsenw
nwneneneswnenwnwnwnenenwnenwsenwnene
seneswneewswnenwwneeeeneeneneewe
seswswswswswneswswswswwweswwswnwswwne
swnenwnwwnenwnwnwsenenwweesenenenew
swsewwnenwnwwwwsenwwwewnwwsenew
eeeeeneeneeweneeeneenwnewswene
nwnwnwnwwnwwwwnwwwwnewnwwswneswe
swwnwsweneseswwswnewswswnwswseswnwseswe
swswswswswswswswswswseswswswswneewnwww
senwnenwsenenewnwnwwsenenwnwnwnwenenw
wswnwenwenewnwwwwwnwnwwswwwsw
swseseswswseswseneswwseneseswwseswsesese
eeeswsenewenweseeeeseeeenesw
enwnenwneswwewnwsewnwnenenwnwse
nwnenwnenwenwnwnenwnwnwswnwnwnwneneswnw
sweswseswswnwswswswswswswseenwswsewsw
wnwnwewnweenwnwewnwwsenwweswnw
senenwnwwnwnwnwwnwwwnwnwnwnwnwnwnwsesw
nwnwnwneswnwnwenwnwnewnwneenwnwnwswne
seesenewnwneswnenenenenenenenesewnene
seswwswnenwnwseseswseswswswseseweneesw
swwswenwwnwnwwewwwnwwnwnwwe
nwnwnenenwnwsenenwnwsenwnwswnwnwnwnwnw
wewsesenwswnewnwnwwnw
nesenenewneesenenweneweneeneeneeswne
senwwsenwswswnwneesewwnwneenwwnwswe
nwnwenwnwnwswnwnwnwnwnwswnwnwwenwnwnwnw
nwnwnwswnwnwneewnesenwnwnwnewnenwnenwnwe
wseseenwswseneseseneeeseeeeesenw
nenewwsewwenenwwsewswwnwwswww
nwwwnwwnesewewwwwswwewwseww
eeswseneswwsenwesesweswwsenwnwnwnese
wnwwswwewwwwwwwsenwnwwnwwsenw
nwnwnwnwnwneseneenwnenwwneenenwnwwnw
nwnwsewswnesenenwenweneseeneswwnenwwne
nwseeneneneneeneneneneneswwwwewswse
nwnenwnenenenwwswneneswnwneneneeenenwne
swswswsweswnwwswswswsweswneswswswswsw
seswseseswseswseswswnwseswswswseneswew
senwwwweswnwneswenwwswnwnwnenwwse
swswswswsewseswsewsesesesweneswsesesw
enenewneneneeeewneneseeneeneseene
nwnwnwnwnwwsenwnwsenwnwsenwnwwnwnenwnwnesw
nenenenwswnwneneneneneneneenwsenenenenw
nwnenwnwnwnwnwenwnwnwswneswnwnwnwnwnwsenw
neenenwseswnwseswswnwwnenwnwnenenenwswsew
sewnenwnenwenesenwwnwsenenwwne
wswnwwswwnwnwnwnenewnwnw
senwswneeswswswswwwswswswwsweswwsw
esewswneeeeneeewneneneneseenenwnene
nenwnwwneswnwswnwnenwswnwnwsenenwnenwnwnw
wswswnwswswwswnwswwsweweswswswsw
swswenewweswwwsweewwseswwnwnw
swwwseswswwsenesweesweenwnewsese
eseeseneseewsweneeeeseeeeee
wwnwwnwnwnwwswsewnwnwnwnwewwwnw
nwneswnwswnenwenwnwnenwnwwsenwnwnwnwne
eeeeeeneneneeweeeese
seseswseswneneseseswsenwseseseswseswsesee
wswwseswswswswswewwswnwnewsww
esenwwwseswwwnewwewnewwwww
seeeeeneeseeesenweseesewnwesese
eswwewwwwnwwwwwsewwwewnwsw
seeseeseesenwnwseeswsweswseseseesesenw
eeseeweeeseeeeeeeee
seeeseewswsenwseenwseeseneneswese
nwnwnwwneneneneewnwenenenenwsenwswnw
wsesweswnewswneswsenesewswnwseswnesene
seswseseseswseseseseswnwswswseswsesenwe
newnenesewneneneeneneseneeneneneesw
swswswswwsweswswwwwswsenweswnwwne
enwwwnwswswswwsew
nwnwnwneswnenwnwnwnenenwe
nenwneneseswnenwnenwneswneswwswneseee
eneneneeneswswneneenwswenwwneseenenw
seseswnwsenwsewswnewnwwneewneswswnew
eneneenenenenenenenenewnenenenesw
neswneswwneneewseneneeewnwnenenwne
swnwnewneeseswnweneswnwsenwnwwsewe
swwenenwswwnwsweseswswsw
senenwnenenenewnwnewnwenwnwneeneswnee
wnewneswswswwneseswww
sewwweswsewseswswswswnewseeneesw
wnwnwwsewwnwneseewwwnwsenwwww
swswswwswwswewwswswswseeswswnwswsw
seswneswsewswswswseseeswsw
nwwwnwsenwwseseneewwnwnwwwwnw
swswswswnwswwswsewne
sewneswswwweseneneeswnwnwswewswswe
nenwenwenwnwwnwnenwnenenenwnwneswnenw
eeneseseseseenwseswnewsesenwwew
nenwnesenenwwnenenenwnenenwneene
swseeseseseswsenewseseeswswnwswwswnwnwne
nwnenwnenwwnewswswseenwnwnwnw
seseswseswwsweswswswsenwswsenenwswswseswsw
nwwwsewwwwwnenwnwwwwwnwsenwsew
nenwnenwnenenenwnenwnenenesewneswnenenw
neenwnenesenwnenwnwneenwseswnwwwnwne
nenwnwnesenwnwenwnwsenwnwnwnwnwnwnwnww
swwwwwswwneswwwwsewwswwswenw
nwswswwswnwseseenww
nenwsesewneeswnwnenesenesenenewnwneee
swnewweneswseswswswswswswswswneswswswnwsw
eneseneeswwnwwnwnwsesewswenwnwsewnw
nweswnenenesenwneneneneswenenenenenenwnw
swnwnweneseenwewnweeswsenwswswnwese
esenwsweenwseeseeeeeesesweeese
wwwwwwwwwwwnesewww
swseswsesesenwseswswse
seseseswseesewseswseseseswswsese
wseeswswneseseswnwnwswswswnewwwwsw
wnwenwnwswnwnwswnwewewwnwnewnwnwse
enenwnwwwnwwwsenenwswnwseneseswnenw
eeeeswseseeeeseeeenwswnweeese
nwneswswswseswswwswswseeswswswwseswswsw
swseswnwswseswneswswswswswswsweswswsww
swswswswnwswswswsenweseseswseneseswswne
eswwnweseesesewnwsesesenwseseneesesese
enwseewnesweeenenwneseeswneeswenwe
wswwswswwseewswwnwwwseswnwswenw
nwnwnwwnwnwnwswnwnwnwe
swsenwnenwnwnwnwwe
nwseeseneeeeseeeeeeeswneseswe
neeeeewnenewnesesw
nwsewesenwnwnenenwnwsewwseneenwswnwnw
nwsewwnenenenesenwnwsenwsewnesenenwse
swsenenenwseseseswswsenwweeswsenwwsesw
wewswswwswwwwnenweswwsw
sewwwwneswnewwswwwwwwwnewwww
nenwnesenwenenwnenesenenwswswenewwnenene
eneeneeseeewneeneee
seswnwwwnenwewewnwenwwnwnwsesew
swseenewnesenwwsenwwseswnese
senwwwwewsenwwnwnwnwnwswnwnenwwswnwne
nwseseseneswsenenesesenewnesesenwswwseswe
sesewnwnwnweeswnwnwwnwnwwnwnenwnwnese
nwneneneenenwneswnwnwneneneneswnenenene
wweseseswswneswsesweseswseseswsewswe
esweseeeseswnwsenwseenwsenweesew
neswseeweeesweseeseesesenwseee
nwwnwnwswesewneenwsesewwwnwnwnww
nesewneseneeneneeeeenenewnenenenenenw
eswswswwswswwwwswnwswswwwswswsene
eeneneeneenenenwnenenewneeeeewsw
swseswneswswseseswswneseneswsesesese
weweseneneesweswswnenwenwnwwseswse
nenewnweesenenwneneneneeseneeneenenese
enenwwnwnwnwnwnewnwnwwswwwnwnwwnwse
seeseswseseeenwsesenesenwseseeeese
neenwwnesenwneneneswsenenenwnwsenwnwwne
swwwswswswnwwewswnewwnewwwswswsw
seswsesesesesewsesesenewneneseesesese
neswswnwswswswseswwnesewswnwse
wseseswnwsenwswswswseseeeswnewseeswsw
seseewenwseseseesesew
seneswseswnweneseswnwwnwsenenwsenwsesww
wwseneswswwswwneseswswswswwseswswwne

76
2020/d24/ex2/ex2.py Executable file
View file

@ -0,0 +1,76 @@
#!/usr/bin/env python
import itertools
import sys
from collections import defaultdict
from copy import deepcopy
from typing import Dict, Iterator, List, Tuple
Offset = Tuple[int, int]
Grid = Dict[Offset, bool]
DELTAS = {
"nw": (0, -1),
"ne": (1, -1),
"e": (1, 0),
"se": (0, 1),
"sw": (-1, 1),
"w": (-1, 0),
}
def to_offset(path: str) -> Offset:
offset = 0, 0
i = 0
while i < len(path):
direction = path[i]
i += 1
if direction in ["s", "n"]:
direction += path[i]
i += 1
x, y = offset
dx, dy = DELTAS[direction]
offset = x + dx, y + dy
return offset
def neighbours(tile: Offset) -> Iterator[Offset]:
x, y = tile
for dx, dy in DELTAS.values():
yield x + dx, y + dy
def step(blacks: Grid) -> Grid:
to_visit = set(itertools.chain.from_iterable(neighbours(tile) for tile in blacks))
to_visit |= {tile for tile in blacks}
res: Grid = defaultdict(bool)
for tile in to_visit:
num_neighbours = sum(blacks[n] for n in neighbours(tile))
if blacks[tile]:
res[tile] = num_neighbours in (1, 2)
else:
res[tile] = num_neighbours == 2
return res
def solve(raw: List[str]) -> int:
blacks: Grid = defaultdict(bool)
for offset in map(to_offset, raw):
blacks[offset] = not blacks[offset]
for __ in range(100):
blacks = step(blacks)
return sum(blacks.values())
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

471
2020/d24/ex2/input Normal file
View file

@ -0,0 +1,471 @@
swswswswneswswwwswnewswswweswnwsww
nwwewenenwnenwnwnwnwneswnwswnwnwswswnw
seneswwwswwnenwnenwswswswswsewseeww
esenesenesesesewseseswnesesweesesesese
seseseeseenesewseenwsesewswwsesenwse
eswenewnenenewneneneneenenenenwnene
nwseeseseeseseseseewseesenwseeesese
nwnwswswswweneseswwswwneswswswswswsw
senenenwnenewneneneseswneeeenenenew
eswnwnesenwnwnenwnwnwnwwnwsenwwswswenw
wswneswswseesewswseswswswnenesenenwswswne
seswseswneswswswwnwswwswseneswswswswsee
neseseswnwesesesesewswsesenesenesesesw
wwswwwsweswwwww
seswwnwneenwswneenwewneneneseenee
eswseenweswewseneeeeseeswnwnwse
swsweswswswnweswswneswwswnwswwwswswswsw
nwwnwnwnwnwnwnwnwwswwnweneswwenwnw
sewswwwwwwwweswwwwneswwnwswnw
nwneeneeneneseneseneneneneneneswnenwnene
swnenenweeneeeseswweneenenenenene
nwnwnwsenwewsesenwenwwwswwnwnesenw
swnwswswswswswsewseswnewneseswswswneesw
wwweswwswwsewswswwwwnwwesewwne
swswsweneswswswenwswnewnwswwneswseswswe
nwnesewwnwwnwwwsew
enwwwnenwnewwwwswwseeswewe
neswseswswsenwseswnwseswse
senwseneneneneneeseneswnenenenenwnenwnw
swseneswwseenwsenwneneswnewnenewene
ewwwwwwwewwwnwswwwwwwwne
eswswenwsenwnwsenenw
nwneseewseswwsewswnwnwnwwwwnewww
nwwwwwwwwewnwwswnew
neeeseeesewseeeeeeeewe
wweswnenwwnewnwnwwwewsewnwwsew
swwswwwswwewwswswnwsweswnwwwww
eseswneenwneenweseenweeseeeenw
neneswneneneneneneneneneswnenwnwnw
nwnwwnwewwswwnwwwnwsewnwwenwnw
seswswswnwswwwwswwswneswwseswnw
nwseswenwwneneneseswneenwnenenwnenwnenw
nwnenenenesewwnenwnwnesenwnwnwnwnenwnwnw
wseeeneseeeseseesesenwseseswsesese
sweseswnwseseseswseswseseseswswswse
ewwwswswsenwewnewwwenwwwnwww
nwwsewnwnwnwneswwnwesewnwwnwnwnwnwne
nenwnwnwnenenwnenwnwswswnwneenenwnwnwne
esenwneswsesesweeeeweseseeseseswnw
swswswswwsesweseswswswsw
swsweneswwseswswswwswsenewswwswseswnene
nenenewnwnenenwenwnesenwneseswnwnwnwne
nenenenewneeseneneswneneneswsenenenwne
nenenwnenwswwnweesenwsenwnwnwseswnwnwnw
seseeenwsenwswsesenwseeseeseeseswese
swneeseseneswswnwswnwwwwswswnee
seeseseseneseseswsewseenenwwneseswse
wswseseenwwswnewenwswswwwnewwsw
nenewswnwnenwnwneeneswseeneswnenwnenesene
nwswsenweweseeneseesesesesesesesee
seneswswwesenenwswseswnwseseseseseswne
wwnwwweswnwnwwweneseewnwsesenw
swswneneneneenewnesenewweenweswne
eseneseneseenenewwswseweenweenenene
nwwnwwnwsenwnwnwnwwnwwnww
swweswsewewwwwwwwwwwnewne
swswnewseseseesenewseesesesesesenwese
swswnenwnenwnwnwnwnenenenwnwwnenwseene
wnwwwwnwnwwnwwnwnwwwnwnwsenwe
nwseswwwnenwwwwesewwwwwwwnenwnw
nwswswnwswwswwnenenwnwnwnwnewnenw
seswswswnwswswswswswswswswswswswsw
neneseeneswnwnenwnwsenwnenenewne
wwwwwnenwnwnweswwnwsewwwesese
swwswswwwwseswswenwnewswwswweswnw
swwswseswswseeswswswewswswnwswswese
nwnwewsenenwnesewwwwswnwnenwswsee
seseseenwwswseneneseswswnwnewswnwsenwse
wwswwnwwwwsewwwenewnwswnwwwe
swwwwswwswwswneseswswswwnewswwse
nenenwneeswnenesweneneneeneneswsewesw
seswswswseswswswswsweenwswswwseswwsw
swswswsewneseesenwseseswseswswswnwsesw
nwwnewnwnwswnwnwswnwsenwwnwenwnenww
wswwnwwwswwwwswe
eewneeeeneeswsee
wseneseeseewseseseswsewse
wwswnwnwwnewnwsewenenwswwewswwne
seneesesesesewswswwnwseswswseseswseswsw
ewnweeeseneseeseseeneseswwwee
wwwwswwsewwwwewwwwwswnwwne
swsewswswswseswseseeswsenwseswswswsenw
nenenenenesenenenenenenewenewneswsene
newnewewwnwnwnwsewwswnwwwwesww
neseeeneneeewnee
wsenwwnwenwnwwnwnwnwwnwnwwnw
nweswenwseseswwseeenwseenwswsesewsw
wwwswwwwsewwwwwwwwne
nenwnwnwnenwnwnwnenwwnwnwnwnwnwe
eeeeeweneeseeeesweeeeew
seneseeeeewewnweseeseseseeseese
swenenenenwesweewneeeneneeeeeee
wnenwseswnwwwsenwnwwnwnwwnwwnwnwnwnw
sewwwswnwwnwwwswwnewwewwwsw
swwwwswswwswswwwswnew
esweeneeswenwnweesweneeeeswee
eenweeseneeeeeeeeeseeenenwsw
nwneswweeneseswnwswnweeesesesenwe
neneneeswnwnwnwnenenwnenene
wseewseeseseneswsenwsenewsesweseswswse
eseswneneseneenenewswwnwnenenesenenenw
seswsesesweseswseswseswwsw
nwnenenenenwnenenwsenenwwsenewnenenene
eneneneneswnenenenenenenenwneneneswnwnw
neneeneneenwnenenesweneneewsweneene
swnwnwneswnwnwseenwnwnenwenewnwnwnwwnw
swswwnwwswnwwseswewswneseneswewneswe
neswswnewwswswwwswwsewww
nwneeenwswnwsenwnwnwnwnenwswnwnwsenwnw
neeswnwnwwnwseswesweneswnw
swnenwenwnwnwnwsesenwswnwnwnwnwnwnwnwnw
swseswswnenwwwwseswwwwsw
seswneseswseswswswsewesenwsenesewsesw
eseeneswseenwewseewneeeene
swnenenenenenenewwneneswnenenesenesenw
swnenwnenwnwenenenwnenenwnwnene
eswneenwwnwwwneewneneneswneseswee
neseneseneewneeeweewnwneeseee
nesenenenenwnwnenwswnwnenwnenenwnw
seswsesesenwseeeeseseeesesewseenw
eneswsewneeswnenweswneeswnewwswseene
eeseseseswneswseseeeeeeeeewne
wwwseswnenwwnwnwenenwnw
sesenesweeeeeweeeweeenwwe
wsewnwwsewwewwnew
esesenwnwwwneswwswsenwnwnwseswneswwew
nenwwnwnwnwswwenwwwenwwwnwnwwnw
seeeneeneeseeswnenenwsweweewee
swswswwswswswswwswswwswneswswsw
nweseneweseeswwnwwswswnw
wnwsweswseswswswswseswne
swnenenwneenenenenenenenenenenenene
swswswswswseswswwswswswwnwwenwnwseswesw
wswwswswwswswsweswewswwswnwnesw
neneeewneneeswnewneneeseseswewnw
seseswseeesenwsesweseneseeseeesese
nenenenwnesewneswneneseneenewnene
neneneneneneswwneneneneneesenenenenene
swswswnwswnwswsweeswswseswswswswswswnw
sweeseseneeeseeswnewnwnwwewsee
neswsenwnewwnwwwwwwswweseenenww
nwwwwnwwwsewnwwswnewwwnewww
nwswsweswswneswseswswswswwneseswwnesww
wsewwnwwwwswnewwwwsewswwwsw
nwwwwwsenewneewwseenewwsesw
nwnenwwnwwnwwnenenwnenwenesenwenwne
nwnenwnwsewnenwsenwnenenwnwnenenenwnene
wswswwwenwswenesewwnenwe
wseswneeswneseenwnwsenwswewwweswesw
swnwseseeeeewseswnwseneseswsenwsesene
sweneswnwnwswsweneswnwswneswneswsweswsw
eeeswnwswneeneenewswnewneneeee
senwwnenwenwnwwsenwnwnwnenw
esesenweseeeeseseeesesese
seeeeseneseseeeswseeeeseewsene
wneswwwwswswwwewwnesesenwwwse
wnwnwwwsenwnwswnwnwnenewnwnwwnwwnw
senewsesesesesesesesesesesese
eenweswneeenee
nwnenwwnwnwnwnwwwseenwnwnwwnwnwnwswnw
esweneseeneeneeneneneneneswnenewnee
nwwwwswwewnwnwww
neneeneewneeneneneswnwnesenenenenwnesene
wneswsesenewswwwwwwwnwswwwseww
wesenesewswsenwswneswswseswneesesese
sesesenwswsewnwsenwswseswesenenwseeseew
wwnwswwneswwweswwwwwwwswww
nenenwnesewwswswewsenwswnewwswew
wwwnwwwnenwwwwwnwswnwnw
nenwswneneneenenenenwnenwnwnwnenwnw
swenwswewswswswewnwwswnewswseswne
swsenweeseswenwseseswsenwsesewseswswse
eeeweswnwnenenweeswneeeseneeee
swwswneseswnwseneswnewswweseswnwww
swswswswnenwswswseswseswswswneswwseswsw
enwsewsweeseseseneweeseswesenwese
nesenweneneneneneswnwnwnenwnenwnenwnene
seswseeenwsesenweseseseseseneseeseeswse
senenwsewnwnwnenwewnwswwneswnwnwsweenw
neeewnenweseseseeswnesweneneewwse
eeenwswswseneweseneenweneneneew
swswneneswnenenenwnenwnenenenwnwnwwnwe
swsweswwswswswwnwwwweswswswwswnw
wewwewwwwnwswswwwwswwswsww
swwnwwswnweseswnwswseweenewwww
neswswswseswswseswswswseswwswswswsesenw
eneeneneneewneneneeneneenesew
nwnwnwnwnwnwnwsenwenenenwnwnwnwwnwnwswne
weneswnwsenewseseswseeseene
eseseweneenwnweseeseseneneweswswe
swswswswseswswsenwnwseswseeswswsweswnw
sweswwsweswswwswswsweswswwnwswnwenw
eeeseseeenwsewswesesewsenwsenesw
seneswseseseseneseseseweesesesw
ewnwnwwnenwwnwwnenwwnwsewwnwswww
senweeswseswneweesesesesewnwnwsee
wseseseseseseeneseese
neswneswewnwswwwwwwwswwwseewnwse
sewwsesesewnwswswswseeneeesesewse
sweswwneseneswswswswnwswnesene
eesweeenenweeneeeswenwneeeene
eseseeneweeseeeeneenwneeenwne
neneneneneswneenenwnewneneneneswnenenenee
nwnesewwswswseswnwwneswswwswwsesesw
eeneeswesenwewenwneneeeseenwesw
nenwneneneneswnenenenwnwnenw
wwseewnewwneenwwnwswsewseenwse
wsenwwnwwswwwwwswnweewnenwsee
nweseswseseseeeseeseeseeesenwsese
neneswseesewesenenenwneswwswnewswswsenw
wwneseenwwsenwnwnwneswswewnwswwnwne
eneneeneneeneesw
nwnenenwenwnwseeenwwswnwnenwnenewnw
swsweswswsewewswswnwnwwsewwe
swseneswswswswswswsesewswswseseswswnesw
eseseesenwsenwseseeeweesesweeene
neswnwsewsweseswseseswsesesenwnwneseseswse
eeneeeseeseenwneeneeeeeewne
nenwswewnwsweneswwenwswneseseneenew
weeswwwwnenwswnwsenewnwswwnwnwenw
wwnewswswswwnwseswwwswswwwnwsew
newsenwwneswwnwwnwswseeswseswsenwww
swswwsweneswwwnwnee
nwswswswswswswswswnwnwswenwseswswseeswsw
nwnwnwnewswwswnwnwnenwsenweenwnwnwnese
nwenwseseseswswswswswswenwseswnwewswswse
swneswwewsenwnwnweeenenweeseese
nwwwwwswnwesenwwnee
nwnwwwwnwwnwnwsenw
nwseseseswswneseswswnwseseswsweswsweswsw
enweswnweswnweneeeneneneeeswee
sesenwseswnwswswnenesesesesweseseesesw
swseswsewnwnwwneswswswseswswneseswwsw
nenwnenwnwnwnwnesenwnwnwnwswnene
swwenweesenesweesenweseeeeee
swnewsesenwswesweeneneesewnw
swneweswsenwnenesese
nwnweseeseseseswseewseseenenwsee
neswswneseeeeenenwwneeenenwneseneene
swswswsesesesenwsesesenwseswsesese
nwswnwenwnwnwnwnwnwnwnwnwnwsenwnw
eeneesweeeeeeseswnweeneneewe
eeenweseseeeswnwwnwnenwswnewsenenw
neswswswswseseesweswsenwsesenwnwswswsesew
eseeeseenweseeeeseese
swwwswwswwswwsewwswswnwsww
swswwsenwswwswswswswwwswew
eeeseeeseswewneeswneee
sweseswswenwnwwswswnwnenwwseewwwsee
wwnwwwwnwnwwwwewwenewnwswww
sewneswnwseeneswwwnewnwenewseswwnw
seswswswswwswswswnwsweswswswswseswswe
seswswswswswnwneswnwswswsesesenese
eenweseeeseeeeneneeeweseesw
swnwseswswnweneswenwnewenenwnwswnenese
wweenewnwsewnwwnwnenwswseweesw
wwseneeneneneneseenwwswsewwesee
wwsenewwswswwwswwwwswsw
nwwswwwnwwwnenwnwwnwnenwwswwnesw
eneseeweseesesesweewnwenwwswe
eneneeeweneeseeeenesenenenwne
neeneeeeesweseweeeeeewee
swsewnesenweenwenwnwneseseswnwnenene
sewseswseseswseseseswswesenwneswsesese
nwwwnewsewswswwnwseewwwsenewne
enwneseeeeswswneeenwnweeewwsw
wnwswswswswswsweswsw
nenenenwnesenwnenwnwswwswnene
swseseseseenwesenwsesewseesewnwseenw
eswenwsweeeenwneswseeeenwwnee
sweeswswwswswnwwnwswseseeswsesw
nweenwswsesenwneswnweeeeseseswswsenw
wnewseenwnwswneseeeeswnenwneene
nwsewnwnwnenwnwnwswenwnwnwnwwnwnwnwse
swswswswswswswnwswswswswseeswnwseswswsw
senwseswseeseneseewnwnweeseesesesesese
eeseeeenweeeneeeeneeeew
seswsenwswseesesenwswsesweswneseswsesese
nwwnenwnwwwnwwwsenwwnwnwsewnwnewsew
swneswswswswnwwswswswseswswsweswseenw
swwnenwnwneneenenenwnenwnenenenwnwne
ewneswsenwnwenenenwswseeesewnwsww
wswswenwwnenwnwseeswwnweswswnweeswse
nwnwnwsewnwnwnwenwswwsewnwenwnwwnw
neneswneneneneneneeneenenwnenewnwneenesw
eeeseseeweeeeenee
nwnwnwswsenenwenwnwnwnwswnwnwsenwnwsweene
wwsewwwwswwnewwnewwswwswwsw
nesesewwneseneseweeenwsweenwswwse
eeenweesweeewweeeeneeeee
eseswnwwsenwswneswsesweseneeneneswwwsw
wnwnwnwnwewnwnwseenwwnww
enwsenwseseeneseeseseseeswnwseesesee
neneseseseeswswwseswnesesewswnwnwwee
neenwnwnwnenwsenwnwnwsenwnenenwnwneneswnwnw
senewnwnenweeewnenwnenenwswnwnenwswnwne
seseswseswsesesesesenesewseesesesesew
nenenenwwnwneeneenwswnwnenwnwnenewnee
wwwwwseswneewnewneswnwewswsenw
nwnenwnwnwnwenwnwnenenwnwsenwnwwwnwne
wswwsenewnenenesewneneseseseewnewsw
nwnwsenwnwnwnenwnwnwnwnwnwnwnw
nwswswnwnenenwenenewneeeneswswnenwwnene
sesenwnwenwnwwnwnwnwnwnwnwnwsenwneswsenw
nwneneneswnenwnwnwnenenwnenwsenwnene
seneswneewswnenwwneeeeneeneneewe
seswswswswswneswswswswwweswwswnwswwne
swnenwnwwnenwnwnwsenenwweesenenenew
swsewwnenwnwwwwsenwwwewnwwsenew
eeeeeneeneeweneeeneenwnewswene
nwnwnwnwwnwwwwnwwwwnewnwwswneswe
swwnwsweneseswwswnewswswnwswseswnwseswe
swswswswswswswswswswseswswswswneewnwww
senwnenwsenenewnwnwwsenenwnwnwnwenenw
wswnwenwenewnwwwwwnwnwwswwwsw
swseseswswseswseneswwseneseswwseswsesese
eeeswsenewenweseeeeseeeenesw
enwnenwneswwewnwsewnwnenenwnwse
nwnenwnenwenwnwnenwnwnwswnwnwnwneneswnw
sweswseswswnwswswswswswswseenwswsewsw
wnwnwewnweenwnwewnwwsenwweswnw
senenwnwwnwnwnwwnwwwnwnwnwnwnwnwnwsesw
nwnwnwneswnwnwenwnwnewnwneenwnwnwswne
seesenewnwneswnenenenenenenenesewnene
seswwswnenwnwseseswseswswswseseweneesw
swwswenwwnwnwwewwwnwwnwnwwe
nwnwnenenwnwsenenwnwsenwnwswnwnwnwnwnw
wewsesenwswnewnwnwwnw
nesenenewneesenenweneweneeneeneeswne
senwwsenwswswnwneesewwnwneenwwnwswe
nwnwenwnwnwswnwnwnwnwnwswnwnwwenwnwnwnw
nwnwnwswnwnwneewnesenwnwnwnewnenwnenwnwe
wseseenwswseneseseneeeseeeeesenw
nenewwsewwenenwwsewswwnwwswww
nwwwnwwnesewewwwwswwewwseww
eeswseneswwsenwesesweswwsenwnwnwnese
wnwwswwewwwwwwwsenwnwwnwwsenw
nwnwnwnwnwneseneenwnenwwneenenwnwwnw
nwnwsewswnesenenwenweneseeneswwnenwwne
nwseeneneneneeneneneneneswwwwewswse
nwnenwnenenenwwswneneswnwneneneeenenwne
swswswsweswnwwswswswsweswneswswswswsw
seswseseswseswseswswnwseswswswseneswew
senwwwweswnwneswenwwswnwnwnenwwse
swswswswsewseswsewsesesesweneswsesesw
enenewneneneeeewneneseeneeneseene
nwnwnwnwnwwsenwnwsenwnwsenwnwwnwnenwnwnesw
nenenenwswnwneneneneneneneenwsenenenenw
nwnenwnwnwnwnwenwnwnwswneswnwnwnwnwnwsenw
neenenwseswnwseswswnwwnenwnwnenenenwswsew
sewnenwnenwenesenwwnwsenenwwne
wswnwwswwnwnwnwnenewnwnw
senwswneeswswswswwwswswswwsweswwsw
esewswneeeeneeewneneneneseenenwnene
nenwnwwneswnwswnwnenwswnwnwsenenwnenwnwnw
wswswnwswswwswnwswwsweweswswswsw
swswenewweswwwsweewwseswwnwnw
swwwseswswwsenesweesweenwnewsese
eseeseneseewsweneeeeseeeeee
wwnwwnwnwnwwswsewnwnwnwnwewwwnw
nwneswnwswnenwenwnwnenwnwwsenwnwnwnwne
eeeeeeneneneeweeeese
seseswseswneneseseswsenwseseseswseswsesee
wswwseswswswswswewwswnwnewsww
esenwwwseswwwnewwewnewwwww
seeeeeneeseeesenweseesewnwesese
eswwewwwwnwwwwwsewwwewnwsw
seeseeseesenwnwseeswsweswseseseesesenw
eeseeweeeseeeeeeeee
seeeseewswsenwseenwseeseneneswese
nwnwnwwneneneneewnwenenenenwsenwswnw
wsesweswnewswneswsenesewswnwseswnesene
seswseseseswseseseseswnwswswseswsesenwe
newnenesewneneneeneneseneeneneneesw
swswswswwsweswswwwwswsenweswnwwne
enwwwnwswswswwsew
nwnwnwneswnenwnwnwnenenwe
nenwneneseswnenwnenwneswneswwswneseee
eneneneeneswswneneenwswenwwneseenenw
seseswnwsenwsewswnewnwwneewneswswnew
eneneenenenenenenenenewnenenenesw
neswneswwneneewseneneeewnwnenenwne
swnwnewneeseswnweneswnwsenwnwwsewe
swwenenwswwnwsweseswswsw
senenwnenenenewnwnewnwenwnwneeneswnee
wnewneswswswwneseswww
sewwweswsewseswswswswnewseeneesw
wnwnwwsewwnwneseewwwnwsenwwww
swswswwswwswewwswswswseeswswnwswsw
seswneswsewswswswseseeswsw
nwwwnwsenwwseseneewwnwnwwwwnw
swswswswnwswwswsewne
sewneswswwweseneneeswnwnwswewswswe
nenwenwenwnwwnwnenwnenenenwnwneswnenw
eeneseseseseenwseswnewsesenwwew
nenwnesenenwwnenenenwnenenwneene
swseeseseseswsenewseseeswswnwswwswnwnwne
nwnenwnenwwnewswswseenwnwnwnw
seseswseswwsweswswswsenwswsenenwswswseswsw
nwwwsewwwwwnenwnwwwwwnwsenwsew
nenwnenwnenenenwnenwnenenesewneswnenenw
neenwnenesenwnenwnwneenwseswnwwwnwne
nenwnwnesenwnwenwnwsenwnwnwnwnwnwnwnww
swwwwwswwneswwwwsewwswwswenw
nwswswwswnwseseenww
nenwsesewneeswnwnenesenesenenewnwneee
swnewweneswseswswswswswswswswneswswswnwsw
eneseneeswwnwwnwnwsesewswenwnwsewnw
nweswnenenesenwneneneneswenenenenenenwnw
swnwnweneseenwewnweeswsenwswswnwese
esenwsweenwseeseeeeeesesweeese
wwwwwwwwwwwnesewww
swseswsesesenwseswswse
seseseswseesewseswseseseswswsese
wseeswswneseseswnwnwswswswnewwwwsw
wnwenwnwswnwnwswnwewewwnwnewnwnwse
enenwnwwwnwwwsenenwswnwseneseswnenw
eeeeswseseeeeseeeenwswnweeese
nwneswswswseswswwswswseeswswswwseswswsw
swseswnwswseswneswswswswswswsweswswsww
swswswswnwswswswsenweseseswseneseswswne
eswwnweseesesewnwsesesenwseseneesesese
enwseewnesweeenenwneseeswneeswenwe
wswwswswwseewswwnwwwseswnwswenw
nwnwnwwnwnwnwswnwnwnwe
swsenwnenwnwnwnwwe
nwseeseneeeeseeeeeeeswneseswe
neeeeewnenewnesesw
nwsewesenwnwnenenwnwsewwseneenwswnwnw
nwsewwnenenenesenwnwsenwsewnesenenwse
swsenenenwseseseswswsenwweeswsenwwsesw
wewswswwswwwwnenweswwsw
sewwwwneswnewwswwwwwwwnewwww
nenwnesenwenenwnenesenenwswswenewwnenene
eneeneeseeewneeneee
seswnwwwnenwewewnwenwwnwnwsesew
swseenewnesenwwsenwwseswnese
senwwwwewsenwwnwnwnwnwswnwnenwwswnwne
nwseseseneswsenenesesenewnesesenwswwseswe
sesewnwnwnweeswnwnwwnwnwwnwnenwnwnese
nwneneneenenwneswnwnwneneneneswnenenene
wweseseswswneswsesweseswseseswsewswe
esweseeeseswnwsenwseenwsenweesew
neswseeweeesweseeseesesenwseee
nwwnwnwswesewneenwsesewwwnwnwnww
nesewneseneeneneeeeenenewnenenenenenw
eswswswwswswwwwswnwswswwwswswsene
eeneneeneenenenwnenenewneeeeewsw
swseswneswswseseswswneseneswsesesese
weweseneneesweswswnenwenwnwwseswse
nenewnweesenenwneneneneeseneeneenenese
enenwwnwnwnwnwnewnwnwwswwwnwnwwnwse
seeseswseseeenwsesenesenwseseeeese
neenwwnesenwneneneswsenenenwnwsenwnwwne
swwwswswswnwwewswnewwnewwwswswsw
seswsesesesesewsesesenewneneseesesese
neswswnwswswswseswwnesewswnwse
wseseswnwsenwswswswseseeeswnewseeswsw
seseewenwseseseesesew
seneswseswnweneseswnwwnwsenenwsenwsesww
wwseneswswwswwneseswswswswwseswswwne

35
2020/d25/ex1/ex1.py Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
import itertools
import sys
from typing import List
def step(value: int, subject: int) -> int:
value *= subject
value %= 20201227
return value
def solve(raw: List[int]) -> int:
value = 1
for rounds in itertools.count(1):
value = step(value, 7)
if value == raw[0]:
break
key = 1
for __ in range(rounds):
key = step(key, raw[1])
return key
def main() -> None:
input = [int(line) for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

2
2020/d25/ex1/input Normal file
View file

@ -0,0 +1,2 @@
8987316
14681524

9
2020/d25/ex2/ex2.py Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env python
def main() -> None:
print("There is no part two...")
if __name__ == "__main__":
main()

Some files were not shown because too many files have changed in this diff Show more