import 2023 aoc

This commit is contained in:
Thibaud Gasser 2024-12-03 15:29:02 +01:00
parent a454b7e15a
commit cacfbd5bb5
29 changed files with 4450 additions and 0 deletions

48
2023/day1/day1.py Normal file
View File

@ -0,0 +1,48 @@
def part1(lines):
res = []
for line in lines:
digits = [c for c in line if c.isnumeric()]
res.append(int(digits[0] + digits[-1]))
print(f"Part 1: {sum(res)}")
spelled_digits = { "one": "o1e", "two": "t2o", "three": "t3e", "four": "f4r", "five": "f5e", "six": "s6x", "seven": "s7n", "eight": "e8t", "nine": "n9e" }
def substitute_digits(s, trans):
res = s
for word, digit in trans.items():
res = res.replace(word, digit)
return res
def part2(lines):
res = []
for line in lines:
line = line.rstrip()
res_line = []
nline = ""
for c in line:
nline += c
nline = substitute_digits(nline, spelled_digits)
digits = [c for c in nline if c.isnumeric()]
r = int(digits[0] + digits[-1])
print(f"{line} => {nline}, {r}")
res.append(r)
print(f"Part 2: {sum(res)}")
if __name__ == "__main__":
import sys
infile = sys.argv[1]
with open(infile) as f:
lines = f.readlines()
part1(lines)
part2(lines)

1000
2023/day1/input.txt Normal file

File diff suppressed because it is too large Load Diff

158
2023/day10/day10.py Normal file
View File

@ -0,0 +1,158 @@
from typing import Dict, List, Set, Tuple
from dataclasses import dataclass
from collections import defaultdict
from enum import Enum
@dataclass(frozen=True)
class Vec2d:
x: int
y: int
def __add__(self, other):
return Vec2d(self.x + other.x, self.y + other.y)
class Direction(Enum):
NORTH = Vec2d(0, -1) # [0, 0] is the top-left corner, so y increases going downwards
SOUTH = Vec2d(0, 1)
EAST = Vec2d(1, 0)
WEST = Vec2d(-1, 0)
"""
| is a vertical pipe connecting north and south.
- is a horizontal pipe connecting east and west.
L is a 90-degree bend connecting north and east.
J is a 90-degree bend connecting north and west.
7 is a 90-degree bend connecting south and west.
F is a 90-degree bend connecting south and east.
. is ground; there is no pipe in this tile.
S is the starting position of the animal; there is a pipe on this tile, but your sketch doesn't show what shape the pipe has.
"""
PIPES = {
"|": (Direction.SOUTH, Direction.NORTH),
"-": (Direction.EAST, Direction.WEST),
"L": (Direction.NORTH, Direction.EAST),
"J": (Direction.NORTH, Direction.WEST),
"7": (Direction.SOUTH, Direction.WEST),
"F": (Direction.SOUTH,Direction.EAST),
}
PIPES_REVERSE_LOOKUP = {v: k for k,v in PIPES.items()}
def find_start_position(grid: List[str]) -> Vec2d:
for y, row in enumerate(grid):
for x, c in enumerate(row):
if c == "S":
return Vec2d(x, y)
raise RuntimeError("The start position was not found")
def update_start_symbol(grid: List[str], start_pos: Vec2d):
"""
Updates the map by replacing the start symbol "S" with its actual corresponding pipe
"""
# check which neighbors are connected to the start position
connections = []
north = start_pos + Direction.NORTH.value
south = start_pos + Direction.SOUTH.value
east = start_pos + Direction.EAST.value
west = start_pos + Direction.WEST.value
if grid[north.y][north.x] in "|7F":
connections.append(Direction.NORTH)
if grid[south.y][south.x] in "|LJ":
connections.append(Direction.SOUTH)
if grid[east.y][east.x] in "-7J":
connections.append(Direction.EAST)
if grid[west.y][west.x] in "-LF":
connections.append(Direction.WEST)
print("Start symbol has the following connections: ", connections)
assert len(connections) == 2, "start symbol has invalid connections"
pipe = PIPES_REVERSE_LOOKUP[tuple(connections)]
print(f"Start symbol is a {pipe} pipe")
# replace it in the grid accordingly
grid[start_pos.y] = grid[start_pos.y].replace("S", pipe)
def parse_graph(grid: List[str]) -> Dict[Vec2d, List[Vec2d]]:
graph = defaultdict(list)
for y, row in enumerate(grid):
for x, pipe in enumerate(row):
pos = Vec2d(x, y)
if pipe in PIPES:
for direction in PIPES[pipe]:
next_pos = pos + direction.value
graph[pos].append(next_pos)
return graph
def traverse_graph(graph, start_pos) -> Tuple[int, Set[Vec2d]]:
"""
traverse the graph using BFS, return the path and the
find the length of the longest path in the graph
"""
queue = [(start_pos, 0)] # (pos, distance from start)
max_dist = 0
visited = {start_pos}
while queue != []:
cur, dist = queue.pop(0)
max_dist = max(max_dist, dist)
for next_pos in graph[cur]:
if next_pos not in visited:
visited.add(next_pos)
queue.append((next_pos, dist+1))
return max_dist, visited
def count_enclosed_tiles(grid, edges):
"""
count the number of enclosed tiles in the loop by casting a ray on each row
and counting the number of intersections with the edges of the loop
"""
enclosed_count = 0
for y, row in enumerate(grid):
crossings = 0
for x, pipe in enumerate(row):
pos = Vec2d(x, y)
if pos in edges:
if pipe in "L|J":
crossings += 1
elif crossings % 2 == 1:
enclosed_count += 1
return enclosed_count
def main(grid):
rows, cols = len(grid), len(grid[0])
start_pos = find_start_position(grid)
print("Start pos ", start_pos)
update_start_symbol(grid, start_pos)
graph = parse_graph(grid)
max_dist, visited = traverse_graph(graph, start_pos)
print("Part 1: ", max_dist)
# visited edges are the ones that are part of the loop
inside_count = count_enclosed_tiles(grid, visited)
print("Part 2: ", inside_count)
if __name__ == "__main__":
import sys
infile = sys.argv[1]
with open(infile) as f:
lines = [l.rstrip() for l in f.readlines()]
main(lines)

5
2023/day10/example1.txt Normal file
View File

@ -0,0 +1,5 @@
.....
.S-7.
.|.|.
.L-J.
.....

5
2023/day10/example2.txt Normal file
View File

@ -0,0 +1,5 @@
..F7.
.FJ|.
SJ.L7
|F--J
LJ...

140
2023/day10/input.txt Normal file
View File

@ -0,0 +1,140 @@
7-LJ.FF7J7-F-F--F7-.LL|7.LFJ--7F.J.L--FF-F77-F7|7F-F-777.JJ7|.J--F7JF-7-7-F-F-J.F-FF--7..|.LFJ77.77|F7FJ-77|F77FFL|7.|-7.|.7JFF--7|.|7-F--77
|..L|LJJ|7-L7L77|JFFLL7|7|J|L7|7FLL.L-LF7||7LJ-J-J|JL|-F-J-F777LL||.F|.L7|JJL||.|-FJ7FL|F|.LLL77F-7LF|JJLJ-.F7-LJJ||-|F|FLL|-F|L||JLL7FJJ-L7
|77||F.FF-J|FJF-J|F7FFJJJL-7L|L--JLF|7F|FJ|J7F7|L7|7JF.F77FJL-7|L|L77F--LF-FFJJ-LJF|J-LL|L|7FLL-7|-JLL.J.FF7J||LL777-FF7J-JJFFJFF.J7LFLJLF7|
|F|J-|---7F-JFL7.F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L--JF-7-F7|||L--77L-J7JL7
.|FLFF-JL-JLJL-JL---J|LJL-7F7F7F-JL7|L-7F7FJ||L7F7|LJFJL7F-7||L7LJF7L|||FJLJL7|L-JFL7FJL-7FJF---JL7L-----7F-7|L--JL---7L7L-JLJLJF--JJ.|||7L|
FLF.LL7F7F----7F7F--7L7F77LJLJLJF--JL--J||L-JL7LJ|L7FJ-FJL7LJ|FJFFJL-J|LJ.F--JL----7||F--JL7L-7F-7|F-----JL7|L7F7F-7F-JFJF7F7F7FJ|.L|-FJ|7-7
LJ|-L7LJ||F-7|LJLJF7L7LJL------7L-------J|FF7FJF-JFJL-7|F7L7FJL-7L---7L7F-JF--7F--7||||F-7FJF-JL7||L7F7F---JL7LJLJ7LJF-JFJLJLJLJF77L7LL-|.|F
.F77.-.|LJL7L7F---JL7|F--7F--7FJLF---7F-7L-J|L7L-7L7F-J||L7|L7F7L7F-7L-J|F-JF-JL-7LJ||LJFJ|FJF-7|||FLJ||F-7F7L----7F7L7FJF---7F7||7--.|7|.-J
J7|.F|F7.F7L7LJF-7F7LJL-7LJF-JL-7L--7||-L7F7L7|F-JFJL7JLJFJ|-|||FJL7L---J|F7L-7F7L-7LJF-JFJ|FJLLJ||F--J|L7LJ|F----J|L-JL-JF--J|LJL-7JF-7L7J7
L|L-7-F77|||L--JL||L----JF-JF--7|F--JLJF7LJL-JLJF7L-7|F7-L-JFJ||L7FJF-7F7LJ|F-J||F-JF7L-7|L|L7F--J||F--J7L-7|L-----JF7F--7|F7L|F---J-FJ|L7L|
LL..LF||FJL---7F7||F--7F7L-7|F-JLJF--7FJ|F7F7F7FJL-7|LJL7F--JFJL7||FJFJ|L7FJ|F7||L--J|F-JL7|FJL-7FJLJF7F7F-JL-------J|L-7|LJL-JL--7J-F7|-JFJ
7-J.LFJLJF---7LJ|||L-7LJ|F7LJL7F7FJF-J|FJ|||||||F--JL--7||F-7L-7LJ||FJFJFJ|FJ||||F7F7||F-7||L7F-J|F7FJLJLJF7F-------7|F7||F----7F-J7JL-.7JL7
J.L-FL---JF7-L-7|LJF7L7FJ|||F7||LJ|L--JL-JLJLJLJL-----7||LJFJF7L-7|||FJJL7|L7|||||||LJLJ|LJL-JL--J||L-----JLJF------JLJLJLJF7F-J||F7.7---7||
LL-LLF-7F7|L---JL7J||FJ|FJ|FJ|LJF----7F-7F7F----------JLJF7|FJ|F7||||L--7LJFJ|||||LJ7F-7F7F7F--7F7|L77F77F--7L------7F-----J|L-7L-JL-77|.LL7
L7.|.L7|||L-7F--7|FJLJFJL7LJFJF7L--7-LJ|LJ|L--7F7F7F-----J|||FJ||||||F7FJF-JFJ||||F--JFJ|LJ|L-7||||FJFJL7L-7|F--7F--J|F--7F7L-7|F7F7FJ.L-7LL
.|FFFFJLJL-7LJF-J|L--7|F7L-7L-JL7F7L----7LL7F-J|LJ||F-7F-7|LJ|FJ|||||||L7L7FJFJ|LJL--7|FL7FJF-JLJLJL-JF7L--J|L-7|L---JL7.LJ|F-J||LJLJJ..L--|
FF---JF7F-7L--JF7L---JLJL7FJF--7LJL--7F7L7FJL--JF7LJL7LJFJL-7|L7LJ|||||FJL||FJFJF----JL--JL-JF-7F7F-7FJ|F--7|F7||F---7FJF77LJF7LJ|F7FF77..FJ
LL-7F7|LJ-L7F7FJL7F---7F-JL-JF-JF7F7|LJL-JL---7FJ|F-7L-7L---J|FJF-J||||L-7LJL7L7|F--7F-7F7F-7L7LJLJ.LJJLJF-JLJLJLJF-7|L-JL---JL7F7||FJL77.L7
FFL|||L7|F7LJLJF-J|F--JL-----JF7|LJL7FF-----7FJ|LLJFJF7L---7LLJJL7FJLJL7FJF7F|FJLJF7LJ|LJ||FJFJ|F7F-----7L------7J|FJ|F7F7F----J|||||F-J|.FL
FF-LJL-J-|L-7F-JF7|L7F7F-7F-7FJLJF--JFJF----JL7L-7JL7||F---JFF--7||LFJJLJ-|L-J|F--JL-----J|L7|FFJLJF-7F7L-------JFJ|LLJLJLJF--7FJLJLJ|-F7-F7
|L|7|F7F7L-7|L-7|||FLJ|L7|L7||F--JF--JFJLF---7L-7L-7|||L---7FJF-J||.|LFJJ-L7F7|L7F-7F7F7F7L7||FJF7FJFJ|L----7F--7L7L----7F7|F-JL7F---JFJ|-F7
.F---J|||F7|L--J|LJF--JFJL-J||L7F-JF-7L--JF--JF7L--JLJ|F---JL7L-7LJ.|..FF-LLJLJFLJFJ|||LJ|FJLJL7||L7L7|F---7LJF7|FJF----J|||L-7FJL----JFJ7|J
FL-7F7LJLJ||F--7L77L7F7L-7F7LJ|LJF-J-L----JFF-J|F-7F7LLJF--7FJF7L77|.FF7JF.L|.F7.FL7|||F-J|F--7|||FJFJ||F-7L--JLJ|FJF7F7FJ||F-J|F------J7F|7
FLFJ|L7F-7LJ|JFJFJF7LJ|F7||L----7L-7F7F7F7F7|F-JL7LJL-77|F-JL7|L-J-J-FL-7.L.-L|L7J7LJ||L--JL-7||||||L7|LJFJJF----J|FJ|||L7||L7FJ|F7F7F7F7JF7
|JL7|LLJFJF7|FJFJ-|L7FJ||||F7F-7L-7LJLJLJLJLJ|F7FJF---JFJL---JL-77FF-LJ.L..FLL|FJ7FF7LJJF7F--JLJ|LJF7LJF-JF7|F----J|FJ|L7|LJFJL7LJLJLJLJL7L-
L77LJF--JFJ||L7|F7L7LJFJ||||LJFJF7|F7F----7F-J|||FJF7F7|F----7F7L---7.L..F-F-.||F7FJ|F7FJ|L--7F7|F-JL77L-7|LJL-----JL7|FJ|F-JF-JF--7F---7|-L
F|LF7L--7|LLJ|LJ||||F7|7LJLJF-JFJ|LJLJF--7LJJFJLJL-JLJLJL---7||L----J7LF7.||JFJLJLJFJ||L7|F-7LJLJL-7FJF7FJ|F-7F-----7LJL-JL7FJF7L-7|L-7FJ|FL
F77||JJ7LJF7F-7FJ|FJ|||F----JF7|FJF---JF7L7F-JF-7F---7F-7F--J|L------77L7-LFFL7F--7L-JL7|||FJF7-F--JL7||L-JL7|L----7|F--7F7LJFJ|F-J|F7|L7|7J
F--J|F77LL||L7LJFJL-JLJL7F---JLJL-JF---JL-JL7FJ.|L--7|L7LJF77L7F7F7F-J7|L--F-7LJF-JF7F7LJ|||FJL7L7F-7LJ|.F--JL7F7F7||L-7|||F7L7||F7||LJ|||7|
L--7|||F7FJL7|F7L7F-7LF7LJF-7F7F7F7L---7F7F-JL-7L---JL-JF7||F7LJLJLJ-L|-|7FL7L7J|F7|||L-7LJLJF7L7LJFJF7L-J7F7FLJLJLJ|F-JLJ||L7||LJ||L7J-LJJJ
F--JLJ|||L-7|LJL7||FJFJL7FL7||LJLJL----J|||F---JF-7F-7F-JLJLJL7FJJJJF-|..-F-L7L-J|||||F-JF7F7|L7L7|L7|L--7FJL------7|L-7F-JL7|||F-JL-J-||.||
L7F7F7LJL--JL7F7|LJ|FJF-JF-J|L----------J||L---7|FJ|FJL7F--7F-J7..|.L-FJ77.F||F7FJLJLJL--J||LJ7L7L7.LJFF7LJF7F7F---JL-7|L7F-JLJ|L-----7FJFL|
L||LJL7F----7|||L-7||FJF7L-7|F7F---------J|F--7LJL-JL7-||F7LJJ7|FF|7LFJL|-.F-LJ||F-7F7F---JL7F7FL7L----JL--JLJLJ|F7F7L|L7||F7F-JF7F---J7-7L-
.LJJL|LJF7F7|LJL--JLJL-JL--J|||L-----7F7F-JL-7L------JFJLJL-77F7LF7|7LJF||FL7L|LJL7|||L-----J||F-JF--7F-----7F7F-JLJL7L-J|LJ|L--J|L-7F7J7F7|
FL|JFF--J||LJF---7F7F7F7F7F7|||F-----J||L-7F-JFF-----7|F-7F-JFJ|FJL-77|7L-.LF.F---J|||F7F7F-7||L--JF7LJF7F-7LJLJF---7|F-7|F-JF7F7L-7LJ|F7.L7
F7|F-L7F7LJF7|F--J|||||||LJ|LJLJF7F---JL--JL7F7|F----J|L7||F7|FJ|F7FJ-L77.7J|FL---7LJLJLJLJFJ||F---JL--J|L7L7F-7L--7|||FJLJF-J|||F7|F-J||7-J
LJ.|-FLJ|F7|LJL7F-JLJLJ||F-JF7F7|||F7F7F7F-7LJLJL-7F7FJ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||L7L--7F7FJ||L-7L7FJL7L-7F-7|||||FJ|-LJLJLJ|LJL-------J|L7|L7|FJL7F7FJ|L7||F7LJL-J-7.7
F7F-L77||F7|FJ|LJL-7|L7F--7F7|L-JLJL------7F-J||L7L-7|L7L-7FJ|LJ7||-FJFJ|F-JF7||LLJLJLJL-JF----7FJF7F----7F--JFJ|FJ||F7LJ||7L-J|LJL---7|-L7|
LFL.LF--J|||L7L-7F-JL7LJF-J||L------7F7F--JL--J|FJFFJL7L7FJ|FJF--JL7L7L7||F7||LJF----7F7F7L---7LJFJLJF7F-J|F--J7LJ-LJ|L7F|L--7FJF----7L7.-J|
F7LF-L-7FJ|L7L--JL7F7|F-JF-JL7F7F7F7LJLJ.F7F--7LJF-JF7|LLJFLJ-L---7|FL7LJLJ||L-7L-7F-J||||F-7FL--JF--J|L--JL7F7F-7.F-JFJFJF-7|L7L---7L-J-JJ|
J|7|FL.LJ.L7|F----J|LJL-7|F--J|||LJL--7F7|||F-JF7L--J|L--7F7F7F---JL7LL--7FJL7FJF7||F-J|||L7L-----JF-7L-----J|||FJFJF7L7L-J-LJFJF7F7L--77-.L
||FJJF-|-JJLJL-----JF--7||L-7FJ||F---7LJ||||L--JL7-F7L---J||||L----7L7|F7||F7|L7||||L-7LJL7L7F--7F7|FJF-----7|LJL7|FJL-J-F-7F7L7||||F7FJJJ|.
FL--77L|-7.|J|FLF--7L-7|LJF-J||LJL--7|F-J|||F----JFJ|F7F7L|LJL7.F7FL7|FJ||||||FJ||||F7L-7FJ-LJF7LJLJL7|F----J|F--J||F-7F7L7LJ|JLJLJ||||.J7|7
7.|LJJF|7FF7--F-JF7||FJL-7L-7|F-7F7FJLJF-JLJL-7F-7|FJ|||L7|F--JFJL--J|L7||||||L-JLJ|||F-JL7.F-JL-7-F-J|L-7F--JL7F-JLJFJ|L-JF-JF---7||||J.-77
|-|J7.FJLL|L7.L--J||FJF7FJF7LJL7LJ|L---JF7F---J|FJ|L7|||FJ||F-7L--7F7L7|LJ||LJF----J||L7F7L7L7F-7L7L7FJF7LJF7F7LJF---JL|F--JF-JF--JLJLJFFJL7
7JFJ|F7|FLL7|F--77||L-J||J|L---JF7L-----J|L--7FJL7L7LJLJL-JLJFJF-7LJL7LJF-JL-7L7F-7FJ|LLJ|FJFJ|LL7L7LJFJL-7|||L7FJFF7JFJL---JF7L7.L|JJF--.-J
J|L7|LJ7||F|LJF7L-JL---JL7L-----JL------7L---JL7FJFJF----7F-7L7L7|F-7L7FJ|F-7L7||FJL7|F7FJ|-L-JF7L7L--JF-7LJLJFJL--JL7L7F----J|FJ-LLJFL-|-LJ
LF7--L-F|7FL-7|L--------7L--------------JF---7FJL7|FJF7F7LJ7L-JFJ|L7|7|L-7L7L-J||L7FJLJ|L7L-7F-JL7L----JFL7F-7L------JFJL----7LJ.F7J-JFF--7.
|L|.LLFJL7J-L||F--------JF--7F7F-7F-7F7F7L7F-JL-7LJL7|||L-7F7F7L7|FJL-JF-J7L--7LJFJL--7L-JF-JL7F7|LF7FF7F-J|FJ.F7LF---JF-----JF7-|J7J.-FJFJ.
L--J.|L-7|LLFJ||F--------JF-J|LJFJ|FJ|LJL-JL7F--JF--J|||F-J|LJ|FJ|L--7FJF7F7F7|F-JF7F7L--7|F-7LJ||FJL-J|L--JL7FJL-JF7F7L--7F7FJL77.|FJJLL-.F
.F7JF|.L7F-.L7|||F---7F-7-L--JF-JFJL-JF---7FJL--7L-7FJ||L7.L-7|L7|.F-JL-J||LJ|||F7|LJL7F-JLJFJJFJLJF7F7L--7F7||F7F7|LJ|F7FJ|||F-J|L-F7|LJ-L7
.||JL.-JFFJ7LLJLJL--7|L7|F7F-7L-7|F--7L--7LJJF--JF-J|FJ|FJF7FJL7|L7L-7F-7||F7LJ|||L7F-JL-7F-J.FJF-7|LJ|F-7LJLJ||LJ|L-7|||L-JLJL7F--LJJ-F-7-|
-|JFJFJFF7JFFF------JL-JLJ|L7|F7LJL-7|F-7L7F7L7F7L-7|L7|L7||L7FJL7L7FJL7LJLJL7FJ|L7|L7F7F||-F7L-JFJL7FJ|LL----JL7FL7FJ|||F7F7F7L77.F|7-LJL.|
|J|L7|LF||7.FL7F----7F-7F7L-JLJL-7F-JLJFJFJ||-LJ|F-J|FJL7|||FJ|F7|FJL-7|F7F7F||FJFJ|FJ||FJL-JL--7L--JL-JF----7F7L-7|L7LJLJLJLJL-J7F|J|7J7-F|
L7-|F7|FJ|77LL||F--7LJ7|||F-7F--7|L---7L-JF||F7FJL7|||J||||||FJ|||L7.FJLJ|||FJ||FJFJL7|LJF------JF77F7F7L---7||L--JL-JF---------7|F7FF7-7-LF
||FF7F7L7L7|F|LJL-7L---J|||FJ|F-JL----JF7F7|LJ|L-7L-JL7FJLJ||L-J|L7L7|F--J|||FJ|L7L7FJL-7L7F7F7F7||FJLJL7F--J|L7F77F--JF7F7F7F--JFJL-J|7L-LL
FF-JLJL7L7|F77LF7FJF----JLJL-JL--7F77F7||||L7FJF-JF---JL-7FJL7F-JFL7||L--7|||||L7|L||F7J|FJ|LJ|||||L---7|L--7L7LJ|FJF7FJ||||LJF--JF--7|JFFLL
LL-7F-7L7|LJ|F7||L-JF-----7F7F7F7LJL7|||||L-JL7L-7|F7F--7|L7FJL7F7FJ||F--J|LJ|F-JL7||||FJL7L-7||||L7F7FJL---JL|F7LJFJ|L7|||L--JF7FJJLLJ-LL7.
|.L||-L7LJF-J||||F-7L----7||LJLJL---J|||||F---JF7||||L-7||FJL7FJ|||FJ||-F7L7FJL-7FJ||||L7FJF7|||||FJ||L-----7FJ||F7L7L-JLJL-7F7|LJJ.LLJ7LLLF
7-J||.F|F7L-7||||L7|F7FF7||L--7F7F7F7|LJ||L7F-7|||LJ|F-J|||F7||FJLJ|FJL7|L-J|F-7|L-J|||FJ|FJ||||||L7||F7F---JL-JLJL-JJF7LF7F|||L7|LL7FF-7|F|
LL-LJ-FJ||F7LJLJL-JLJL-JLJL---J|LJ|||L7FJ|FJL7||||F-JL7FJ|LJ|||L-7L||F-JL7F-JL7|L-7J||||FJL7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|FJ|L7LJ.F--JJL77L|-J|-FJ7|L77-F|7L-JJF|FL-LL7|JFF77FJJL--7-L-L-L.FLFJ|F.|.FL|.J.
|.L77.L-7|||F|J.7-7F7||F-.LFJ7|L|J.LL7L7|-FLJJF-JLL.-777|FFLJL|FJ-LF-LL|.FLJ-|LFF7|.-J.7J-LJ|.7FL-JLJ-L|7JLFJ.|7L77||JFL-.|7.LJF7---7-FJ|FJ7
F|.LJ.|LFFJJ77-JJ-LL-JLF.FJ.LLF-JF77JL7-L-7JJ-JLLFJ.|.L--JJJ-LLJ.L-JL--L-JJJ-J--L-F.|L--7J.7J-LL...|J-L---L|J|JJ.LF-|.F-L.-J.L.L|.L.L-|.F|.J

45
2023/day2/day2.py Normal file
View File

@ -0,0 +1,45 @@
from math import prod
def part1(lines):
result = set()
for index, line in enumerate(lines):
game_id = index + 1
_, line = line.split(": ")
result.add(int(game_id))
hands = line.rstrip().split("; ")
for hand in hands:
colors = {"red": 0, "green": 0, "blue": 0}
cubes = hand.split(", ")
for cube in cubes:
n, color = cube.split()
colors[color] = int(n)
if colors["red"] > 12 or colors["green"] > 13 or colors["blue"] > 14:
# impossible configuration, remove this game_id from the result (if present)
result.discard(int(game_id))
print(f"Part 1: {sum(result)}")
def part2(lines):
result = []
for line in lines:
colors = {"red": 0, "green": 0, "blue": 0}
_, line = line.split(": ")
hands = line.rstrip().split("; ")
for hand in hands:
cubes = hand.split(", ")
for cube in cubes:
n, color = cube.split()
colors[color] = max(colors[color], int(n))
result.append(prod(colors.values()))
print(f"Part 2: {sum(result)}")
if __name__ == "__main__":
import sys
infile = sys.argv[1]
with open(infile) as f:
lines = f.readlines()
part1(lines)
part2(lines)

5
2023/day2/example.txt Normal file
View File

@ -0,0 +1,5 @@
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green

100
2023/day2/input.txt Normal file
View File

@ -0,0 +1,100 @@
Game 1: 2 blue, 4 green; 7 blue, 1 red, 14 green; 5 blue, 13 green, 1 red; 1 red, 7 blue, 11 green
Game 2: 6 blue, 3 green; 4 red, 1 green, 7 blue; 2 green
Game 3: 4 blue, 3 red; 2 blue, 4 red, 7 green; 1 blue, 6 red, 7 green; 5 green, 10 blue; 9 green, 1 blue, 6 red; 8 blue, 1 red, 12 green
Game 4: 15 blue, 4 green, 5 red; 2 red, 2 green, 5 blue; 3 green, 13 blue; 17 blue, 1 green, 5 red
Game 5: 11 green, 4 red, 3 blue; 8 blue, 6 green; 8 green, 2 red, 9 blue; 4 red, 16 blue; 8 blue, 10 red, 6 green; 9 blue, 3 red, 10 green
Game 6: 4 green, 9 red, 2 blue; 7 red, 2 green, 15 blue; 13 red, 2 green, 6 blue; 5 green, 7 blue, 6 red; 19 red, 15 blue, 4 green
Game 7: 12 blue, 5 red; 5 green, 6 blue; 5 red, 15 blue; 5 blue, 5 red, 5 green; 1 green, 11 blue, 2 red
Game 8: 6 red, 11 green; 5 red, 2 blue, 7 green; 7 red, 6 green
Game 9: 5 red, 1 blue, 11 green; 4 green, 1 blue; 8 green, 2 red; 1 green, 2 red, 2 blue; 3 green, 2 red
Game 10: 7 blue, 4 red, 11 green; 13 green, 1 red, 1 blue; 7 blue, 6 green
Game 11: 4 blue, 7 red, 2 green; 1 green, 14 red, 3 blue; 2 green, 5 red, 3 blue
Game 12: 6 green, 6 blue, 1 red; 1 green, 3 red, 2 blue; 2 blue, 6 red, 7 green
Game 13: 6 red, 10 green, 13 blue; 3 red, 12 green, 9 blue; 11 blue, 1 green; 4 red, 3 blue, 13 green; 12 green, 10 blue, 6 red; 13 blue, 3 green, 3 red
Game 14: 8 green, 1 blue, 17 red; 7 green, 11 blue, 19 red; 19 red, 9 blue, 2 green; 8 green, 20 red, 12 blue; 16 red, 3 green, 11 blue
Game 15: 3 red, 1 green, 5 blue; 9 blue, 4 green; 6 blue, 5 green, 9 red
Game 16: 13 blue, 1 red; 2 blue, 2 green; 1 green; 10 blue, 8 red; 4 red, 3 green, 9 blue
Game 17: 10 blue, 2 red; 3 green, 4 red; 6 blue, 1 red, 6 green; 5 green, 7 blue, 5 red
Game 18: 3 red, 1 green; 2 red, 5 blue; 5 blue, 2 red
Game 19: 7 green, 4 blue, 1 red; 1 green, 4 blue, 4 red; 6 blue, 8 green; 4 green, 2 blue, 1 red; 1 red, 1 blue, 2 green
Game 20: 13 green, 1 red, 1 blue; 12 green, 1 blue; 5 green, 1 blue, 2 red; 16 green, 3 red; 2 red, 9 green
Game 21: 8 red, 2 green, 2 blue; 5 red, 3 blue; 2 blue, 5 red, 2 green; 7 blue
Game 22: 9 red, 12 blue, 7 green; 7 red, 13 blue, 4 green; 9 blue, 13 red, 1 green; 3 blue, 4 red, 5 green
Game 23: 7 green, 12 red; 6 red, 7 green, 4 blue; 1 blue, 11 red, 5 green; 4 green, 2 blue, 6 red; 12 green, 6 red, 3 blue
Game 24: 11 red, 4 blue; 9 blue, 6 green, 17 red; 8 green, 2 red; 16 blue, 6 red, 2 green
Game 25: 7 red, 4 blue; 7 blue, 4 green; 10 blue, 4 red, 2 green; 6 green, 4 blue, 1 red; 10 blue, 2 red, 4 green
Game 26: 7 green, 8 red, 6 blue; 5 red, 3 green, 2 blue; 13 blue, 6 green, 5 red; 10 blue, 4 red, 8 green; 2 red, 2 blue, 1 green; 8 blue, 1 green, 4 red
Game 27: 7 green, 3 blue, 13 red; 1 green, 17 red, 1 blue; 16 red, 3 blue, 3 green; 5 green, 3 red, 5 blue; 13 red, 4 green, 8 blue; 6 blue, 2 green, 15 red
Game 28: 8 blue, 5 red, 18 green; 1 green, 6 red; 7 blue, 18 green, 5 red; 16 green, 3 red, 7 blue; 6 blue, 18 green; 8 blue, 8 green, 7 red
Game 29: 4 blue, 1 red; 6 blue, 1 red; 17 blue, 1 green
Game 30: 1 red, 2 green, 5 blue; 2 blue, 7 green, 6 red; 11 blue, 4 red, 2 green; 5 green, 6 blue, 4 red; 5 red, 8 blue, 7 green
Game 31: 10 green, 9 blue; 5 green, 9 blue, 1 red; 1 red, 8 blue
Game 32: 3 red, 5 green; 5 red, 5 blue, 14 green; 2 red, 2 green; 11 green, 3 red, 5 blue
Game 33: 7 blue, 10 green, 8 red; 18 blue, 15 green, 4 red; 6 red, 1 green; 18 blue, 8 red, 11 green
Game 34: 3 green; 2 red, 5 green; 5 blue, 3 green; 3 blue, 5 green, 1 red
Game 35: 1 blue, 5 green, 6 red; 3 green, 2 red, 3 blue; 4 red, 9 blue, 3 green; 1 green, 12 blue, 1 red
Game 36: 14 green, 3 blue, 16 red; 1 green, 2 red, 4 blue; 4 blue, 9 green, 18 red; 4 blue, 4 green, 14 red; 4 blue, 11 green
Game 37: 7 green, 2 blue, 3 red; 8 green, 9 red, 2 blue; 4 blue, 15 green, 18 red
Game 38: 11 red, 1 blue, 6 green; 6 green, 2 blue, 1 red; 6 blue, 17 red, 2 green; 17 red, 9 blue, 3 green; 7 red, 7 blue, 3 green; 3 green, 7 red, 7 blue
Game 39: 1 blue, 2 green; 1 blue, 2 green, 7 red; 1 blue, 4 red, 2 green; 1 blue, 12 red
Game 40: 1 blue, 4 red, 15 green; 12 green, 1 blue, 15 red; 15 red, 8 green
Game 41: 5 blue, 5 green, 1 red; 9 red, 8 green, 9 blue; 10 red, 10 blue, 4 green; 3 blue, 17 red, 3 green; 3 blue, 4 red, 2 green
Game 42: 2 blue, 10 red, 17 green; 6 red, 10 green, 10 blue; 3 blue, 6 green, 8 red; 9 green, 2 blue, 8 red; 13 green, 5 blue; 4 red, 18 green, 11 blue
Game 43: 8 red, 3 blue, 6 green; 2 red, 8 green, 10 blue; 5 blue, 9 red, 9 green; 1 green, 15 red, 8 blue
Game 44: 11 green, 19 red, 14 blue; 1 red, 19 green, 9 blue; 7 green, 8 red, 10 blue; 14 green, 8 blue, 15 red; 7 green, 3 red, 2 blue
Game 45: 4 green, 9 blue, 4 red; 7 blue, 13 green, 2 red; 12 green, 10 blue, 10 red
Game 46: 10 red, 2 green, 1 blue; 10 red, 10 green, 1 blue; 1 blue, 13 green; 1 blue, 2 green, 10 red; 1 blue, 7 red, 11 green; 10 red, 5 green
Game 47: 3 blue, 2 green, 12 red; 5 blue, 7 red; 5 green, 14 red; 12 red, 7 green, 5 blue
Game 48: 5 red, 1 blue, 3 green; 7 red, 8 green, 4 blue; 4 blue, 5 green, 17 red; 1 blue, 12 red
Game 49: 2 green, 7 red, 1 blue; 11 green, 5 red; 4 red, 1 blue, 1 green; 11 green, 1 blue, 7 red
Game 50: 10 red, 3 blue, 6 green; 1 blue, 5 red, 3 green; 6 blue, 11 red, 12 green; 10 green
Game 51: 18 blue, 1 green, 1 red; 15 blue; 13 blue, 11 green, 4 red; 8 red, 1 green, 18 blue; 10 green, 7 blue, 8 red
Game 52: 13 green, 15 blue; 6 blue, 4 red, 8 green; 6 red, 13 green, 11 blue; 2 red, 7 green, 13 blue; 12 green, 2 blue, 3 red; 6 red, 11 green, 1 blue
Game 53: 2 red, 2 green; 3 green, 1 blue, 1 red; 1 blue, 4 green, 7 red; 4 red, 1 blue; 4 red, 5 green, 2 blue
Game 54: 8 blue, 2 red, 5 green; 6 green, 2 blue, 3 red; 1 blue, 8 green, 4 red
Game 55: 6 green, 6 blue, 3 red; 13 green, 1 red; 2 blue, 1 red, 1 green; 14 green, 1 blue, 1 red; 1 blue, 2 red, 9 green; 9 green, 2 blue, 4 red
Game 56: 4 green, 6 blue, 1 red; 5 red, 3 blue; 6 red, 1 blue; 9 green, 5 blue, 7 red
Game 57: 5 red, 5 green, 8 blue; 11 red, 3 blue, 8 green; 7 green, 9 blue, 11 red; 3 green, 2 blue, 12 red
Game 58: 3 green, 3 red; 4 red, 1 green; 1 red, 6 green; 5 green; 5 red, 1 blue, 3 green; 3 red, 1 blue
Game 59: 2 green, 2 blue; 7 red, 18 green; 2 blue, 7 red, 16 green; 7 red, 10 green
Game 60: 3 blue, 4 red; 4 blue, 3 red, 3 green; 16 green
Game 61: 1 blue, 2 red, 8 green; 9 blue, 4 green, 12 red; 10 green, 2 red; 5 blue, 11 red, 1 green; 10 green, 3 blue, 8 red; 5 red, 2 green
Game 62: 15 red, 10 blue, 7 green; 4 blue, 9 red, 4 green; 4 red, 2 blue, 2 green; 11 green, 2 red; 8 blue, 2 green; 2 green, 8 red, 8 blue
Game 63: 2 green, 3 blue, 1 red; 7 blue, 5 red; 7 blue
Game 64: 3 green, 5 blue, 6 red; 9 green, 4 red; 13 red, 1 blue, 5 green; 4 blue, 13 red, 8 green
Game 65: 7 green, 1 blue; 1 red, 14 blue, 4 green; 8 blue, 6 red; 14 green, 4 red
Game 66: 6 red, 11 green, 7 blue; 1 blue, 6 red; 13 red, 7 blue, 3 green; 8 red, 6 blue, 15 green; 7 green, 6 blue, 4 red; 4 red, 1 blue, 20 green
Game 67: 4 blue, 9 green; 15 red, 16 green, 3 blue; 1 green, 14 red, 3 blue; 3 red, 2 blue, 3 green; 4 green, 3 blue, 12 red
Game 68: 5 green, 3 blue, 2 red; 4 green, 8 blue, 11 red; 6 red, 6 blue, 4 green; 8 red, 5 blue, 7 green; 6 blue, 6 green, 11 red; 2 blue, 3 green, 3 red
Game 69: 15 blue, 16 green, 5 red; 10 blue, 3 red, 13 green; 4 red, 5 blue, 2 green; 1 red; 11 green, 5 red, 15 blue
Game 70: 8 red, 9 blue, 12 green; 3 red, 2 blue, 14 green; 10 blue, 1 red, 18 green; 1 blue, 7 red, 16 green; 3 green, 4 red, 16 blue; 10 green, 6 red
Game 71: 12 blue, 7 red, 16 green; 2 red, 9 blue, 15 green; 1 red, 11 blue, 11 green; 15 red, 16 blue, 2 green
Game 72: 1 blue, 11 red, 6 green; 1 red, 2 blue, 5 green; 4 green, 2 red; 2 green, 12 red
Game 73: 1 blue, 1 red; 2 red, 4 blue, 2 green; 1 blue, 2 green, 10 red; 8 red
Game 74: 12 red, 1 green, 4 blue; 1 red, 5 blue, 1 green; 11 green, 16 red, 7 blue; 7 red, 1 blue, 1 green; 12 red, 11 green, 12 blue; 11 green, 6 red
Game 75: 12 green, 8 red, 3 blue; 7 red, 10 green; 1 green, 7 blue, 1 red
Game 76: 4 green, 1 red, 3 blue; 7 blue, 3 green, 3 red; 4 blue, 2 red, 3 green; 4 blue, 1 green
Game 77: 2 green, 12 blue, 10 red; 5 blue, 7 red; 2 red, 6 green; 1 blue, 2 red, 6 green
Game 78: 2 green, 4 blue, 4 red; 8 green, 10 red, 10 blue; 5 green, 8 blue, 10 red; 6 green, 2 red
Game 79: 3 green, 2 blue, 11 red; 8 red, 11 green, 1 blue; 1 blue, 16 red; 5 red, 7 green, 16 blue; 12 red, 7 green, 9 blue; 4 red, 20 blue, 12 green
Game 80: 3 red, 5 green; 2 blue, 4 green; 2 red, 12 green, 4 blue; 10 green, 1 blue, 1 red; 4 blue, 3 red
Game 81: 1 blue, 1 green, 1 red; 5 green, 3 red, 1 blue; 1 blue, 6 green; 1 green; 1 red, 5 green, 2 blue; 1 blue, 1 red, 3 green
Game 82: 7 green, 10 blue, 3 red; 10 green, 12 red, 12 blue; 18 red, 8 green, 14 blue; 3 red, 3 green, 10 blue; 3 red, 1 blue, 5 green; 1 green, 8 blue
Game 83: 9 red, 3 blue; 14 blue, 8 red, 3 green; 14 blue, 5 green, 4 red
Game 84: 2 blue, 3 red, 6 green; 11 green, 2 red, 1 blue; 17 green, 3 blue, 3 red; 1 red, 1 blue; 1 red, 2 blue, 19 green
Game 85: 3 green, 2 blue, 3 red; 4 red, 5 blue, 8 green; 15 green, 1 red, 9 blue; 12 green, 3 blue, 2 red
Game 86: 15 green, 7 red, 10 blue; 2 blue, 2 red, 1 green; 4 red, 1 green, 9 blue; 7 red, 14 blue, 5 green
Game 87: 1 green, 3 blue, 1 red; 2 blue, 1 green; 1 blue, 2 green, 1 red
Game 88: 2 green, 6 blue, 5 red; 5 blue, 2 red; 3 red, 13 blue; 9 blue, 10 red, 1 green
Game 89: 6 green, 10 red, 2 blue; 7 red, 1 blue, 8 green; 4 blue, 3 red, 5 green; 4 green, 4 blue, 10 red
Game 90: 8 red, 7 blue; 4 green, 3 red, 1 blue; 5 blue, 2 green
Game 91: 15 green, 14 red; 12 red, 16 green, 2 blue; 8 red, 10 green; 1 green, 6 red; 8 green, 12 red
Game 92: 4 blue, 4 green, 9 red; 1 blue, 17 green; 1 green; 15 green, 3 blue, 12 red; 11 red, 1 blue, 7 green; 7 blue, 13 red, 8 green
Game 93: 10 blue, 12 red; 10 blue, 11 green, 8 red; 1 blue, 11 green, 7 red; 10 blue, 15 red, 5 green; 11 red, 8 green, 9 blue; 10 green, 3 blue
Game 94: 1 blue, 2 red; 4 red, 1 green, 5 blue; 3 red, 2 green; 2 green, 2 blue; 1 red, 5 blue, 1 green; 4 blue, 1 red, 2 green
Game 95: 1 red, 1 blue, 3 green; 2 green, 6 blue; 1 green, 13 blue, 1 red; 3 green, 15 blue
Game 96: 16 blue, 7 green, 5 red; 5 green, 5 blue, 6 red; 3 green, 17 blue, 10 red; 13 blue, 2 red, 1 green
Game 97: 12 red; 1 blue, 6 red, 1 green; 9 red, 2 blue, 1 green; 1 green, 2 blue, 1 red; 15 red, 1 blue; 1 blue
Game 98: 11 red, 6 blue, 13 green; 4 blue, 2 red, 12 green; 2 blue, 8 green, 10 red
Game 99: 2 red, 1 blue; 4 green; 7 green, 1 blue, 1 red; 5 green, 2 red; 1 blue, 2 red, 9 green; 2 green, 3 red
Game 100: 7 red, 11 blue; 10 red, 5 blue, 1 green; 7 red, 1 green, 13 blue; 9 red; 9 red, 19 blue; 9 red, 9 blue

116
2023/day3/day3.py Normal file
View File

@ -0,0 +1,116 @@
from typing import Tuple, List, Set
from dataclasses import dataclass
@dataclass(frozen=True)
class Item:
pos: Tuple[int, int]
symbol: str
def browse_schema(schema):
total_parts = 0
buf = []
max_row, max_col = len(schema), len(schema[0])
symbols: List[Tuple[Item, Set[Item]]] = []
numbers: List[Item] = []
for y in range(max_row):
for x in range(max_col):
item = schema[y][x]
if item.isnumeric():
# continue parsing full number
buf.append(item)
else:
neighbors = get_neighbors_of((x, y), schema)
symbols.append((Item((x, y), item), set(neighbors)))
if buf and not item.isnumeric():
# end of a number, do the engine part check
number = "".join(buf)
neighbors = get_neighbors((x, y), len(buf), schema)
start_pos = (x-len(number), y)
symbols.append((Item((x, y), number), get_neighbors_of((x, y), schema)))
numbers.append(Item(start_pos, number))
if is_engine_part(neighbors):
total_parts += int(number)
buf.clear() # reached end of a number, clear buffer
print(f"Part 1, sum of the parts numbers = {total_parts}")
part2(symbols, numbers)
def part2(symbols, numbers):
total_gears = 0
stars = [(s, neighbors) for s, neighbors in symbols if s.symbol == "*"]
for _, neighbors in stars:
corresponding_numbers = set()
digits = [n for n in neighbors if n.symbol.isdigit()]
for digit in digits:
# find full number (number.start_pos < digit.pos < number.end_pos)
for number in numbers:
if number.pos[1] - 1 <= digit.pos[1] <= number.pos[1] + 1 and number.pos[0] <= digit.pos[0] <= number.pos[0]+len(number.symbol):
corresponding_numbers.add(number.symbol)
if len(corresponding_numbers) == 2:
a, b = corresponding_numbers
total_gears += int(a) * int(b)
#print(f"star: {star.pos} {corresponding_numbers}")
print(f"Part 2, sum of gear ratios = {total_gears}")
def is_engine_part(neighbors: List[Item]) -> bool:
# get list of symbols (not '.', \n or a number)
symbols = filter(lambda x: not x.symbol.isnumeric() and not x.symbol in (".", "\n"), neighbors)
return next(symbols, None) is not None
def get_neighbors(pos: Tuple[int, int], length: int, schema: List[List[str]]) -> List[Item]:
x, y = pos
start_x = x - length
neighbors = [get_neighbors_of((x, y), schema) for x in range(start_x, x)]
neighbors = [item for sublist in neighbors for item in sublist] # flatten list of list
return neighbors
def get_neighbors_of(pos: Tuple[int, int], schema: List[List[str]]) -> List[Item]:
max_row, max_col = len(schema), len(schema[0])
x, y = pos
neighbors: List[Item] = []
# top
if y-1 >= 0:
neighbors.append(Item((x, y-1), schema[y-1][x]))
# bottom:
if y+1 < max_row:
neighbors.append(Item((x, y+1), schema[y+1][x]))
# left
if x-1 >= 0:
neighbors.append(Item((x-1, y), schema[y][x-1]))
# right
if x+1 < max_col:
neighbors.append(Item((x+1, y), schema[y][x+1]))
# top-left
if y-1 >= 0 and x-1 >= 0:
neighbors.append(Item((x-1, y-1), schema[y-1][x-1]))
# top-right
if y-1 >= 0 and x+1 < max_col:
neighbors.append(Item((x+1, y-1), schema[y-1][x+1]))
# bottom-left
if y+1 < max_row and x-1 >= 0:
neighbors.append(Item((x-1, y+1), schema[y+1][x-1]))
# bottom-right
if y+1 < max_row and x+1 < max_col:
neighbors.append(Item((x+1, y+1), schema[y+1][x+1]))
return neighbors
if __name__ == "__main__":
import sys
infile = sys.argv[1]
with open(infile) as f:
schema = [[c for c in line] for line in f.readlines()]
browse_schema(schema)

10
2023/day3/example.txt Normal file
View File

@ -0,0 +1,10 @@
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..

140
2023/day3/input.txt Normal file
View File

@ -0,0 +1,140 @@
................................................965..583........389.................307.................512......................395.....387
........................#....374...382....250...*..........737*....*896.395...........*....................$.........................#......
..494.........532-...474......*.......#....*...................522......*..........%...........................%...+................269.....
.....*..#................506..143........375......77.....155...........400.518...64....773...718..797........694....972.603.....*...........
....479.795...............*..........800...........*.$.......264*636.......@..............&..*...*.......499...............*...5.20.........
515...................512.484...*....*...=......390...427...................................644.804.........*...@......-..532............28.
..........607...........&.....105...906...910.......@............979.969...........-..=.............462....414..101.361..........283$.......
..........*...781................................925..............=...*..........434..899....368.......*..................33...........*....
.......850.......=........559..249...................732.....430....132........................*.....................817-.=.........613.381.
....................157....*...&....978..............$......-...................*626.-.......297.............750............................
..........312...........606........*....136.............593.............638...........177.....................*....672.772....998.491=......
....450......*..156...............760.....=.......227......%..794...157........................919.......&....607..*...*....................
.......*...108...............968...................-..........*........*....80....669..........$..........854......6..572.....743....&......
......759.......649.............*832.......351.........433...418...997........*.....*.......46....187...........................*.....759...
............344.&..........&.........573......@...556.............*..........884...748..317../....+..........................236............
......#..................627.....334*..............*...933........774.534................*.......................................905........
...642.....105..........................100.......372.....$...........*..........*982..527....$837..406.948....*127......455........*.......
...........*.......383............293......*750.&.....774....630......51......826...........................361.........=.......993..822....
....*..576.346.876....@..907.953..@..............982..*.........+.................913*782...*115..565..526........779.......971.............
..20...*..........*.......*....%.............46-.......8................232................5.....................*....@........$........903.
.....$.............483.....420......115....$......287...............................873.......................131....818...............*....
......161....*362.....................-.266.........*......524...157.79....@.396.......*............848@.293............................988.
..........412...................................97..721.....#.......*...638../......305.......................+.................630*818.....
.194..................556....297.253...........*.........................................................@.....186..213..819................
................154.....$.......*....454......46.795.686.......=..204.........$...=............771.....171..........#................-456...
..................*.....................*........*.....-.....457.....*....638.466..579......................#..........109.....727..........
..................177......785.769...827..........500....168........479....*...........=....255..............74...........*845....*..375....
................-.........*.....*..........................*..............360..681......700.......................853...........781.....*...
..846..91......966........511.435.............245.......617.............*.....*....................................$.....810...........836..
.....*.................................%86......*..............121.......721..751......386*.......476*60...%195......801...%.......345......
..763........+....428@....-40.391...............970......803......=...*....................351...................185....*.....118...*.......
......#862..345....................629......45............+.........897.....802........488..........................*.....274.../..676../...
..945.............299.......$......*..........................183..................190...&........763.....484..364...235....%..........564..
...*..............*........404...527....&....137.814.......57......890.......407..*.........................*...*..............711&.........
....424..........66..................966.......*.@.........*......*......806...+........................98....762......$...663........605...
....................404......................614...489..........150....-..*........367...................*.........909.863...#........*.....
.............%759...*...+....916.498...&.............*.551..........191..606...............797........391.......................=568...898..
........2*........632.987......*....*.155.$2......412........................730...401.....#....438..........412*199........................
..........729...............89.753...........364.........687....................*.....*86........*.............................%.....657....
...............182./687.214.*.......................141..*....................$..620.......706%.368.....*.............758....694.971....*774
.....617........*.........*..335....89....583.........*..378...945.....272...97......................264.817.............*........*..+......
.../....*506.779...31..168..................*......732............*.../.....................957......................104.156...160..219.$...
....789.............*....../........671...45....................982.&.......%.......$.......*...264.............386..*..................588.
..................575.......192...../..................51*952.......264....655..=17..113...998.............932.......638..........24*.......
...........@............@.......................................#................................650..........*734...........652.....278....
........903.....=....805......944..............................377........477........&73.610.......+...640..........852.........*893........
.............882.........@768..%..103........465......636.............................................*..........29...*.661.295......61.....
.....................467.........$......292...*.........&..........640.......926.........201..173...38...........*..805.*.............*.....
......296....317.......*.....995............$.889..890....665.......*....47..@....701&..$.......$......739....388.......257............790..
..989..*.....&....980..168.....*...........17........*.....*.......894..*.........................*200.*....................................
..../...561....................198.34*811......726.122...+.63..437......787.........668........355.......641....@...........................
.................................................*.....112.....*................798*.......420..........*........244..758..............771..
...&.......573..............515..................252........511......................396...%.......805.736............/..........546........
342.......*....................*.44.................................*....399.188.....*........................254........13*................
........%..720.............695......875*362.........@...649*919..585.477...*..*...245....450....-............*.......743....645.&......796..
.....556.........460.........$..............919&....679...................935.............*...273.........396.........*..........659........
...&.............-.........%.....542*...............................................255.368........387..............435..612*...............
980................484...964.........736........%327.......210..+......962.610...............396.............492.............259.970*.......
....-.......850...............645...........56.........275*.....928.....*.....-..81....133........=..889....*........................382....
..382................419*.......*......@......*.............439........953.......*....*..........341..*..322.....226.342.......*598.........
...............636=......662.204........620..13..............*...171..............19..396............27.............*.......539........278..
.........131.........133........................282...900...48...*........678.379................+.....................798.......131....@...
.....684*.....944.......*...@.....991...................*.........90.......*..+...818.783....19..492...501*842..........*..480*..@..........
..........515..........855...646.+.......451.../533.....115...../.........841.................#........................272...........154....
....107=..*................................&..........=.......631.....837.............52..............485......193.%.......983......*.......
..........587............405*329....957............451............60.*............370......................222..*...461....@.......894..534.
..705...............131...............$...640...............127*8.+..859.145.......%...440...%..................875.........................
...*..714....783..........@986......&........*.........................................*...199.451....=.....................87.......190....
.349..*......%.....429...............602..562..519................=......112*....669....8..............105...........#......../..387........
.....792.............*.......854..............*.................93...........808...$...........%673........802$.......586..........*........
.............-.......282.....+...-756.......291.........&...............................209.......................534.......573.831....*955.
..........195............401..........617.............676.........................................961..716...................*..............
.....762................*.......*864.........%694..............249./....-....572.327..........784..*..........@.534........883.........724..
......%..............#...109.304....................................56...240.*...*......657...%....837..792.292...=...............*.........
...................974..............89..............629....#460..............330.....*....*..............*................620#...887........
...877*793..................680+...*........$662...*..............................365.898..773.........726...........607.............579....
.................................316.404...........716.....*775.....%.........................................573.67.#...399.953......*.....
.......931...................91@.....*.........680.....395.......760......165....302............960....*.........*.......*.........697......
.......*......962..997/.............363.....*....*....@....126........566*........$..4..739*..........545.953.............955...............
....548.........%................./.....*.734.....653.....*...........................#.....489..............*....336.763...................
........@.185........88.........483...208......-..........419..331......460.../46.406.......................582.-....*..........408.........
.....106../......654..*.....................423.......109.........*................*............269..%21.........632.....324+......*...*....
................%....265......906....926.............*............475..60........188...............*.............................994..905...
........=781....................*....*.....938....401.......857.......*.......................802.300..625.....207..%.......................
..................355..894...410....402...*...................*.....467................660*..*.........%.......*....721.....&....764........
...........554...*.......*..............277..-.......648.......491..........................968...........24....380......520....*...........
......%....*.....757......788.................851......*...416.....493........635....241.........409.....*..........362......660............
.......23..52..........@............................791.....*......+...=..*.........../...$209...*......282..214...=....370.................
...................328..291.529.........................50.63........412.591..../..............169........................+........+........
..701&....=..198.....*.........*....+...........896......$..../................772......*626........458..578=...............337..95...482...
.......540...&......989....227..736.229.....................52...........241..........95.............*..................599...*......*......
........................................820.397................937...664*...............................820...222.185...*.....47....862..192
...........................$.....484.....*..$.......$601........*...............540.........&.............*..............694................
.....818.630..........15..495...........119...36.........273.....329..=.398....*...........578....220...607..580.......%.......876..........
.....*........=......*...................................*...........30..=......89..........................*.......182....574.$............
...98...127....182.363..921..............................273.........................................@231..926...............=....=18.......
........&.................................183........7@.......................347=.....=......903....................*732..............782..
.............*635............................%.604*.........@.#910.226...............288..........767.............227............753/..*....
770.......661............812...$709..430...........997....556......*.....................@...970...........949..........................775.
............................................984.....................845.......$........861.......297..415.*...............789..*937.........
..541.......614..10.........453.....................67.....................735...../..............*..*.......................*..............
...%.../....*..........468...=........*824.109........*58............318............29.....152..538.488.....423.......19......602...162.....
......279.363.228........*.........221.............&.......*..................................@................*788....*...........*........
706....................114..............&987.873..316...701.871.....846...501......200.603..........876.................929......178........
...*..503.......78.................................................-......*..........*............+.........179......$......................
.850.....$..118...+.............944..........19.............@735..........388..160...365..582....524..........*.......355.....840...........
..............*......*..........=...475+.926*.....433.............../146.......*..............................380.....................614...
...........228....200.695..........................*..391..529..................918...290...340..16*.....482................363.........$...
.......906......................993......=986...874...*...#....+............37...........*....=...........#...................*.....32......
...&......*230..204=........721...*.$...............839.....456..553..601..*...408.....914..................77.................662..*..=554.
...29.......................*...717.248.....358.................@......$...977...*................94.....................*846...............
.............542..546.....52.................*........286........................669......................=...401......61.....709*389.480...
........989......*....253....713.........742..171.........325....976....*...513/....................967.246....*........................*...
...........=....571...*........-..=456.....................*........*..300.......344..........146..............87........................66.
..199*................204..............+.490.......584...427.166...810.....431......+...115....*..........195...........=...................
......247.645....................693.204....-.....*....................310...*..*........*.....772....686*.........=323.194....451......=...
.....................596.304*696.@....................................*....220...351..444..934..................................+........136
..736...............&..................................510..250..638.766..................*....511....195.........#..778..&902....721.......
...........758............*..........=401......210..#.....&.-...*................572...385....*.......%.....200.248.*..............*........
...........*...........991.358.256.........782*......742.........832....*.......=..........799...675*......*.........80.819.902...18........
...........735...*.............*........*.......*242.....414*704.....194..325...........................569..............$...@..............
..................772.......309...+..204.....659.....&.....................*............297*..396*494.......26......................131.....
.....%..+.......................169...................860..333...212*....459.............................../.......392.............@.....103
....628..891....../....519..88............................*..........530......90*....225.418....112....614....274..$......169%.399...481....
850............829..48..%.........931........./388.......270..............@......798......#........@....*........$...............-..*.......
...*876...............*...820.....*............................614*834...745............................575..................-......827.....
......................764....*..432...........516$.133..633..................489$........396.255.............636..413*.811....337.......*682
.667......................639...........199..........*...+......=....*500.........401@......*...........878-..*........../...........419....
....@......28...........................*...#....@..72.......539..708........237.................=............675.851@......................
.......777........406...459$..........993.445.719......./......................+...706........386....%....../..................*96.271......
.311..*.......................&......................317../542....................@.....+.........136......821.543..........947.............
...*..982.....657..70=..948#..159..777../.....757....................816...............887.............325........*....................871..
.804..........=.....................*..284..........255*...............+....48...589*......199................#.68..542......&.&241...*.....
.......10............604.....287...66......507..........917...585............-.......6.327..-......822.....718.....*.......825.......34.....
........*......904$....*..................+......*.............*.....454.820............@.....492.*................887............@.........
.......645.-.........49..............844.........533........958.........*.......32.892..........%.118...+..670*296......%...122..840.230....
....=......176..........................*.=..........................%1.....397*...........820.........407...............21...........*.....
...913...........&............408.....135.300..............775...993.........................@..............%.....272...........*626...101..
..................95..505......*.................581.........+...*...........59*23.......449.......964...657.......*..........75............
.............................87...622..........................822...............................................215.............810........

44
2023/day4/day4.py Normal file
View File

@ -0,0 +1,44 @@
def parse_tickets(lines):
tickets = []
for line in lines:
_, nums = line.rstrip().split(": ")
winning, played = nums.split(" | ")
winning, played = set(winning.split()), set(played.split())
tickets.append((winning, played))
return tickets
def part1(tickets):
total = 0
for ticket in tickets:
winning, played = ticket
num_wins = len(winning.intersection(played))
points = 0 if num_wins == 0 else 2**(num_wins-1)
total += points
print(f"part 1, total={total}")
def part2(tickets):
tickets = [[1, t] for t in tickets]
for index, ticket in enumerate(tickets):
mult = ticket[0]
winning, played = ticket[1]
num_wins = len(winning.intersection(played))
for i in range(index+1, index+1+num_wins):
tickets[i][0] += mult
num_tickets = sum(n for n, _ in tickets)
print(f"part 2, number of tickets: {num_tickets}")
def main(f):
tickets = parse_tickets(f)
part1(tickets)
part2(tickets)
if __name__ == "__main__":
import sys
infile = sys.argv[1]
with open(infile) as f:
main(f)

6
2023/day4/example.txt Normal file
View File

@ -0,0 +1,6 @@
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11

188
2023/day4/input.txt Normal file
View File

@ -0,0 +1,188 @@
Card 1: 95 57 30 62 11 5 9 3 72 87 | 94 72 74 98 23 57 62 14 30 3 73 49 80 96 20 60 17 35 11 63 87 9 6 5 95
Card 2: 65 16 99 4 48 52 84 7 26 12 | 86 7 71 12 52 4 84 15 48 20 16 3 10 87 56 99 26 66 88 65 98 32 14 51 59
Card 3: 19 70 1 34 10 79 23 58 64 68 | 95 14 64 53 19 63 83 46 77 75 3 12 70 65 22 13 66 34 23 89 94 50 69 79 68
Card 4: 27 57 62 6 53 68 97 35 23 8 | 23 2 81 62 19 8 65 27 93 53 57 67 6 91 68 97 16 30 12 96 15 35 25 55 43
Card 5: 49 95 30 21 42 63 92 97 89 93 | 35 34 46 89 93 29 42 21 63 49 77 30 95 27 28 62 72 32 97 54 75 56 4 58 92
Card 6: 7 39 29 54 34 40 63 64 32 23 | 88 4 54 73 32 18 36 31 19 35 61 94 28 40 23 41 96 59 14 48 77 29 39 21 33
Card 7: 20 58 79 66 51 65 72 27 62 67 | 37 7 90 62 3 17 88 58 86 28 55 42 15 20 79 94 38 92 76 41 30 93 25 24 14
Card 8: 3 83 96 15 95 72 63 87 74 78 | 16 74 6 49 15 87 46 3 64 90 82 85 2 78 32 9 97 96 70 95 63 72 54 83 38
Card 9: 40 74 17 75 12 97 71 15 30 83 | 13 21 15 12 8 81 50 7 44 67 6 40 30 76 22 75 42 79 5 97 83 60 71 47 74
Card 10: 47 96 36 45 84 14 65 7 69 38 | 36 38 85 14 87 95 7 24 69 29 68 65 26 94 84 78 83 45 98 9 2 20 93 96 47
Card 11: 22 5 16 86 91 96 27 39 8 30 | 14 98 84 51 11 5 23 36 40 81 82 78 13 2 43 39 42 68 34 71 10 38 61 70 46
Card 12: 57 95 65 48 50 46 69 61 58 70 | 64 69 52 84 93 65 61 37 25 22 31 6 46 83 50 48 75 58 59 98 95 70 19 51 57
Card 13: 67 63 56 28 11 81 43 60 93 57 | 61 67 82 60 7 11 98 78 50 33 84 64 74 63 28 15 56 66 39 57 69 54 65 8 12
Card 14: 30 97 48 84 86 1 59 83 8 44 | 70 94 38 62 71 79 47 99 68 93 67 15 33 57 60 72 50 31 88 20 82 40 18 63 29
Card 15: 7 2 46 28 61 63 17 95 32 47 | 56 97 17 93 36 78 16 25 18 33 61 90 10 55 82 26 2 69 43 22 96 37 64 74 95
Card 16: 45 90 36 48 81 64 68 58 4 66 | 31 36 34 41 46 56 2 74 50 57 93 86 22 60 43 24 12 17 73 79 15 63 82 97 32
Card 17: 1 82 47 86 6 33 52 51 98 91 | 88 98 26 33 82 93 16 45 65 68 47 96 39 83 14 86 61 71 75 90 3 54 59 77 9
Card 18: 43 73 13 32 98 11 15 12 97 99 | 83 15 60 62 95 36 98 16 51 79 20 24 73 46 5 67 12 32 11 84 89 23 93 59 74
Card 19: 54 93 71 65 66 56 26 97 33 24 | 67 24 89 17 99 18 5 54 26 14 57 10 3 33 91 94 16 80 97 49 12 46 19 75 38
Card 20: 65 10 75 93 72 62 29 69 59 66 | 58 55 56 87 66 88 7 34 36 62 4 35 67 90 33 52 99 17 32 68 80 79 40 48 31
Card 21: 93 75 39 12 21 77 99 46 4 24 | 39 19 98 59 43 14 28 9 89 81 1 5 63 87 48 95 41 36 29 27 44 15 50 17 18
Card 22: 78 39 74 11 41 24 9 33 68 45 | 41 66 29 79 15 90 62 60 95 69 57 55 81 33 20 89 76 65 56 77 61 18 88 75 19
Card 23: 64 16 33 77 80 89 90 50 57 4 | 46 94 45 42 82 61 67 3 76 74 96 79 7 70 73 97 11 34 35 72 55 51 36 12 13
Card 24: 40 13 83 79 42 70 26 33 7 12 | 95 17 5 74 68 28 46 21 96 43 73 47 18 86 54 88 82 61 85 51 11 9 56 20 75
Card 25: 97 54 33 84 85 49 4 26 25 67 | 22 41 72 84 25 16 85 8 83 62 15 33 97 17 38 67 69 51 45 77 28 87 24 54 4
Card 26: 54 22 60 99 15 96 80 3 5 64 | 96 65 54 38 60 87 8 15 80 10 3 32 22 56 43 5 44 14 78 18 97 64 25 63 99
Card 27: 88 93 30 77 33 46 38 66 7 20 | 96 75 30 77 83 76 54 46 15 66 38 88 55 40 22 21 34 42 29 20 71 16 28 61 18
Card 28: 48 85 39 25 47 80 98 33 68 66 | 50 82 40 60 84 46 29 51 25 47 11 22 58 64 36 2 63 92 80 15 72 27 37 98 10
Card 29: 85 92 67 13 70 60 9 35 18 98 | 44 16 66 33 81 56 58 73 64 85 39 40 49 63 23 17 19 1 28 62 2 65 10 68 11
Card 30: 15 64 30 28 6 97 69 38 17 79 | 92 50 33 24 85 6 38 44 91 28 35 58 90 97 39 79 64 80 84 22 15 66 2 45 17
Card 31: 7 74 79 40 62 55 16 48 59 97 | 31 70 34 85 23 17 4 92 12 66 1 50 43 87 27 64 11 28 26 47 94 2 36 15 39
Card 32: 97 95 38 61 7 22 36 94 47 4 | 21 37 44 88 77 33 11 12 91 27 80 67 25 83 17 45 89 61 98 40 59 76 96 71 1
Card 33: 15 35 9 39 25 62 57 19 81 47 | 64 57 71 56 35 25 33 1 76 97 48 84 44 79 82 39 19 74 78 59 14 49 81 29 11
Card 34: 97 3 81 82 28 40 35 67 38 85 | 36 76 21 89 38 34 43 10 85 9 99 83 68 94 47 19 17 91 41 26 20 30 63 25 69
Card 35: 43 49 58 92 57 71 56 28 33 3 | 32 1 70 43 29 93 54 63 58 27 14 28 51 31 81 57 25 50 87 90 82 73 97 7 12
Card 36: 18 85 61 97 29 25 66 28 11 62 | 44 26 46 65 83 59 30 66 68 47 90 93 15 84 9 7 72 1 95 87 3 20 23 81 86
Card 37: 97 22 74 4 43 78 76 8 26 1 | 4 93 24 5 80 37 48 12 59 32 50 71 66 69 52 23 34 25 57 89 51 99 41 56 63
Card 38: 20 57 93 41 87 71 76 29 33 66 | 63 56 49 11 64 2 62 68 82 8 67 81 41 4 78 17 85 97 69 35 19 47 30 95 65
Card 39: 6 81 87 68 29 23 76 9 44 33 | 74 71 60 82 98 72 85 57 7 96 84 30 19 3 35 12 22 50 15 26 94 65 62 61 83
Card 40: 96 61 74 3 10 54 58 86 97 87 | 16 37 57 5 72 93 74 45 88 67 97 54 69 2 71 58 46 96 87 44 10 20 86 28 3
Card 41: 28 83 7 40 32 56 82 70 14 22 | 82 81 37 73 76 65 35 56 17 40 83 29 39 6 80 61 25 28 31 32 1 38 42 85 8
Card 42: 16 47 55 93 99 1 7 72 12 40 | 78 2 26 88 9 98 40 47 61 77 23 1 66 27 55 5 72 67 50 12 85 83 90 71 25
Card 43: 17 94 80 60 24 12 20 66 99 41 | 53 69 76 97 15 54 29 73 98 33 30 45 24 19 70 66 16 78 6 90 61 96 32 89 46
Card 44: 16 20 87 88 90 27 69 81 79 70 | 52 70 85 7 13 87 34 26 60 82 15 88 69 79 58 62 75 44 42 49 48 11 97 16 27
Card 45: 72 9 25 20 48 79 15 2 49 67 | 4 3 60 85 48 73 15 98 25 84 95 80 22 7 58 72 44 67 79 20 40 70 1 29 13
Card 46: 86 95 61 42 30 43 1 72 19 53 | 65 88 13 2 3 30 51 7 5 19 74 25 56 50 10 32 43 85 78 61 99 12 75 42 80
Card 47: 80 62 17 58 21 95 18 65 19 54 | 23 1 28 41 80 46 18 17 35 54 19 40 43 62 96 77 45 90 13 21 12 66 52 53 65
Card 48: 52 43 23 72 73 82 9 19 60 83 | 35 29 60 57 22 46 78 39 86 27 92 90 19 71 28 44 41 40 52 79 6 50 15 82 21
Card 49: 10 19 28 81 32 46 42 8 54 16 | 42 93 82 62 95 67 59 8 87 36 28 35 38 31 75 70 96 10 56 1 54 44 4 88 24
Card 50: 12 66 62 83 81 13 2 38 85 57 | 73 95 59 70 54 93 71 35 25 75 82 46 14 21 76 32 8 81 68 42 79 44 34 41 55
Card 51: 62 51 82 74 97 93 49 94 76 58 | 4 46 69 1 33 38 68 89 59 91 57 67 3 92 19 53 77 50 94 48 62 26 98 9 81
Card 52: 52 51 23 12 82 32 96 89 47 55 | 12 4 60 90 17 35 52 64 94 43 27 14 9 25 6 66 41 68 38 56 37 19 55 85 69
Card 53: 23 59 46 4 62 48 71 20 50 1 | 41 77 25 16 35 34 44 81 65 17 78 15 42 12 72 55 57 3 58 88 40 95 66 13 74
Card 54: 43 96 23 40 48 38 10 21 8 20 | 98 88 67 99 97 56 54 1 29 57 37 69 63 32 89 35 41 85 11 49 74 36 28 65 91
Card 55: 9 66 49 29 54 15 36 93 50 13 | 84 79 55 53 41 8 78 89 18 40 56 61 45 7 88 63 37 4 67 85 90 28 34 51 10
Card 56: 51 99 43 34 16 30 8 36 71 88 | 99 36 8 16 71 28 43 29 61 94 92 48 77 58 51 34 88 67 47 30 54 14 66 70 68
Card 57: 46 90 29 80 82 93 4 66 57 91 | 90 57 74 20 54 42 93 60 88 80 5 78 82 51 7 29 4 55 33 89 32 12 27 63 44
Card 58: 46 16 53 11 58 63 65 93 99 36 | 22 29 59 91 79 40 95 68 67 99 88 87 13 73 54 8 49 20 16 94 9 43 47 4 98
Card 59: 57 93 76 90 32 22 30 9 98 88 | 48 93 22 33 14 92 80 3 2 17 82 54 42 63 41 74 56 87 45 52 71 35 70 32 60
Card 60: 26 74 89 84 81 10 79 99 75 11 | 86 81 64 26 54 35 66 99 84 53 89 79 13 75 24 98 60 19 94 74 5 11 49 10 23
Card 61: 51 99 9 36 82 83 40 25 97 39 | 2 82 72 65 7 17 63 28 16 84 34 56 37 81 25 13 26 50 73 51 40 94 49 8 39
Card 62: 98 72 92 16 2 68 65 61 20 78 | 89 60 42 83 20 7 64 36 77 95 63 37 39 4 74 75 25 67 9 58 49 2 87 10 68
Card 63: 17 86 72 89 44 30 21 64 36 84 | 72 30 91 27 31 50 64 7 25 9 89 84 17 86 92 71 13 63 36 2 41 28 33 94 82
Card 64: 9 71 80 49 16 90 92 17 39 45 | 53 9 30 93 7 12 98 87 45 16 67 71 90 18 17 31 42 36 39 48 47 85 19 97 95
Card 65: 76 39 34 30 80 38 16 45 46 58 | 16 79 45 51 40 67 31 49 30 22 85 63 57 34 76 80 3 48 46 36 38 58 19 55 6
Card 66: 97 57 52 42 67 92 28 6 7 73 | 55 79 71 61 94 86 83 35 72 78 4 58 10 51 73 89 68 92 42 24 69 57 91 7 43
Card 67: 99 35 28 30 61 98 51 73 4 85 | 90 34 58 69 21 59 36 97 96 98 44 47 12 15 61 29 28 42 99 51 52 71 19 40 73
Card 68: 72 30 78 60 61 91 14 73 76 47 | 46 41 40 6 94 56 16 45 60 20 33 24 43 1 88 67 62 68 2 84 29 12 4 96 74
Card 69: 14 20 41 89 85 13 98 6 33 4 | 36 99 26 58 49 55 16 68 15 52 30 35 28 21 82 57 65 56 7 37 3 20 14 47 22
Card 70: 93 18 99 57 25 81 95 4 58 37 | 24 66 67 61 34 55 85 37 78 30 75 79 3 32 83 33 10 52 69 98 20 45 2 68 44
Card 71: 47 27 78 40 34 56 59 62 26 93 | 50 18 84 99 64 10 97 22 85 20 15 19 72 31 58 89 37 6 26 44 68 60 43 21 17
Card 72: 28 18 7 3 11 94 85 44 90 40 | 59 2 49 16 27 42 72 33 50 5 92 37 88 55 95 11 62 7 52 23 41 74 98 35 30
Card 73: 1 46 31 33 20 19 97 89 15 45 | 50 77 71 24 88 87 74 95 56 44 42 70 4 75 96 25 21 11 59 47 29 35 83 2 85
Card 74: 88 55 81 82 51 18 48 12 72 19 | 41 78 28 96 83 5 33 60 3 73 53 85 22 4 50 61 98 23 32 68 34 80 49 75 36
Card 75: 17 93 50 45 57 97 39 3 87 32 | 79 87 59 15 1 71 54 37 80 85 14 93 45 3 24 50 94 74 75 64 55 97 17 76 21
Card 76: 37 19 35 66 32 28 43 68 13 86 | 68 45 91 37 33 69 35 24 1 14 58 25 52 3 50 70 62 64 94 32 49 13 28 43 21
Card 77: 5 6 46 30 74 35 48 94 26 88 | 82 55 59 35 74 92 36 26 48 5 7 98 27 42 60 94 11 71 6 33 23 30 56 25 46
Card 78: 27 81 2 26 70 83 28 75 15 82 | 47 25 73 15 36 86 93 90 46 37 1 28 75 89 49 83 2 79 81 27 9 44 82 70 61
Card 79: 35 38 41 81 18 89 9 34 55 16 | 21 31 76 69 50 45 88 63 89 70 15 96 99 8 67 42 20 59 74 19 48 37 98 10 39
Card 80: 97 65 69 37 10 86 57 41 15 31 | 17 58 2 50 45 27 33 73 96 12 29 86 60 74 89 81 51 95 37 41 75 98 38 93 20
Card 81: 12 6 42 18 14 74 61 85 47 28 | 13 49 34 78 81 75 57 11 95 3 69 27 2 42 44 76 54 4 68 48 24 53 52 20 15
Card 82: 40 27 39 47 34 78 31 79 91 12 | 63 6 76 5 50 8 86 96 99 57 82 87 7 37 95 56 28 26 77 67 45 17 51 66 30
Card 83: 38 96 19 65 28 70 54 95 62 15 | 29 26 46 50 32 18 89 93 22 24 1 52 2 39 59 86 69 56 72 58 25 70 54 7 10
Card 84: 76 89 49 56 46 1 83 64 73 40 | 19 60 49 99 18 28 54 73 32 38 97 87 2 79 8 61 12 93 35 20 52 51 58 3 21
Card 85: 77 86 68 78 37 82 93 17 15 36 | 9 19 79 80 39 8 15 54 68 27 98 50 46 41 88 12 34 47 76 93 81 7 35 85 73
Card 86: 68 22 45 20 26 79 88 44 46 90 | 84 19 67 86 49 18 21 65 23 6 57 90 75 28 51 83 4 56 26 98 38 5 3 80 63
Card 87: 43 34 86 6 75 41 38 17 22 61 | 54 95 20 36 72 28 59 90 40 50 63 81 89 30 92 32 26 78 53 42 46 15 73 51 7
Card 88: 15 32 22 2 63 17 62 94 99 83 | 44 25 22 16 58 54 67 4 92 8 75 27 41 99 53 97 76 5 51 32 78 74 73 81 45
Card 89: 67 75 27 99 94 7 57 15 40 65 | 61 42 96 13 53 56 3 63 70 41 69 28 86 11 54 16 34 22 31 76 14 5 43 79 77
Card 90: 10 49 37 75 89 18 62 16 65 13 | 8 67 79 40 27 23 15 56 69 71 5 85 87 88 14 74 22 19 64 98 93 35 18 82 31
Card 91: 73 28 59 31 18 92 69 84 38 52 | 86 70 65 90 53 95 45 33 16 94 23 71 25 34 26 98 13 87 55 8 1 49 6 93 63
Card 92: 18 60 22 23 16 6 88 4 32 44 | 37 88 46 75 97 6 22 9 5 18 92 32 16 4 49 82 13 60 44 26 28 86 8 12 23
Card 93: 14 39 72 74 69 9 4 13 57 7 | 22 6 96 21 23 80 50 83 55 81 30 1 79 92 34 32 95 91 11 76 85 12 73 99 89
Card 94: 38 18 52 85 43 3 89 63 78 77 | 78 35 89 77 96 27 38 46 3 58 84 37 85 4 13 52 80 7 21 50 63 42 86 28 43
Card 95: 72 18 32 20 23 9 43 97 71 30 | 21 29 14 50 5 48 35 15 58 75 24 73 81 88 82 13 98 86 26 33 70 64 96 11 90
Card 96: 36 27 25 77 60 63 49 1 39 31 | 29 78 5 67 77 24 71 59 22 73 6 69 99 88 37 25 21 47 42 61 2 40 26 45 23
Card 97: 40 74 36 19 92 51 78 44 96 20 | 18 98 69 94 73 40 82 45 38 44 78 58 57 32 99 14 34 63 35 92 3 83 4 84 75
Card 98: 57 55 61 60 77 56 50 33 48 47 | 61 77 33 86 75 47 65 50 48 84 10 55 14 28 19 53 3 46 83 31 1 51 89 56 57
Card 99: 93 47 74 10 37 90 76 1 40 54 | 62 72 8 28 79 84 23 75 2 45 96 32 16 71 56 14 13 63 78 30 12 55 65 46 91
Card 100: 15 33 70 46 11 23 24 69 47 5 | 6 68 69 86 55 3 50 43 45 75 36 97 91 20 15 77 21 23 17 71 70 82 42 35 9
Card 101: 40 41 98 7 73 21 47 68 59 1 | 11 79 77 37 48 96 92 30 18 24 31 88 49 99 14 23 82 35 42 16 22 84 8 75 32
Card 102: 92 51 37 63 18 54 28 58 40 4 | 10 94 9 42 64 11 91 23 50 30 90 81 74 77 65 24 49 60 19 70 79 83 76 72 99
Card 103: 66 62 18 43 33 50 51 30 22 63 | 20 68 54 91 55 14 1 31 71 38 80 86 81 87 89 53 42 83 65 64 30 73 6 61 2
Card 104: 2 86 13 94 18 9 74 35 49 91 | 82 21 12 51 25 10 89 6 73 95 2 16 83 36 49 64 3 87 41 78 27 98 67 56 7
Card 105: 51 42 19 18 31 2 29 80 99 65 | 27 55 14 37 52 11 25 5 30 73 41 32 76 28 50 69 88 66 22 74 40 21 13 35 90
Card 106: 6 19 88 46 69 13 49 20 63 31 | 47 32 72 78 79 53 55 75 98 16 76 52 93 17 27 77 74 45 44 60 10 91 3 87 30
Card 107: 11 42 78 2 9 91 46 51 68 88 | 30 7 18 76 94 87 50 57 73 14 54 36 80 59 71 61 20 64 5 44 55 93 27 74 24
Card 108: 4 79 42 25 54 92 93 88 90 81 | 86 92 79 4 52 58 3 65 95 14 42 59 15 81 12 39 90 25 98 49 38 63 27 84 88
Card 109: 65 16 49 63 6 37 48 75 77 19 | 16 73 6 25 14 28 27 75 49 11 61 77 76 19 85 95 63 37 33 88 48 22 65 72 31
Card 110: 83 63 27 82 72 40 70 35 12 86 | 14 96 39 40 72 56 8 83 63 43 42 86 91 58 48 70 3 73 22 35 82 33 29 31 12
Card 111: 36 31 68 37 83 23 9 39 12 26 | 80 92 71 20 48 37 53 32 75 31 83 58 9 26 77 52 42 68 70 7 72 36 23 87 50
Card 112: 94 61 81 68 89 42 52 92 74 39 | 94 89 15 76 86 92 65 57 84 2 21 81 49 68 42 39 90 31 13 27 69 61 3 74 52
Card 113: 68 9 32 67 96 43 14 15 28 48 | 2 81 58 90 45 89 53 34 39 7 46 55 20 69 25 66 17 54 44 19 93 23 92 26 10
Card 114: 25 77 57 50 59 16 46 80 2 14 | 58 14 78 81 8 75 21 45 50 67 55 1 51 92 20 25 86 32 72 54 65 44 38 91 70
Card 115: 11 10 76 79 84 82 16 14 43 6 | 84 59 20 63 79 33 23 47 40 17 48 80 76 25 83 16 82 89 6 11 10 97 44 43 14
Card 116: 21 1 37 82 29 36 57 76 68 63 | 86 38 20 14 36 8 7 31 68 21 56 1 63 26 28 57 96 54 29 82 37 76 61 71 40
Card 117: 4 7 73 26 78 49 22 11 74 35 | 76 26 57 22 66 36 73 35 16 77 87 49 32 54 92 43 7 15 20 38 8 82 29 78 11
Card 118: 58 12 45 87 44 90 48 72 77 66 | 34 57 66 52 90 98 4 99 21 80 8 3 18 45 79 23 50 10 43 62 54 60 39 29 33
Card 119: 58 97 56 38 78 75 84 99 7 32 | 92 33 78 72 7 84 64 18 38 43 27 32 21 99 85 40 58 93 97 13 3 75 56 25 46
Card 120: 40 31 79 63 24 20 11 56 92 32 | 63 32 92 22 1 30 79 20 58 53 64 24 56 36 81 6 49 48 17 26 73 83 47 3 8
Card 121: 51 39 2 99 40 21 4 8 14 46 | 11 29 41 74 55 73 16 95 21 30 85 81 2 76 59 99 9 51 58 8 44 43 61 27 25
Card 122: 29 76 10 60 87 27 35 65 37 59 | 59 53 46 17 1 48 36 88 95 85 13 41 67 31 90 39 99 24 51 11 84 42 96 91 92
Card 123: 99 34 55 8 23 83 28 26 21 54 | 99 8 2 10 26 76 11 52 95 73 38 74 23 92 59 57 71 56 1 13 93 87 43 4 70
Card 124: 75 96 37 43 92 85 68 78 18 4 | 71 43 78 96 92 62 76 19 39 21 52 29 36 93 81 33 53 2 10 69 82 87 14 85 68
Card 125: 11 32 49 86 21 95 94 64 77 23 | 53 25 9 94 75 21 10 35 95 81 39 41 90 18 45 43 78 73 63 56 27 74 46 17 85
Card 126: 8 64 16 62 90 93 98 27 57 4 | 39 89 62 42 60 33 90 3 44 32 8 13 24 85 5 93 68 55 73 22 4 52 28 58 12
Card 127: 22 52 46 90 56 44 84 62 48 8 | 46 86 7 72 80 58 38 76 53 12 83 22 15 60 84 14 33 17 52 49 88 93 36 4 71
Card 128: 49 31 89 7 43 41 27 58 74 72 | 92 24 40 95 80 84 2 19 70 29 83 69 42 17 39 67 97 98 32 56 23 59 21 5 68
Card 129: 92 50 77 38 85 25 5 72 34 84 | 39 38 55 26 58 83 75 70 80 94 42 9 12 69 29 88 50 3 62 96 13 48 93 44 22
Card 130: 45 23 32 47 89 28 9 95 94 14 | 53 78 75 3 50 29 65 60 1 98 15 13 36 71 52 21 66 19 73 67 91 37 76 26 56
Card 131: 70 27 15 12 83 23 96 57 90 77 | 14 34 88 74 59 68 94 44 99 39 40 78 47 17 43 42 80 9 73 93 41 25 71 22 75
Card 132: 16 32 43 64 77 1 14 78 97 98 | 78 97 64 75 52 98 13 81 16 57 3 9 14 83 32 28 56 58 1 43 87 12 77 24 31
Card 133: 95 53 4 45 36 20 77 60 8 49 | 2 62 83 20 53 95 57 86 8 45 38 63 49 82 85 26 36 60 89 81 92 51 54 4 99
Card 134: 95 23 88 8 52 67 46 15 36 55 | 74 44 67 8 94 88 82 46 6 34 64 23 36 14 19 91 15 72 98 56 55 95 65 13 52
Card 135: 27 40 81 65 23 49 89 67 4 32 | 75 32 8 40 16 27 38 54 48 67 22 42 85 57 4 97 76 81 82 28 55 65 2 72 23
Card 136: 7 35 1 24 95 80 25 4 75 37 | 73 28 64 72 56 66 55 29 52 2 80 98 11 41 16 78 75 89 35 12 85 69 24 42 39
Card 137: 19 38 84 95 77 68 50 70 16 17 | 71 69 30 27 86 7 35 96 33 74 20 93 36 47 6 55 29 32 78 72 58 46 21 99 9
Card 138: 97 58 41 82 43 64 26 81 2 36 | 55 79 30 88 96 99 34 82 25 6 71 44 54 77 91 11 90 80 76 40 92 69 64 29 15
Card 139: 41 27 9 87 98 24 72 58 2 88 | 93 72 58 89 34 23 24 48 49 98 78 50 87 64 2 14 85 21 62 75 88 60 41 53 16
Card 140: 79 92 45 91 75 2 1 57 66 40 | 42 82 45 28 75 91 1 11 63 17 20 54 27 92 48 40 12 57 69 66 2 21 19 88 79
Card 141: 33 4 49 55 78 9 61 83 58 50 | 50 9 94 83 98 78 14 66 67 61 71 4 72 39 49 40 29 30 36 16 47 3 58 19 33
Card 142: 80 32 49 19 43 42 50 86 97 87 | 42 15 71 58 18 85 80 19 97 86 32 62 95 44 56 50 83 28 51 34 33 43 36 87 49
Card 143: 76 89 44 30 69 84 47 85 42 23 | 54 17 16 52 86 48 81 92 1 7 78 64 66 59 21 55 36 58 46 37 6 61 89 72 82
Card 144: 22 9 57 50 38 82 66 70 92 37 | 71 18 63 27 87 34 23 13 39 92 77 60 74 46 50 48 57 54 66 22 59 83 44 9 70
Card 145: 56 90 36 66 70 16 73 62 4 37 | 18 34 96 7 47 65 99 56 58 75 85 31 36 3 90 70 5 66 83 62 73 16 55 37 4
Card 146: 68 59 27 32 62 43 25 22 42 3 | 67 68 59 70 98 16 8 25 24 22 44 53 63 11 6 65 54 74 81 32 91 50 13 62 99
Card 147: 21 95 4 18 23 68 83 36 29 3 | 94 42 90 33 50 39 41 66 58 8 96 83 15 85 56 93 14 99 67 37 5 61 24 4 3
Card 148: 13 22 23 39 61 17 50 28 25 19 | 86 92 67 42 85 22 17 19 7 5 39 55 47 20 64 25 50 66 31 30 61 41 18 89 74
Card 149: 24 79 8 18 15 97 95 13 33 89 | 72 18 13 85 89 49 47 1 11 84 40 50 44 71 15 53 43 26 8 86 23 22 83 21 97
Card 150: 98 78 63 19 91 86 1 9 55 35 | 41 33 95 85 83 20 66 23 86 94 8 87 43 37 71 58 21 14 96 3 29 6 39 53 32
Card 151: 47 78 1 40 26 97 61 73 24 21 | 59 60 94 4 52 42 92 19 23 57 82 88 70 45 43 96 7 72 26 58 71 6 16 53 8
Card 152: 3 79 50 95 26 91 66 60 71 53 | 12 96 93 92 49 5 9 76 30 8 23 58 63 73 94 10 19 46 39 55 33 87 18 78 86
Card 153: 2 55 64 32 42 68 63 52 50 90 | 60 20 30 16 98 85 1 35 97 33 64 65 79 12 51 78 48 49 86 50 57 99 3 10 46
Card 154: 4 72 77 78 27 68 37 57 82 91 | 38 39 36 23 43 53 71 24 63 64 89 80 49 97 60 47 21 90 93 48 70 86 65 66 3
Card 155: 90 34 33 91 74 28 36 4 5 39 | 51 23 30 73 37 97 99 25 32 54 67 52 75 48 38 78 42 35 13 6 81 63 49 83 80
Card 156: 38 8 26 2 43 32 72 45 29 5 | 77 89 32 45 73 34 23 80 1 78 5 86 19 38 7 59 75 29 8 43 26 72 20 12 2
Card 157: 42 20 82 74 94 44 54 33 69 93 | 94 98 34 54 20 68 82 18 13 53 33 67 22 42 72 16 62 6 25 17 46 56 87 9 7
Card 158: 41 46 13 9 93 48 65 76 3 4 | 10 67 53 57 44 18 47 13 98 59 6 52 5 91 17 54 97 61 68 26 25 42 40 72 22
Card 159: 73 1 50 18 66 97 12 93 41 80 | 12 80 36 41 53 1 50 18 19 75 3 40 39 16 83 85 66 73 35 70 97 25 56 67 93
Card 160: 86 47 9 35 3 85 33 53 99 50 | 44 55 12 43 86 13 20 31 3 37 33 28 9 41 98 39 35 58 19 29 25 1 82 67 71
Card 161: 68 93 52 43 62 15 66 33 53 84 | 27 44 37 39 50 71 63 94 20 79 62 38 42 72 12 33 85 9 43 93 83 68 28 47 45
Card 162: 54 43 38 6 50 80 72 41 78 92 | 92 73 55 15 34 61 79 57 72 71 53 83 50 41 47 60 10 58 67 36 69 2 63 84 5
Card 163: 58 52 14 99 77 51 70 16 35 57 | 60 51 34 86 92 66 10 93 99 16 67 27 47 19 35 61 58 4 9 28 82 84 42 38 43
Card 164: 9 19 34 3 38 46 74 85 42 87 | 68 71 70 98 63 84 10 59 16 76 91 18 36 4 60 77 97 80 64 88 95 66 94 58 37
Card 165: 46 68 72 82 41 79 28 6 19 23 | 88 74 16 36 44 19 46 63 85 77 94 38 42 28 21 26 70 66 1 51 9 45 49 20 6
Card 166: 94 97 38 52 45 84 81 71 49 22 | 86 66 45 40 21 58 6 82 29 87 38 68 20 96 95 49 4 77 25 36 32 51 18 94 48
Card 167: 47 98 46 63 38 23 57 61 31 96 | 63 44 68 56 67 26 27 7 10 93 79 50 4 48 42 9 19 5 23 11 47 52 40 88 58
Card 168: 36 59 73 99 8 49 63 19 34 74 | 24 30 98 46 65 95 91 14 7 37 87 57 40 67 16 94 66 93 12 82 48 28 88 90 58
Card 169: 34 48 11 54 74 40 13 71 86 76 | 7 65 66 23 95 45 27 42 47 60 20 92 28 84 50 73 2 80 41 99 77 62 17 21 85
Card 170: 67 6 17 58 51 2 19 72 33 41 | 34 20 46 35 29 89 12 77 37 97 88 4 98 44 82 39 38 15 32 48 63 65 68 21 93
Card 171: 63 1 50 71 14 33 78 85 40 99 | 40 32 54 69 4 93 85 1 99 50 71 78 57 22 63 5 14 38 33 72 16 24 29 64 13
Card 172: 33 52 35 85 57 49 60 11 80 43 | 39 92 94 83 49 81 82 79 97 5 72 33 87 80 63 52 96 53 1 43 35 60 85 57 11
Card 173: 33 40 92 88 97 77 20 84 27 23 | 58 33 12 27 34 92 46 23 13 62 77 82 43 54 40 64 37 96 15 84 60 88 20 97 1
Card 174: 4 6 66 57 77 24 59 50 9 46 | 63 57 2 60 4 89 88 46 24 14 5 66 16 59 11 13 64 39 38 92 65 44 77 17 79
Card 175: 55 82 61 80 67 89 90 93 43 1 | 7 3 84 23 14 69 47 35 57 10 95 99 64 63 42 93 96 6 53 72 29 33 18 56 83
Card 176: 70 7 30 29 66 82 8 24 89 11 | 9 67 86 87 22 76 50 51 40 21 6 98 94 17 12 74 33 34 55 20 53 99 1 80 52
Card 177: 78 14 51 53 26 44 36 2 33 23 | 53 26 48 24 5 88 33 90 36 22 29 89 51 45 70 44 23 2 73 91 57 92 78 47 14
Card 178: 19 75 43 85 35 45 93 59 57 7 | 57 32 12 45 76 59 71 85 74 46 69 25 86 10 50 44 79 95 93 49 63 24 82 33 73
Card 179: 35 18 9 3 88 62 83 98 61 41 | 41 70 64 48 31 61 45 46 15 99 69 51 98 28 87 17 30 26 24 52 29 71 60 38 66
Card 180: 13 20 97 73 94 22 80 40 47 85 | 41 30 22 11 65 87 69 23 58 27 59 57 96 55 82 20 79 76 85 3 89 13 8 25 94
Card 181: 14 74 36 86 59 49 69 24 65 28 | 93 24 57 83 34 62 80 85 74 36 23 9 13 45 52 67 64 26 15 69 95 21 43 38 77
Card 182: 41 88 35 24 7 6 11 79 8 56 | 25 78 66 69 64 44 95 81 85 48 87 26 47 63 56 3 94 86 8 52 24 73 15 20 19
Card 183: 2 35 46 34 76 99 12 47 33 64 | 15 53 32 21 73 11 7 26 75 95 37 17 67 56 77 99 39 72 82 47 2 64 20 33 55
Card 184: 73 43 57 65 99 86 29 32 69 53 | 4 19 89 82 48 94 18 53 17 64 45 85 26 52 97 43 47 1 41 90 65 72 46 20 31
Card 185: 81 71 51 68 27 22 63 76 85 3 | 84 20 91 48 47 98 13 30 83 64 93 26 50 78 66 77 9 97 32 12 90 41 74 52 43
Card 186: 76 27 92 85 62 60 75 11 65 70 | 48 51 58 99 40 52 50 10 95 1 46 21 67 78 86 36 55 14 84 28 12 18 8 42 53
Card 187: 88 55 79 69 45 73 16 21 5 11 | 95 24 32 59 96 37 87 7 28 89 33 82 35 60 83 20 43 75 57 80 1 9 52 31 36
Card 188: 61 32 89 34 13 46 66 42 22 91 | 74 52 2 85 82 57 8 41 26 6 10 38 95 64 90 79 3 60 98 76 45 94 51 70 28

70
2023/day5/day5.py Normal file
View File

@ -0,0 +1,70 @@
from itertools import zip_longest
def grouper(n, iterable):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args)
def part1(sections):
# consume seed section
_, seeds = next(sections)
seeds = [int(s) for s in seeds]
for _, mapping in sections:
seeds = [apply_mapping(s, mapping) for s in seeds]
print(f"Part 1, lowest location number = {min(seeds)}")
def part2(sections):
# consume seed section
_, seeds = next(sections)
seeds = [int(s) for s in seeds]
min_seed = 2**128
for start_seed, length in grouper(2, seeds):
subseeds = range(start_seed, start_seed + length)
print(f"calculate_for_subseeds(subseeds len={len(subseeds)})")
res = calculate_for_subseeds(subseeds, sections)
mini = min(res)
if mini < min_seed:
min_seed = mini
print(f"Part 2 {min_seed}")
def calculate_for_subseeds(seeds, sections):
new_seeds = seeds
for _, mapping in sections:
new_seeds = [apply_mapping(s, mapping) for s in new_seeds]
return new_seeds
def apply_mapping(seed, mapping):
for dst, src, length in grouper(3, mapping):
src, length, dst = int(src), int(length), int(dst)
end = src + length
if src <= seed < end:
return seed + (dst-src)
return seed
def parse_input(infile):
with open(infile) as f:
sections = f.read().split("\n\n")
sections = ((title, numbers) for title, numbers in (s.split(":") for s in sections))
sections = ((title, numbers.split()) for title, numbers in sections)
return sections
if __name__ == "__main__":
import sys
import os
SCRIPTPATH = os.path.dirname(os.path.realpath(__file__))
infile = next(iter(sys.argv[1:]), None)
sections = parse_input(infile or os.path.join(SCRIPTPATH, "example.txt"))
part1(sections)
sections = parse_input(infile or os.path.join(SCRIPTPATH, "example.txt"))
part2(sections)

33
2023/day5/example.txt Normal file
View File

@ -0,0 +1,33 @@
seeds: 79 14 55 13
seed-to-soil map:
50 98 2
52 50 48
soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15
fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4
water-to-light map:
88 18 7
18 25 70
light-to-temperature map:
45 77 23
81 45 19
68 64 13
temperature-to-humidity map:
0 69 1
1 0 69
humidity-to-location map:
60 56 37
56 93 4

183
2023/day5/input.txt Normal file
View File

@ -0,0 +1,183 @@
seeds: 629551616 310303897 265998072 58091853 3217788227 563748665 2286940694 820803307 1966060902 108698829 190045874 3206262 4045963015 223661537 1544688274 293696584 1038807941 31756878 1224711373 133647424
seed-to-soil map:
3809825462 2725979505 339457863
3359244708 2085610478 450580754
652041572 2536191232 189788273
841829845 3346349446 343599367
1408035723 73701258 732851393
2140887116 3689948813 88205018
0 3778153831 371129494
2953980724 0 73701258
3027681982 1754047752 331562726
2229092134 1029159162 724888590
1185429212 806552651 222606511
371129494 3065437368 280912078
soil-to-fertilizer map:
201390752 0 263005475
772560454 263005475 186665885
3597849741 3228095269 216867970
959226339 951560560 85171934
2882237029 3813801625 34286208
0 586356609 16090261
1460387186 1189054013 136970257
2511361703 2581174071 147006778
201110502 1477157137 280250
3582774663 3444963239 15075078
2073881675 2245158204 30510333
3127914126 3163440286 64654983
1724767985 602446870 349113690
1597357443 1036732494 127410542
1044398273 1164143036 24910977
635875205 449671360 136685249
2916523237 2728180849 211390889
1069309250 1854080268 391077936
167223128 1820192894 33887374
4168481019 2454687794 126486277
3496254979 4048626015 86519684
2454687794 4238293387 56673909
2104392008 1648916365 171276529
3814717711 3460038317 353763308
464396227 1477437387 171478978
2658368481 2939571738 223868548
16090261 1326024270 151132867
3393107291 4135145699 103147688
3192569109 3848087833 200538182
fertilizer-to-water map:
357701033 441924316 54941059
2047098412 1574732688 106451110
2414997091 2961420861 217583761
3647103220 3202843177 147888878
1781607871 3397471081 265490541
433955285 629676938 29320532
3280739425 2494455782 366363795
2818710889 1426835569 147897119
1120892574 3179004622 23838555
1539573533 3662961622 195295312
3794992098 1820059317 63264836
0 84223283 357701033
1144731129 1702496991 117562326
2153549522 2046878176 261447569
593734757 726830618 239035306
987137385 83279657 943626
2966608008 0 83279657
1734868845 3350732055 46739026
1438972249 2860819577 100601284
2632580852 2308325745 186130037
1262293455 965865924 108845646
412642092 1681183798 21313193
472462518 1305563330 121272239
988081011 496865375 132811563
463275817 2037691475 9186701
3049887665 1074711570 230851760
832770063 1883324153 154367322
1371139101 658997470 67833148
water-to-light map:
4062286509 3839153068 91029970
1610728246 3827168971 11474903
2753947407 2725849236 1101319735
2525484879 1829977386 228462528
657837215 1095779595 241604827
1895347620 1337384422 492592964
1425623249 4009599599 185104997
2446068318 3930183038 79416561
1894838426 3838643874 509194
2389619503 896001044 56448815
3855267142 2058439914 207019367
1187459420 657837215 238163829
1622203149 2467395620 172372577
2387940584 952449859 1678919
985523081 2265459281 201936339
4153316479 954128778 141650817
1794575726 4194704596 100262700
899442042 2688664470 37184766
936626808 2639768197 48896273
light-to-temperature map:
0 2682471120 43545350
2829609407 2423668531 227914183
3685065657 3821208881 65673550
1319277847 0 33132672
818263707 3091863377 5216721
3144636417 670795080 1340457
1352410519 895535914 570572224
2709351136 1662268878 120258271
115643652 2726016470 93054822
455333494 1538206440 124062438
3839611769 4030334543 30664857
3750739207 4258515305 36451991
2070721515 33132672 155555065
3132740473 2067641423 5192544
4147162986 3685065657 58311172
4278703737 3743376829 16263559
1070098598 2174489282 249179249
716608392 2072833967 101655315
43545350 1466108138 72098302
3057523590 3016646494 75216883
2700979566 887164344 8371570
4205474158 4060999400 73229579
2226276580 188687737 474702986
1971879519 1968799427 98841996
3931845119 4134228979 124286326
579395932 2819071292 137212460
3137933017 672135537 6703400
1062694241 663390723 7404357
3787191198 3886882431 52420571
269061216 1782527149 186272278
1031805835 2651582714 30888406
823480428 678838937 208325407
3870276626 3759640388 61568493
4056131445 3939303002 91031541
1922982743 3097080098 48896776
208698474 2956283752 60362742
temperature-to-humidity map:
219529182 731674447 232727899
2748076784 2771987989 46463882
2514344851 4061235363 233731933
0 1369964423 219529182
452257081 362359049 21789881
4243457964 2720478657 51509332
3085663754 3109574959 64704581
1639319644 384148930 347525517
3150368335 3626166922 251414834
1986845161 0 139120377
1382707786 1339581093 30383330
1413091116 1113352565 226228528
2794540666 2818451871 291123088
2125965538 338187591 24171458
474046962 139120377 157229612
2361125570 1100881680 12470885
631276574 296349989 41837602
3401783169 3428035243 198131679
3989702261 3174279540 253755703
2224646236 964402346 136479334
2150136996 2299087215 74509240
3806048654 3877581756 183653607
3599914848 2514344851 206133806
673114176 1589493605 709593610
humidity-to-location map:
4029426902 1202474782 191291587
2764446301 708692227 493782555
2188304413 3350514524 33021460
3318755823 4213528230 67155117
2000392671 620732246 87959981
3754724301 3075811923 274702601
3258228856 1393766369 60526967
2088352652 4113576469 99951761
363515622 1849258760 614077493
1213242541 342257124 11129119
1733046668 353386243 267346003
1224371660 4280683347 14283949
2577070088 2888435710 187376213
4220718489 2832149614 56286096
324294413 1810037551 39221209
3385910940 2463336253 368813361
977593115 3383535984 235649426
1238655609 3619185410 494391059
4277004585 324294413 17962711
2221325873 1454293336 355744215

40
2023/day6/day6.py Normal file
View File

@ -0,0 +1,40 @@
def parse_part1(path):
with open(path) as f:
time, distance = f.readlines()
time = [int(x) for x in time.split()[1:]]
distance = [int(x) for x in distance.split()[1:]]
return zip(time, distance)
def calculate_wins(data):
total = 1
for time, record in data:
ways = 0
for n in range(0, time+1):
speed = n
distance = (time-n) * speed
if distance > record:
ways += 1
total *= ways
return total
def parse_part2(path):
with open(path) as f:
time, distance = f.readlines()
time = time.split(":")[1].replace(" ", "").rstrip()
distance = distance.split(":")[1].replace(" ", "").rstrip()
return int(time), int(distance)
if __name__ == "__main__":
assert calculate_wins(zip(*[[7, 15, 30], [9, 40, 200]])) == 288 # part 1 example
assert calculate_wins([[71530, 940200]]) == 71503 # part 2 example
import sys
if len(sys.argv) == 2:
data = parse_part1(sys.argv[1])
res = calculate_wins(data)
print(f"Part 1, res={res}")
data = parse_part2(sys.argv[1])
res = calculate_wins([data])
print(f"Part 2, res={res}")

2
2023/day6/input.txt Normal file
View File

@ -0,0 +1,2 @@
Time: 61 67 75 71
Distance: 430 1036 1307 1150

70
2023/day7/day7.py Normal file
View File

@ -0,0 +1,70 @@
from collections import Counter
def calculate_rank(hand, part2=False):
card_ranks = {'2': 1, '3': 2, '4': 3, '5': 4, '6': 5, '7': 6, '8': 7, '9': 8, 'T': 9, 'J': 10, 'Q': 11, 'K': 12, 'A': 13}
if part2:
# in part2, jokers are the weakest card
card_ranks['J'] = 0
# substitute cards with their ranks to make them sortable
hand = [card_ranks[c] for c in hand]
cnt = Counter(hand)
if part2 and cnt[0] != 5: # edge case if hand == 'JJJJJ'
# substitute jokers with the most common card that isn't a joker
most_common_card = cnt.most_common(2)[0][0] if cnt.most_common(2)[0][0] != 0 else cnt.most_common(2)[1][0]
new_hand = [most_common_card if c == 0 else c for c in hand]
cnt = Counter(new_hand)
rank = 0
match sorted(cnt.values()):
case [5]: rank = 7
case [1, 4]: rank = 6
case [2, 3]: rank = 5
case [1, 1, 3]: rank = 4
case [1, 2, 2]: rank = 3
case [1, 1, 1, 2]: rank = 2
case [1, 1, 1, 1, 1]: rank = 1
# return rank, and hand as a tiebreaker
return (rank, hand)
def parse_input(inp):
hands = [l.strip().split() for l in inp.strip().split("\n")]
return hands
def calculate_wins(hands, part2=False):
total = 0
hands = sorted(hands, key=lambda hb: calculate_rank(hb[0], part2=part2))
for rank, hand in enumerate(hands):
hand, bid = hand
total += (rank + 1) * int(bid)
return total
if __name__ == "__main__":
sample_input = """
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
"""
res = calculate_wins(parse_input(sample_input))
print(f"part 1 example: {res}")
assert res == 6440
res = calculate_wins(parse_input(sample_input), part2=True)
print(f"part 2 example: {res}")
assert res == 5905
import sys
if len(sys.argv) == 2:
with open(sys.argv[1]) as f:
inp = parse_input(f.read())
res = calculate_wins(inp)
print(f"Part 1, res={res}")
res = calculate_wins(inp, part2=True)
print(f"Part 2, res={res}")

1000
2023/day7/input.txt Normal file

File diff suppressed because it is too large Load Diff

75
2023/day8/day8.py Normal file
View File

@ -0,0 +1,75 @@
import re
import math
from itertools import cycle
def parse_input(infile):
with open(infile) as f:
content = f.read().rstrip()
directions, nodes = content.split("\n\n")
directions = directions.strip()
nodes = nodes.split("\n")
nodes = [n.split(" = ") for n in nodes]
nodes = {k: re.findall(r"\w{3}", v) for k, v in nodes}
return directions, nodes
def part1(directions, nodes):
iterations = 0
current_node = "AAA"
for d in cycle(directions):
if current_node == "ZZZ":
break
iterations += 1
if d == "L":
current_node = nodes[current_node][0]
else:
current_node = nodes[current_node][1]
print(f"Part 1: reached 'ZZZ' in {iterations} iterations")
def part2(directions, nodes):
current_nodes = [k for k in nodes.keys() if k.endswith("A")]
# keep track of iterations number for each visited node
# (the number will stop to beeing incremented once the node n_i value reached the target value 'xxZ')
iterations = [0] * len(current_nodes)
for d in cycle(directions):
if all(c.endswith("Z") for c in current_nodes):
break
if d == "L":
new_nodes = []
for i, n in enumerate(current_nodes):
if n.endswith("Z"): # end condition already reached for this node
new_nodes.append(n)
else:
new_nodes.append(nodes[n][0])
iterations[i] += 1
current_nodes = new_nodes
else:
new_nodes = []
for i, n in enumerate(current_nodes):
if n.endswith("Z"): # end condition already reached for this node
new_nodes.append(n)
else:
new_nodes.append(nodes[n][1])
iterations[i] += 1
current_nodes = new_nodes
# the result is the lowest common multiple between the number of iterations
# for each node
result = math.lcm(*iterations)
print(f"Part 2: reached all nodes such that 'xxZ' in {result} iterations")
if __name__ == "__main__":
import sys
import os
SCRIPTPATH = os.path.dirname(os.path.realpath(__file__))
infile = sys.argv[1] if len(sys.argv) == 2 else "example.txt"
directions, nodes = parse_input(os.path.join(SCRIPTPATH, infile))
part1(directions, nodes)
directions, nodes = parse_input(os.path.join(SCRIPTPATH, infile))
part2(directions, nodes)

5
2023/day8/example.txt Normal file
View File

@ -0,0 +1,5 @@
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)

10
2023/day8/example2.txt Normal file
View File

@ -0,0 +1,10 @@
LR
11A = (11B, XXX)
11B = (XXX, 11Z)
11Z = (11B, XXX)
22A = (22B, XXX)
22B = (22C, 22C)
22C = (22Z, 22Z)
22Z = (22B, 22B)
XXX = (XXX, XXX)

716
2023/day8/input.txt Normal file
View File

@ -0,0 +1,716 @@
LRRLRRLLRRRLRRLRLRRRLRRLRRRLRLLRRRLRRRLRLRRRLRRLRRLRLRLLLRRRLRRRLRRLRRLRLRRRLRRLLRRLRRLRLLRLRLRRLRLLRLRLRRRLRRLRLLRLRLLRRLRLRRLLLRLRRLRRRLLLRRLRLRRRLLRRLLLRRRLRRRLLLRRLLRLRRLRLRRLLLRLRRLLLLRRLLRRRLRRLRRLRLRLLRLRRRLLRRLLRRLRRLRRLRRLRLLRRLRRRLRLRLLLRRRLLRRRLRRLRRLLLLRRRR
VRN = (CSM, GPD)
XDT = (QBK, PJR)
HVC = (MKM, TJS)
KRH = (BHN, PXB)
GTX = (VFD, TXR)
BQB = (MQV, PFQ)
TDV = (VSG, MJX)
VJM = (QHP, XMB)
KLG = (QLJ, HCV)
TSM = (JPG, DNP)
KHS = (QNR, DXJ)
FXM = (PHF, PHF)
RMV = (BMM, KHS)
QXL = (BKG, TLP)
MHS = (QXL, CFQ)
TBT = (TVT, BRD)
QXS = (GPP, RND)
XLL = (JHQ, LDV)
PBQ = (VXK, RJR)
FXB = (HMN, THX)
DPF = (GLX, GNC)
HVG = (HJF, SCH)
QMN = (DQJ, GMN)
MBS = (PFX, JHG)
VGL = (FHX, CCK)
QLV = (BLT, FDR)
MNS = (BDB, BMJ)
MMT = (TSM, SFR)
NRP = (FKB, QPH)
XFQ = (GTS, CCQ)
XFF = (HKG, NVL)
TXR = (VHQ, CKP)
VPL = (GHC, VMT)
SGC = (BGM, MJV)
SMS = (GJV, LSC)
BVC = (PRH, FJJ)
JHQ = (VJQ, XTX)
RJF = (GKK, NKX)
RJR = (JJQ, JTK)
VHQ = (JPS, JPS)
SFR = (JPG, DNP)
RDP = (GPD, CSM)
GGQ = (MVX, XBP)
XGK = (GBB, VPH)
XBH = (PTH, GSL)
MKG = (RBP, MGG)
FSG = (KFC, RMB)
NHC = (RQG, CVF)
SSV = (MVF, QFP)
RLP = (FXC, HCP)
FBZ = (FJF, CRJ)
HFL = (FKB, QPH)
NBM = (QBD, XGK)
NSP = (QKG, NDN)
TQF = (RMH, TDB)
RBB = (QTC, HPT)
CVF = (BSV, VTR)
XQG = (LFJ, JXD)
KXF = (CRJ, FJF)
MQC = (MQL, BSL)
RCC = (NHC, QLC)
TNT = (VKQ, NSX)
TVN = (NDN, QKG)
SCH = (FXB, NTM)
CVD = (XLJ, XDT)
QVF = (MQR, RDB)
GXS = (HCK, SHD)
KBD = (JHG, PFX)
KXV = (HVQ, QCJ)
MQR = (RNQ, SVC)
CBC = (SXB, BVC)
GKK = (HDR, LTF)
FRT = (CFQ, QXL)
VMT = (SQQ, DBB)
QPV = (NVQ, VVV)
XGD = (MPL, PMQ)
MNT = (JDD, NQC)
RGT = (QHD, SQP)
HXV = (RQD, RRX)
LGR = (FHX, CCK)
PHF = (CBV, TMC)
BTP = (JSC, QMN)
CXS = (SCH, HJF)
MQV = (FGJ, QPD)
HRZ = (CCX, BCF)
DDB = (DJK, CVD)
XNL = (QLJ, HCV)
GLX = (MGN, CFV)
QCJ = (NDK, XBR)
XBX = (CQM, VKD)
QPH = (XBH, CFG)
NSL = (LFJ, JXD)
DJQ = (VMN, STS)
RNV = (XFF, KSR)
JTR = (QLG, XRD)
VVV = (MDH, KHK)
TLR = (DMH, NXC)
GBH = (GLS, XLK)
LRN = (QRM, FMC)
BRM = (DCK, DSK)
GQS = (FXV, QPV)
XMT = (NHF, RXG)
KLR = (HFN, KDR)
SVH = (RMR, JLC)
QSG = (KQC, CMH)
VVX = (XGM, FNX)
BCF = (LNR, MTS)
RPJ = (RCC, CKG)
JJD = (NRP, HFL)
FGP = (MFS, RBB)
BJX = (BTD, KSC)
PQC = (VMN, STS)
JPG = (RQL, CSQ)
SLK = (JJC, BPJ)
JTK = (XHN, BFH)
HCV = (BRF, VPT)
VPH = (BVS, RRT)
MSH = (JQF, XFJ)
JHL = (QPF, QPF)
FGD = (MPC, TVB)
DCB = (JBC, XFB)
RKN = (TSL, VQG)
QBQ = (QLV, NRT)
MQX = (JSX, MCV)
XHX = (FNX, XGM)
DTL = (JDM, BDX)
LST = (JHL, CQN)
VGR = (HQV, HRZ)
CTQ = (XCF, TJK)
SQP = (HHB, NBM)
RRL = (TSL, VQG)
NNM = (DDS, XSF)
KHK = (HSG, NDF)
MGN = (VXT, VGV)
TLB = (DPK, MLV)
NMM = (TRR, XJH)
SJG = (XRJ, XBX)
GSC = (RRL, RKN)
KDR = (PSJ, TBM)
LRP = (SQP, QHD)
DKF = (MVR, QQB)
FHC = (BPT, BKC)
PLT = (JGG, GGQ)
XRD = (HMH, PBQ)
RHP = (JPD, XVL)
MXF = (MQR, RDB)
DML = (BRD, TVT)
CKP = (JPS, RBS)
BFK = (BCL, TLK)
KSR = (NVL, HKG)
XQF = (BMM, KHS)
BVJ = (CBL, PLC)
BCS = (RQF, GTB)
JCC = (VTT, VPQ)
BCL = (BNV, PDB)
HCK = (DDB, CBX)
SVG = (FGD, VQL)
BLT = (XNK, LHM)
MVQ = (LRG, NPB)
RND = (QCK, QRN)
HFR = (FBT, CLS)
KNK = (XDS, BCK)
XBB = (BRM, FDC)
XGM = (FFC, GJX)
PTN = (TQF, QKP)
RNQ = (GSC, XKH)
TPT = (CMK, KXT)
HPL = (CKB, QLR)
MVX = (QSG, TKJ)
QFP = (RLP, RSF)
GXF = (LNB, VNJ)
QHD = (NBM, HHB)
KSS = (LLH, PFK)
MFD = (XGJ, GGS)
JJQ = (XHN, BFH)
JDD = (HXV, FVH)
CFR = (FXM, FXM)
FDR = (XNK, LHM)
DHG = (BRS, TLR)
TDB = (SBS, XBB)
BVS = (GQH, BFS)
DGZ = (TMC, CBV)
HQD = (JSC, QMN)
TMZ = (XFB, JBC)
BRF = (MBF, KGJ)
RQG = (VTR, BSV)
CSQ = (FTS, RHR)
FFJ = (QCL, CTQ)
XKH = (RRL, RKN)
VJQ = (BTL, GQS)
NGK = (JGG, GGQ)
RQN = (GVG, SJN)
GRR = (RNV, FHF)
LSR = (VBL, SLK)
VQG = (QBV, NJV)
BHK = (BVJ, LJR)
BRS = (DMH, NXC)
NKX = (LTF, HDR)
QBD = (GBB, VPH)
RGQ = (CLM, FHK)
VXX = (KRH, VGN)
KRF = (VFQ, SMN)
XFR = (XGD, RMM)
JGC = (JGM, PFR)
SHD = (DDB, CBX)
QKG = (QTS, GXP)
CDL = (GLX, GNC)
RBP = (HKK, CMN)
CLN = (HDG, BHM)
XFX = (RNV, FHF)
AAA = (DXX, SVG)
FXC = (MMT, KLS)
PTF = (SKF, SDF)
QPF = (RQF, RQF)
DTB = (HQV, HQV)
RRF = (FNV, MKG)
MGG = (HKK, CMN)
NDF = (KMD, FFH)
DVL = (RKL, CLC)
JRQ = (BXV, BRB)
HVM = (DRT, SSV)
BHM = (KNK, BPP)
TDT = (DPS, VCP)
JPC = (DCH, FHD)
RSF = (FXC, HCP)
KSX = (BVJ, LJR)
NLT = (LTB, QBQ)
SBD = (NKX, GKK)
VQL = (MPC, TVB)
JXD = (MLK, LHN)
XNN = (TNT, LPQ)
HMH = (RJR, VXK)
JGG = (MVX, XBP)
PTP = (MVQ, NPS)
FQC = (XQF, RMV)
FXT = (TDH, JGD)
RGP = (CPN, KGF)
BTD = (NKN, NTQ)
BGM = (NRJ, CJN)
RMM = (PMQ, MPL)
DQJ = (DPF, CDL)
TVT = (TFJ, VJM)
TGL = (CGS, SJG)
NHF = (HVC, LVM)
NMK = (GRR, XFX)
QRN = (MMP, XSL)
FFH = (DJQ, PQC)
PDJ = (NQC, JDD)
CGS = (XBX, XRJ)
NTQ = (RXX, FLX)
CFB = (TVC, PTP)
GXK = (FLC, GXS)
RBS = (DCB, TMZ)
CFQ = (TLP, BKG)
QHP = (KVX, GSG)
HDJ = (RPH, QPK)
VXT = (GXF, JKM)
NCM = (NJL, TGL)
HFN = (TBM, PSJ)
JGF = (CFB, NMC)
JDM = (CLN, PHJ)
DJS = (RMR, JLC)
RDB = (RNQ, SVC)
RRX = (HQD, BTP)
HHS = (MXF, QVF)
MMP = (GTX, HKC)
JRK = (KKP, PTN)
TRR = (VGD, HGC)
JKM = (LNB, VNJ)
BRD = (TFJ, VJM)
TLK = (BNV, PDB)
QTS = (CHL, LSR)
BPP = (XDS, BCK)
RXX = (BKP, TLS)
VFD = (VHQ, VHQ)
BQF = (DHG, DQC)
XDL = (QVF, MXF)
ZZZ = (SVG, DXX)
GGB = (LTB, QBQ)
QTN = (JHL, CQN)
BVK = (BHQ, SSG)
VGB = (BXV, BRB)
QLR = (XFR, KNM)
QBK = (KNC, VJX)
BMJ = (JLK, TDV)
FDC = (DSK, DCK)
XDS = (SMS, TVR)
GBC = (NGK, PLT)
HPT = (XHQ, SXT)
FHK = (JCC, FJS)
KNM = (RMM, XGD)
GTB = (KLR, JVZ)
VCT = (PTN, KKP)
LDV = (XTX, VJQ)
KTK = (MQV, PFQ)
TVC = (MVQ, NPS)
BXV = (XLL, KDL)
BFA = (BCF, CCX)
CCF = (CLM, FHK)
JGS = (VCP, DPS)
RVK = (MKJ, QLH)
FNX = (FFC, GJX)
XBP = (QSG, TKJ)
LMJ = (FPH, JVL)
HKG = (VXX, RNX)
KMD = (DJQ, PQC)
BRB = (XLL, KDL)
NDK = (DJS, SVH)
BSV = (XVC, QXS)
TLS = (FSJ, MNS)
CRJ = (SGC, RNH)
BNV = (QSF, FSG)
SMN = (MNK, QGN)
JVV = (TRN, DVL)
JJC = (HBT, RPJ)
KSB = (XVL, JPD)
JJT = (TLB, DTJ)
TSL = (QBV, NJV)
GNV = (GCS, JLR)
HJF = (FXB, NTM)
VMN = (CFR, CFR)
GVG = (XDL, HHS)
LNB = (HMP, XMP)
RTL = (FXT, RCT)
XVC = (RND, GPP)
GNS = (MFS, RBB)
XTG = (LRM, DKQ)
JVZ = (KDR, HFN)
QQB = (XTG, GFG)
HMN = (FHC, FMN)
XLC = (FXT, RCT)
CKG = (QLC, NHC)
NJB = (DVL, TRN)
VCP = (LRF, HPL)
KQJ = (MXH, MXH)
GJV = (TPT, QNJ)
CCX = (LNR, MTS)
DTJ = (MLV, DPK)
HDX = (JSX, MCV)
XRJ = (VKD, CQM)
DMH = (RGP, KPR)
QGN = (VRF, QDL)
JSC = (DQJ, GMN)
BPT = (LLB, XNN)
CJN = (JJT, PGM)
XDV = (XVD, HJH)
JHG = (LLF, MLJ)
NKN = (FLX, RXX)
TGP = (XJH, TRR)
TLP = (XLC, RTL)
HQT = (SSN, BPS)
BKP = (MNS, FSJ)
VPT = (KGJ, MBF)
JSJ = (PFK, LLH)
CBX = (DJK, CVD)
TJK = (VGL, LGR)
THP = (TGL, NJL)
NSX = (SQL, GNV)
JQF = (VDM, JJD)
SDF = (JPC, KRV)
XNK = (HDJ, MQJ)
DSD = (SJN, GVG)
SBS = (FDC, BRM)
FPH = (NCM, THP)
LMR = (KQJ, BGV)
VKQ = (SQL, GNV)
FMC = (CPV, GBC)
HHB = (QBD, XGK)
HVQ = (NDK, XBR)
KXT = (JKG, NLS)
GJX = (TVP, JTR)
JLT = (MHM, MSH)
VNJ = (HMP, XMP)
TDH = (JGF, GGD)
VPQ = (HDX, MQX)
SKF = (JPC, KRV)
NXT = (RXG, NHF)
TRN = (CLC, RKL)
RRT = (BFS, GQH)
JFJ = (SXB, BVC)
KBR = (CGD, JGC)
PGG = (HFR, TJJ)
CMK = (JKG, NLS)
CBV = (FCX, KBR)
GMN = (DPF, CDL)
BTL = (QPV, FXV)
PFX = (MLJ, LLF)
DCT = (XLK, GLS)
PGM = (DTJ, TLB)
NVL = (VXX, RNX)
RPD = (TLK, BCL)
QDL = (FFJ, SFH)
JVL = (THP, NCM)
NVQ = (MDH, KHK)
TMC = (FCX, KBR)
LPQ = (NSX, VKQ)
RHR = (PPL, LCD)
JSX = (DHM, PMS)
DPK = (KBD, MBS)
LTF = (PGG, QPN)
BPS = (GXK, HCM)
HKC = (VFD, TXR)
PXB = (RPN, BQF)
FLX = (TLS, BKP)
PJR = (VJX, KNC)
PDB = (QSF, FSG)
NMC = (TVC, PTP)
MLP = (MSH, MHM)
PMQ = (KXV, QFJ)
FKB = (XBH, CFG)
JRV = (SMN, VFQ)
SQL = (GCS, JLR)
DXX = (FGD, VQL)
XMM = (GMG, LRN)
PFK = (HDL, XFQ)
XSL = (GTX, HKC)
CLC = (JRQ, VGB)
LMH = (KXF, FBZ)
NMX = (KSC, BTD)
GTJ = (KLG, XNL)
THX = (FMN, FHC)
RMH = (XBB, SBS)
SSG = (MFD, KFP)
QNR = (RBG, HNG)
DSK = (LMJ, FRP)
GQP = (FXM, XVT)
MFS = (QTC, HPT)
VHX = (VBD, RDD)
SQS = (GTJ, MSR)
LJR = (CBL, PLC)
QSF = (KFC, KFC)
DHM = (VFJ, DTL)
MDH = (NDF, HSG)
SSN = (HCM, GXK)
HCM = (FLC, GXS)
PQX = (FGG, BXR)
DQC = (BRS, TLR)
KRV = (DCH, FHD)
FNH = (SKF, SDF)
LFJ = (LHN, MLK)
MVR = (GFG, XTG)
HBT = (RCC, CKG)
VKD = (NMK, PFV)
TKJ = (KQC, CMH)
MRH = (RHV, ZZZ)
CKB = (XFR, KNM)
BMM = (DXJ, QNR)
KDL = (JHQ, LDV)
VFJ = (BDX, JDM)
PLC = (PND, GNP)
MNK = (QDL, VRF)
MXT = (RMV, XQF)
TJS = (PTF, FNH)
PHJ = (BHM, HDG)
FSJ = (BDB, BMJ)
CFV = (VGV, VXT)
XVD = (CBF, SQS)
TFJ = (QHP, XMB)
CPV = (PLT, NGK)
VTR = (XVC, QXS)
BKC = (XNN, LLB)
NPS = (NPB, LRG)
FXV = (NVQ, VVV)
FTS = (PPL, LCD)
HMP = (QMD, SNX)
VBD = (DTB, DTB)
VFQ = (QGN, MNK)
KFP = (GGS, XGJ)
BHN = (RPN, BQF)
PFV = (GRR, XFX)
QMD = (MGK, XDV)
MLK = (RPD, BFK)
GFG = (DKQ, LRM)
NLS = (BQB, KTK)
XLK = (HVG, CXS)
LSC = (QNJ, TPT)
FNV = (RBP, MGG)
HKK = (RCX, MQC)
GPD = (NSL, XQG)
RQL = (RHR, FTS)
HDB = (GHC, VMT)
HJH = (SQS, CBF)
QTC = (SXT, XHQ)
TRS = (BXR, FGG)
MTS = (DML, TBT)
RHV = (DXX, SVG)
XVL = (FGP, GNS)
GSG = (RRF, CSP)
VBL = (JJC, BPJ)
CCK = (RJF, SBD)
QPN = (TJJ, HFR)
PRH = (TGP, NMM)
PQT = (TRS, PQX)
QKP = (RMH, TDB)
XMP = (SNX, QMD)
QPD = (KRF, JRV)
RQD = (HQD, BTP)
XVT = (PHF, DGZ)
GXP = (CHL, LSR)
LHM = (MQJ, HDJ)
STS = (CFR, GQP)
FJJ = (NMM, TGP)
MPC = (CCF, RGQ)
MKM = (PTF, FNH)
QVH = (VBD, VBD)
XMB = (KVX, GSG)
CHL = (VBL, SLK)
XBR = (DJS, SVH)
KPR = (CPN, KGF)
MQL = (KSB, RHP)
CQM = (PFV, NMK)
XHQ = (HCR, HVM)
FFC = (JTR, TVP)
FMN = (BPT, BKC)
SNX = (MGK, XDV)
KNC = (QVJ, NNM)
DPS = (LRF, HPL)
GBB = (BVS, RRT)
BFH = (XMM, XQL)
GLS = (HVG, CXS)
RXG = (LVM, HVC)
MPL = (QFJ, KXV)
NXC = (KPR, RGP)
NJV = (TVN, NSP)
LLB = (LPQ, TNT)
SXT = (HVM, HCR)
LLH = (HDL, XFQ)
MLV = (KBD, MBS)
CBF = (GTJ, MSR)
JBC = (KTX, QQG)
FLC = (SHD, HCK)
FRP = (FPH, JVL)
BHQ = (MFD, KFP)
LNR = (DML, TBT)
CSP = (MKG, FNV)
GHC = (SQQ, DBB)
NRT = (BLT, FDR)
VTT = (HDX, MQX)
HSG = (FFH, KMD)
VGA = (CBV, TMC)
KLS = (TSM, SFR)
PFQ = (FGJ, QPD)
MKJ = (JLT, MLP)
MFX = (RVK, NSF)
QNJ = (KXT, CMK)
QBV = (NSP, TVN)
MSR = (KLG, XNL)
NSF = (QLH, MKJ)
DKQ = (JDR, DQQ)
PLH = (RVK, NSF)
JKG = (BQB, KTK)
LVM = (MKM, TJS)
QLJ = (VPT, BRF)
FVH = (RRX, RQD)
MJX = (DCT, GBH)
QLH = (MLP, JLT)
NPB = (XMT, NXT)
HDL = (CCQ, GTS)
JPS = (DCB, DCB)
CQN = (QPF, BCS)
GNP = (DSD, RQN)
JLK = (MJX, VSG)
PMS = (DTL, VFJ)
BFS = (JGS, TDT)
XJH = (VGD, HGC)
VRF = (SFH, FFJ)
BCK = (SMS, TVR)
DRT = (QFP, MVF)
PND = (DSD, RQN)
VSG = (GBH, DCT)
VGV = (JKM, GXF)
FHD = (MXT, FQC)
GPP = (QRN, QCK)
BDX = (CLN, PHJ)
LLF = (HQT, DCL)
DXA = (HFN, KDR)
MCV = (DHM, PMS)
NTM = (HMN, THX)
JLC = (RDP, VRN)
HQV = (BCF, CCX)
NDN = (QTS, GXP)
QVJ = (DDS, XSF)
MQJ = (RPH, QPK)
FGJ = (KRF, JRV)
LHN = (BFK, RPD)
MXH = (RHV, RHV)
HGC = (DNN, PQT)
MHM = (XFJ, JQF)
JGD = (JGF, GGD)
FCX = (JGC, CGD)
GCS = (LST, QTN)
RCX = (BSL, MQL)
XGJ = (VCT, JRK)
SXB = (FJJ, PRH)
LRG = (XMT, NXT)
XSF = (LRP, RGT)
DNP = (CSQ, RQL)
RKL = (VGB, JRQ)
KVX = (CSP, RRF)
JPD = (FGP, GNS)
GNC = (MGN, CFV)
PFR = (MHS, FRT)
DCK = (LMJ, FRP)
KKP = (TQF, QKP)
XQL = (GMG, LRN)
QCL = (TJK, XCF)
TVP = (XRD, QLG)
HDR = (QPN, PGG)
HLN = (BHQ, SSG)
GGS = (VCT, JRK)
SJN = (HHS, XDL)
DBB = (BHK, KSX)
QPK = (MFX, PLH)
MBF = (NLT, GGB)
BDB = (TDV, JLK)
KSC = (NKN, NTQ)
CPN = (HDB, VPL)
TVB = (RGQ, CCF)
VJX = (NNM, QVJ)
FBT = (JLL, LMR)
TVR = (GJV, LSC)
RNX = (KRH, VGN)
RPH = (MFX, PLH)
VJA = (JBC, XFB)
CLS = (JLL, LMR)
PSJ = (DKF, MSL)
QLG = (PBQ, HMH)
DXJ = (HNG, RBG)
XFB = (KTX, QQG)
TJJ = (FBT, CLS)
KFC = (JRF, JRF)
XFJ = (JJD, VDM)
RCT = (TDH, JGD)
RNH = (BGM, MJV)
VGD = (PQT, DNN)
KQC = (JFJ, CBC)
PPL = (JSJ, KSS)
HCR = (DRT, SSV)
XLJ = (PJR, QBK)
PTH = (QVH, VHX)
RQF = (KLR, KLR)
MSL = (MVR, QQB)
NRJ = (PGM, JJT)
JLL = (KQJ, KQJ)
DCL = (BPS, SSN)
GTS = (MNT, PDJ)
BXR = (NMX, BJX)
CBL = (PND, GNP)
VXK = (JJQ, JTK)
BSL = (RHP, KSB)
NJL = (SJG, CGS)
DQQ = (XHX, VVX)
SQQ = (BHK, KSX)
KTX = (BVK, HLN)
QCK = (XSL, MMP)
SVC = (GSC, XKH)
BGV = (MXH, MRH)
GMG = (QRM, FMC)
KGJ = (NLT, GGB)
LRF = (QLR, CKB)
CMN = (RCX, MQC)
CGD = (JGM, PFR)
LCD = (JSJ, KSS)
HDG = (BPP, KNK)
DDS = (LRP, RGT)
LRM = (DQQ, JDR)
CMH = (CBC, JFJ)
GQH = (TDT, JGS)
BKG = (RTL, XLC)
RMR = (VRN, RDP)
MGK = (XVD, HJH)
FJS = (VTT, VPQ)
SFH = (CTQ, QCL)
XHN = (XQL, XMM)
BPA = (CRJ, FJF)
XCF = (VGL, LGR)
TBM = (MSL, DKF)
JLR = (LST, QTN)
QFJ = (HVQ, QCJ)
CCQ = (MNT, PDJ)
VGN = (PXB, BHN)
LTB = (QLV, NRT)
DCH = (MXT, FQC)
CFG = (PTH, GSL)
JRF = (KXF, KXF)
QRM = (CPV, GBC)
XTX = (BTL, GQS)
FHX = (SBD, RJF)
FHF = (KSR, XFF)
CSM = (NSL, XQG)
HCP = (MMT, KLS)
DJK = (XDT, XLJ)
QLC = (CVF, RQG)
MLJ = (HQT, DCL)
CLM = (JCC, FJS)
NQC = (HXV, FVH)
RDD = (DTB, VGR)
RPN = (DQC, DHG)
GSL = (QVH, VHX)
FGG = (NMX, BJX)
BPJ = (RPJ, HBT)
RBG = (NJB, JVV)
FJF = (SGC, RNH)
GGD = (CFB, NMC)
QQG = (HLN, BVK)
MVF = (RLP, RSF)
JGM = (MHS, FRT)
RMB = (JRF, LMH)
VDM = (HFL, NRP)
HNG = (NJB, JVV)
MJV = (CJN, NRJ)
DNN = (PQX, TRS)
JDR = (XHX, VVX)
KGF = (HDB, VPL)

33
2023/day9/day9.py Normal file
View File

@ -0,0 +1,33 @@
def parse_input(infile):
with open(infile) as f:
return [[int(x) for x in l.strip().split()] for l in f.readlines()]
def process_line(line):
if set(line) == {0}:
return 0
else:
next_line = [cur - next for next, cur in zip(line, line[1:])]
return line[-1] + process_line(next_line)
def process_line_back(line):
if set(line) == {0}:
return 0
else:
next_line = [cur - next for next, cur in zip(line, line[1:])]
return line[0] - process_line_back(next_line)
def solve(data):
print(f"Part 1: {sum(process_line(l) for l in data)}")
print(f"Part 2: {sum(process_line_back(l) for l in data)}")
if __name__ == "__main__":
import sys
import os
SCRIPTPATH = os.path.dirname(os.path.realpath(__file__))
infile = sys.argv[1] if len(sys.argv) == 2 else "example.txt"
data = parse_input(os.path.join(SCRIPTPATH, infile))
solve(data)

3
2023/day9/example.txt Normal file
View File

@ -0,0 +1,3 @@
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45

200
2023/day9/input.txt Normal file
View File

@ -0,0 +1,200 @@
10 13 27 64 140 281 549 1101 2294 4858 10201 21027 42709 86382 175728 361360 750462 1566611 3268603 6783010 13951998
19 34 52 73 97 124 154 187 223 262 304 349 397 448 502 559 619 682 748 817 889
17 26 44 90 198 421 827 1483 2426 3639 5103 7110 11251 22954 57394 152565 397364 990709 2363587 5425543 12050149
23 34 55 94 159 267 456 809 1511 2974 6087 12696 26528 54998 112755 228528 457939 906582 1769955 3399902 6411185
13 27 44 66 106 212 497 1166 2538 5079 9491 16942 29573 51480 90442 160750 287587 513515 907742 1578970 2692764
1 8 28 76 172 354 716 1490 3198 6915 14720 30485 61283 119915 229408 430889 797095 1455082 2623652 4673906 8225526
-3 5 16 26 37 58 110 243 573 1347 3044 6520 13205 25360 46402 81305 137085 223377 353112 543302 815941
20 44 95 198 403 806 1585 3064 5819 10840 19770 35271 61655 106168 181980 315548 564578 1060004 2098881 4338784 9183751
11 17 29 64 153 350 754 1553 3099 6023 11399 20966 37417 64764 108788 177583 282203 437421 662609 982748 1429577
15 23 43 95 224 524 1173 2494 5085 10107 19900 39256 78000 156163 314217 632971 1271436 2537313 5015496 9797973 18888265
-3 -6 -10 -3 44 181 485 1069 2097 3823 6706 11715 21054 39774 79253 164654 350909 756900 1637990 3538025 7603072
15 24 39 60 85 117 188 413 1095 2925 7376 17500 39539 86134 182650 379673 778035 1579706 3192165 6441832 13004669
6 18 40 82 177 389 822 1635 3067 5473 9380 15629 25852 43976 80372 162060 355758 816973 1890831 4315400 9629275
0 -9 -23 -29 0 101 310 655 1177 2023 3701 7704 17986 44363 110077 267928 633224 1448352 3204545 6863560 14248490
12 38 85 159 263 397 558 740 934 1128 1307 1453 1545 1559 1468 1242 848 250 -591 -1717 -3173
11 23 53 116 248 519 1041 1963 3448 5650 8761 13288 20862 36099 70366 148812 322789 690925 1433769 2869296 5539872
8 26 56 112 230 481 987 1939 3625 6508 11475 20557 38782 78504 168755 374185 831386 1815370 3856374 7937866 15821706
13 10 11 17 25 35 61 149 409 1085 2731 6646 15861 37180 85069 188576 402965 828372 1638555 3123727 5752545
9 6 11 34 97 250 604 1397 3129 6850 14770 31483 66259 137080 277451 547674 1053553 1977942 3634997 6564680 11697717
10 23 53 115 238 476 937 1850 3695 7426 14822 29006 55177 101605 180944 311923 521480 847409 1341595 2073917 3136904
5 17 52 132 288 568 1063 1960 3637 6820 12825 23910 43766 78187 135984 230256 380213 613875 972162 1515160 2331716
-3 5 23 69 176 392 780 1418 2399 3831 5837 8555 12138 16754 22586 29832 38705 49433 62259 77441 95252
13 23 36 69 156 357 771 1566 3045 5782 10898 20613 39315 75556 145710 280790 539833 1037897 2007196 3931949 7840962
13 33 72 142 264 476 847 1512 2768 5305 10692 22314 47112 98827 204221 415374 834390 1662953 3300286 6532935 12895485
3 2 -4 -7 13 102 361 994 2396 5340 11385 23712 48683 98459 194909 374637 694045 1231738 2083182 3339595 5040493
24 37 47 45 29 16 54 234 702 1671 3433 6371 10971 17834 27688 41400 59988 84633 116691 157705 209417
7 9 24 70 168 340 608 1002 1608 2736 5382 12318 30388 74926 177641 399813 853169 1731287 3354704 6232938 11146188
13 19 40 84 171 353 740 1531 3047 5761 10318 17536 28377 43875 65006 92483 126457 166103 209068 250756 283423
21 38 72 129 215 336 498 707 969 1290 1676 2133 2667 3284 3990 4791 5693 6702 7824 9065 10431
-2 15 47 94 156 233 325 432 554 691 843 1010 1192 1389 1601 1828 2070 2327 2599 2886 3188
28 41 54 81 162 373 841 1771 3487 6485 11506 19691 33041 55803 98311 186795 386856 856817 1963836 4527177 10310638
-5 7 33 73 127 195 277 373 483 607 745 897 1063 1243 1437 1645 1867 2103 2353 2617 2895
14 29 42 48 48 56 119 366 1104 2996 7403 17064 37440 79275 163244 327980 643314 1231239 2297936 4181192 7418712
22 36 66 125 242 472 911 1740 3342 6559 13177 26736 53745 105331 199283 362432 633466 1066806 1739272 2763059 4310832
2 0 -2 -4 -6 -8 -10 -12 -14 -16 -18 -20 -22 -24 -26 -28 -30 -32 -34 -36 -38
18 25 43 101 251 576 1198 2286 4064 6819 10909 16771 24929 36002 50712 69892 94494 125597 164415 212305 270775
24 41 62 89 137 245 493 1033 2146 4346 8583 16683 32370 63687 128687 268561 577177 1265569 2797915 6167557 13435492
10 23 59 142 319 664 1287 2355 4126 6987 11474 18238 27920 40958 57585 78915 111446 180159 360593 849158 2105337
5 0 -3 -5 -15 -47 -106 -146 40 1067 4438 13380 34212 78563 167101 336150 649903 1223206 2263499 4145957 7543779
16 38 69 109 158 216 283 359 444 538 641 753 874 1004 1143 1291 1448 1614 1789 1973 2166
16 30 55 90 128 156 159 130 90 140 615 2498 8391 24556 64904 158512 363744 795381 1678545 3459099 7033146
0 17 56 133 268 479 772 1138 1582 2223 3518 6677 14350 31681 67838 138142 266932 491317 865980 1469213 2410376
9 14 18 23 44 138 451 1290 3237 7336 15399 30489 57642 104880 184536 314852 521713 840234 1315712 2003179 2964432
11 10 18 56 159 387 844 1703 3235 5840 10078 16698 26663 41169 61656 89809 127547 176998 240458 320332 419055
12 22 46 111 273 640 1418 2991 6045 11748 22003 39799 69696 118494 196153 317051 501690 778986 1189308 1788463 2652859
9 20 46 93 169 298 556 1147 2553 5815 13032 28202 58573 116723 223646 413186 738233 1279174 2155178 3538987 5675985
17 27 31 26 8 -28 -88 -179 -309 -487 -723 -1028 -1414 -1894 -2482 -3193 -4043 -5049 -6229 -7602 -9188
3 10 17 23 29 45 101 260 633 1406 2914 5844 11725 23975 49930 104485 216239 437362 858799 1632901 3006133
10 8 8 28 102 295 731 1632 3366 6511 11973 21266 37189 65337 117179 215849 406358 772694 1465306 2743876 5042228
10 24 52 108 211 389 690 1212 2176 4085 8041 16334 33475 67922 134847 260416 488206 888566 1571946 2707472 4548339
23 46 74 102 132 190 360 846 2086 4965 11207 24069 49513 98095 187883 348799 628873 1103000 1884904 3143136 5122066
-1 6 32 102 264 611 1309 2632 5004 9057 15753 26720 45185 78396 143498 281002 584247 1261461 2762805 6035330 13028230
23 40 75 153 321 670 1385 2844 5793 11630 22837 43605 80703 144648 251239 423524 694275 1109052 1729943 2640073 3948981
15 25 33 46 80 167 367 787 1614 3183 6133 11763 22795 44891 89465 178588 353113 685557 1299777 2400076 4313082
13 32 58 102 196 405 841 1677 3159 5614 9452 15160 23286 34411 49107 67879 91089 118860 150958 186650 224536
10 21 51 112 231 474 985 2040 4116 7975 14763 26124 44329 72420 114369 175252 261438 380793 542899 759288 1043691
12 33 57 95 176 359 763 1632 3463 7247 14924 30272 60710 121017 240939 480350 958458 1908109 3773455 7380505 14227480
17 26 49 105 238 534 1144 2317 4455 8221 14772 26271 46982 85505 159107 301701 577877 1106564 2099475 3921541 7183166
-7 0 20 61 139 279 523 962 1815 3588 7363 15297 31469 63337 124349 238908 452432 852898 1618891 3129293 6215242
30 60 106 166 244 363 592 1102 2271 4874 10429 21829 44475 88235 170685 322233 593876 1068480 1876588 3217832 5389030
25 34 38 29 -6 -85 -231 -472 -841 -1376 -2120 -3121 -4432 -6111 -8221 -10830 -14011 -17842 -22406 -27791 -34090
14 27 64 140 270 469 752 1134 1630 2255 3024 3952 5054 6345 7840 9554 11502 13699 16160 18900 21934
3 3 2 -2 -10 -23 -34 18 380 1774 5941 16569 40769 91302 189803 371295 690337 1229205 2108564 3501152 5649064
11 27 63 132 250 436 723 1190 2024 3624 6767 12869 24390 45446 82694 146534 252605 423413 689683 1090630 1671742
10 21 43 84 174 383 853 1859 3938 8162 16688 33820 68032 135885 269855 534392 1059114 2106599 4207317 8419480 16811962
4 8 20 39 64 94 128 165 204 244 284 323 360 394 424 449 468 480 484 479 464
14 32 62 100 152 246 451 914 1930 4064 8348 16580 31756 58670 104721 180970 303494 495088 787370 1223348 1860512
24 36 57 108 225 475 977 1923 3594 6366 10701 17118 26139 38205 53557 72077 93084 115080 135441 150048 152853
8 30 64 111 189 360 771 1716 3739 7818 15697 30467 57538 106192 191962 340144 590818 1005830 1678270 2745071 4403451
19 26 41 67 115 229 536 1331 3207 7240 15239 30071 56071 99547 169390 277799 441131 680886 1024837 1508315 2175659
12 31 72 154 300 536 888 1386 2103 3281 5625 10880 22845 49022 103147 208904 405182 753299 1346686 2323598 3883498
14 33 55 75 87 84 58 0 -100 -253 -471 -767 -1155 -1650 -2268 -3026 -3942 -5035 -6325 -7833 -9581
18 18 14 9 5 10 67 329 1226 3800 10322 25351 57449 121828 244275 466779 855370 1510774 2582590 4287805 6934581
11 26 67 162 365 774 1563 3031 5671 10277 18150 31560 54814 96640 175240 328510 634023 1247352 2475005 4913050 9710375
10 12 21 49 125 306 694 1465 2935 5720 11101 21812 43698 89177 184454 384515 804128 1681341 3505647 7271462 14966863
3 7 8 7 5 3 2 3 7 15 28 47 73 107 150 203 267 343 432 535 653
7 22 61 136 259 442 697 1036 1471 2014 2677 3472 4411 5506 6769 8212 9847 11686 13741 16024 18547
2 9 21 39 72 152 353 825 1866 4069 8597 17657 35264 68408 128761 235087 416546 717113 1201365 1961923 3128872
-1 -9 -21 -43 -89 -180 -326 -472 -384 561 3748 11992 30761 70471 150894 309768 619705 1221143 2385397 4632275 8943215
23 52 99 163 235 306 400 654 1471 3780 9454 21971 47481 96644 188123 355863 665091 1247984 2382457 4663003 9363499
-5 -8 -13 -23 -40 -64 -92 -111 -72 193 1206 4443 13762 38657 101444 252655 602917 1386566 3083809 6646613 13901608
-1 -5 3 40 139 377 928 2149 4706 9750 19171 36016 65299 115731 203485 360222 649705 1201404 2277721 4408645 8664071
22 29 51 104 202 350 529 676 665 294 -722 -2761 -6329 -12159 -21434 -36219 -60216 -99989 -166843 -279582 -468416
12 31 57 90 149 301 705 1683 3848 8355 17405 35234 69972 136982 264623 503889 944168 1738619 3144657 5588178 9765043
3 6 17 54 145 328 651 1172 1959 3090 4653 6746 9477 12964 17335 22728 29291 37182 46569 57630 70553
20 47 88 143 212 295 392 503 628 767 920 1087 1268 1463 1672 1895 2132 2383 2648 2927 3220
11 14 24 51 99 172 295 560 1216 2832 6583 14759 31696 65486 131013 254962 483123 888785 1576642 2666148 4215487
5 28 69 136 250 453 812 1413 2334 3583 5005 6234 6941 7983 14726 45075 147219 437194 1177122 2937595 6934002
-3 -1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37
23 47 92 168 290 484 790 1270 2052 3476 6455 13223 28713 62891 134467 276511 544621 1028421 1867310 3271538 5549852
5 8 25 63 129 230 373 565 813 1124 1505 1963 2505 3138 3869 4705 5653 6720 7913 9239 10705
7 4 -4 -18 -39 -68 -106 -154 -213 -284 -368 -466 -579 -708 -854 -1018 -1201 -1404 -1628 -1874 -2143
8 22 47 86 140 213 338 647 1519 3852 9518 22074 47817 97287 187339 343923 605730 1028882 1692865 2707926 4224178
8 7 20 67 186 446 975 2011 3989 7695 14557 27226 50783 95304 181324 351286 692830 1384471 2781802 5574133 11059128
0 17 56 127 240 405 632 931 1312 1785 2360 3047 3856 4797 5880 7115 8512 10081 11832 13775 15920
9 7 5 3 1 -1 -3 -5 -7 -9 -11 -13 -15 -17 -19 -21 -23 -25 -27 -29 -31
18 27 50 102 215 449 903 1726 3128 5391 8880 14054 21477 31829 45917 64686 89230 120803 160830 210918 272867
2 6 24 80 226 564 1280 2708 5456 10649 20394 38681 73153 138584 263617 503538 963971 1844077 3514433 6656595 12512437
21 31 38 50 89 195 439 964 2083 4473 9514 19832 40115 78281 147087 266278 465385 787291 1292694 2065606 3220037
27 44 68 103 157 254 450 847 1602 2948 5302 9667 18798 40080 91876 216401 504165 1137956 2468512 5139831 10289931
12 16 15 10 8 26 103 329 914 2351 5782 13764 31764 70901 152714 317085 634904 1227650 2296801 4166902 7347240
24 40 66 108 186 352 726 1577 3503 7817 17343 37986 81677 171612 351112 698024 1347788 2531473 4643823 8378986 15025772
18 24 33 60 146 376 917 2087 4466 9061 17542 32590 58476 102196 175971 302974 530317 957661 1798344 3506829 7040265
26 54 90 124 146 164 233 506 1327 3392 8018 17601 36452 72475 140829 272293 532468 1064838 2183738 4566562 9634194
2 12 36 85 187 410 895 1906 3927 7876 15570 30669 60453 118946 232119 446279 841554 1554212 2815554 5023317 8877249
11 38 85 165 304 547 972 1729 3140 5939 11821 24642 52934 114998 248951 532138 1117933 2304140 4657409 9234315 17964728
19 31 43 55 67 79 91 103 115 127 139 151 163 175 187 199 211 223 235 247 259
13 26 59 122 223 375 619 1082 2112 4569 10405 23745 52808 113245 233970 467633 910119 1737872 3280091 6157476 11543989
9 23 59 125 224 354 511 698 943 1328 2029 3364 5842 10201 17417 28659 45157 67941 97399 132591 170244
18 33 50 65 85 140 299 710 1707 4075 9657 22645 52146 117004 254495 535614 1091707 2161171 4173032 7901130 14758416
9 20 40 84 183 394 810 1570 2869 4968 8204 13000 19875 29454 42478 59814 82465 111580 148464 194588 251599
19 30 47 75 111 153 223 409 933 2265 5347 12093 26525 57232 122347 258981 540095 1103200 2197127 4255487 8008435
2 -1 -7 -20 -48 -107 -210 -317 -212 745 4082 13075 34379 81200 179516 380139 781514 1571431 3100731 6009170 11433534
27 53 97 166 267 415 665 1188 2416 5280 11555 24318 48566 92259 168738 303202 549777 1033491 2046105 4250726 9094061
26 39 52 65 78 91 104 117 130 143 156 169 182 195 208 221 234 247 260 273 286
23 28 30 29 28 40 113 386 1196 3278 8149 18863 41505 88134 182530 371286 744869 1476728 2893904 5600425 10685362
-3 10 52 137 290 559 1027 1829 3186 5487 9496 16849 31158 60316 121168 248972 516815 1075808 2237856 4642837 9586726
14 28 52 96 173 311 577 1118 2238 4549 9257 18670 37043 71904 136034 250302 447582 778002 1315794 2168028 3485521
12 10 19 69 218 566 1268 2541 4663 7985 13046 21042 35235 64539 131731 290932 662942 1504036 3336277 7189251 15040904
21 40 75 145 291 595 1212 2420 4707 8937 16660 30642 55676 99679 174968 299426 497005 796658 1228341 1814179 2552253
5 -1 -9 -10 7 57 170 418 964 2142 4591 9507 19185 38292 76948 158114 334787 728489 1611871 3578712 7879983
15 30 54 91 156 290 575 1149 2221 4086 7140 11895 18994 29226 43541 63065 89115 123214 167106 222771 292440
26 36 60 112 205 351 561 845 1212 1670 2226 2886 3655 4537 5535 6651 7886 9240 10712 12300 14001
2 7 25 83 215 469 935 1803 3460 6635 12601 23443 42401 74297 126055 207323 331206 515119 781769 1160275 1687435
17 39 74 124 191 277 384 514 669 851 1062 1304 1579 1889 2236 2622 3049 3519 4034 4596 5207
-3 -9 -11 7 67 194 414 759 1296 2216 4046 8082 17184 37125 78745 161228 316895 597989 1086019 1904329 3234665
8 16 23 27 22 -2 -59 -167 -348 -628 -1037 -1609 -2382 -3398 -4703 -6347 -8384 -10872 -13873 -17453 -21682
19 41 88 184 364 671 1148 1819 2652 3500 4020 3570 1086 -5013 -16635 -34647 -53835 -48048 68522 534603 1954552
17 35 62 94 123 145 181 319 796 2164 5632 13759 31806 70256 149301 306498 609339 1175193 2201994 4014204 7130013
13 20 27 34 41 48 55 62 69 76 83 90 97 104 111 118 125 132 139 146 153
7 -3 -15 -19 2 72 222 490 921 1567 2487 3747 5420 7586 10332 13752 17947 23025 29101 36297 44742
16 24 32 51 122 332 835 1897 4000 8054 15770 30238 56744 103886 185183 321730 547208 917948 1533084 2573509 4373862
-7 3 40 115 232 388 578 804 1097 1595 2790 6175 15700 40696 101260 237524 524769 1097003 2182412 4155027 7608040
-1 16 47 92 164 316 689 1594 3644 7967 16584 33176 64775 125542 245009 485472 977581 1991294 4074185 8315444 16839374
23 38 62 115 228 453 880 1663 3063 5522 9788 17117 29584 50541 85266 141853 232399 374550 593474 924335 1415348
21 43 84 161 309 589 1103 2028 3681 6627 11842 20943 36497 62421 104485 170930 273213 426891 652656 977533 1436253
-1 0 22 77 169 303 511 910 1829 4073 9445 21749 48689 105416 221026 450160 893099 1729494 3273248 6059213 10976433
-9 -12 -16 -21 -26 -25 13 196 824 2622 7193 17896 41579 92080 197440 414961 862813 1786164 3693918 7636129 15753420
15 19 18 5 -35 -133 -334 -656 -953 -581 2306 12127 38432 100587 236346 517687 1080427 2180027 4296650 8331021 15963515
15 31 54 79 116 218 529 1357 3275 7265 14970 29255 55600 105551 204889 411927 856335 1817519 3875878 8193119 17013220
17 38 86 173 311 512 788 1151 1613 2186 2882 3713 4691 5828 7136 8627 10313 12206 14318 16661 19247
15 29 65 148 318 630 1167 2088 3740 6868 12960 24765 47021 87427 157888 276055 467173 766239 1220459 1891978 2860840
13 20 40 94 216 459 901 1657 2924 5130 9334 18141 37563 80483 172673 362688 737415 1445608 2732396 4988520 8818946
10 14 40 102 214 390 644 990 1442 2014 2720 3574 4590 5782 7164 8750 10554 12590 14872 17414 20230
-2 2 18 69 188 421 841 1589 2968 5626 10874 21195 41010 77777 143509 256807 445514 750106 1227946 1958537 3049920
5 14 32 74 162 325 599 1027 1659 2552 3770 5384 7472 10119 13417 17465 22369 28242 35204 43382 52910
-3 -3 12 62 189 478 1087 2286 4500 8343 14633 24427 39268 62169 100447 172395 320864 637864 1304863 2653271 5249412
18 37 78 157 301 564 1062 2032 3928 7589 14553 27650 52089 97362 180425 330785 598326 1064949 1861384 3190859 5361685
24 49 85 135 203 294 426 663 1178 2355 4939 10243 20421 38816 70392 122259 204300 329909 516849 788239 1173679
-6 6 27 49 55 28 -24 -23 259 1359 4471 12225 30376 71273 160582 349623 736928 1504324 2975091 5704649 10617909
22 34 46 58 70 82 94 106 118 130 142 154 166 178 190 202 214 226 238 250 262
-1 11 38 85 175 375 843 1901 4147 8641 17247 33319 63167 119310 227777 444324 889598 1823128 3794302 7941695 16571260
14 21 44 93 193 395 795 1581 3146 6327 12848 26059 52098 101731 193492 359603 657898 1196185 2180968 4011313 7452315
12 14 25 58 144 353 838 1924 4272 9156 18899 37522 71668 131871 234248 402700 671716 1089882 1724205 2665370 4034056
-7 -4 2 8 24 88 285 785 1940 4520 10226 22707 49462 105293 218500 441937 872607 1685968 3194942 5949254 10898776
9 15 27 45 69 99 135 177 225 279 339 405 477 555 639 729 825 927 1035 1149 1269
1 7 18 33 56 109 254 618 1427 3089 6443 13441 28783 63396 141114 310383 663073 1362143 2678340 5032341 9031334
8 30 62 96 130 188 356 843 2075 4824 10363 20622 38299 66854 110283 172533 256378 361530 481708 600332 684448
16 33 68 127 220 368 624 1130 2258 4917 11148 25171 55086 115463 231105 442406 813124 1442381 2484872 4187559 6958992
19 46 82 129 190 262 327 341 221 -170 -1040 -2687 -5520 -10082 -17075 -27387 -42121 -62626 -90530 -127775 -176654
10 24 54 110 204 349 564 899 1500 2745 5512 11728 25576 56253 124229 275003 608250 1337779 2912588 6259085 13264076
17 23 29 41 78 187 464 1081 2324 4661 8898 16588 31128 60596 124667 270430 606415 1371815 3070427 6718531 14285838
22 32 42 52 62 72 82 92 102 112 122 132 142 152 162 172 182 192 202 212 222
-5 -2 14 47 110 246 558 1248 2665 5362 10162 18233 31172 51098 80754 123618 184023 267286 379846 529411 725114
11 14 14 12 17 45 109 196 228 5 -871 -3091 -7752 -16486 -31602 -56237 -94511 -151680 -234280 -350254 -509053
8 25 62 147 337 733 1495 2857 5142 8777 14308 22415 33927 49837 71317 99733 136660 183897 243482 317707 409133
-1 2 22 77 206 494 1107 2337 4657 8786 15764 27037 44552 70862 109241 163809 239667 343042 481442 663821 900754
24 50 87 141 235 417 780 1509 2981 5974 12102 24700 50566 103297 209592 421173 837594 1650633 3232271 6311824 12336389
3 4 0 -11 -31 -62 -106 -165 -241 -336 -452 -591 -755 -946 -1166 -1417 -1701 -2020 -2376 -2771 -3207
26 56 103 171 263 374 481 535 462 192 -233 -348 1536 10273 38409 116432 315337 794905 1904134 4384770 9774416
6 11 29 74 169 361 747 1512 2977 5651 10278 17870 29722 47417 72850 108332 156880 222859 313219 439666 622223
23 48 87 144 228 356 556 870 1357 2096 3189 4764 6978 10020 14114 19522 26547 35536 46883 61032 78480
7 15 30 59 118 247 531 1134 2358 4744 9237 17442 32003 57142 99400 168627 279273 452037 715936 1110861 1690692
10 20 35 72 171 399 849 1634 2876 4690 7163 10328 14133 18405 22809 26802 29582 30032 26659 17528 191
17 24 41 86 185 378 726 1315 2257 3693 5819 9007 14216 24133 45917 97130 217557 491334 1086409 2322292 4782951
28 50 92 173 315 552 963 1749 3391 6963 14740 31356 65972 136277 275762 546694 1062683 2026717 3792870 6961951 12521696
19 33 62 123 238 445 831 1611 3295 7007 15059 31967 66268 133815 263764 509311 966491 1806133 3326508 6037459 10791026
10 33 62 103 170 279 432 598 711 726 824 1981 7389 25746 78354 213440 533320 1243135 2734058 5719219 11447172
14 38 84 172 346 686 1315 2398 4130 6710 10298 14952 20542 26638 32369 36250 35974 28166 8096 -30652 -96558
-4 -7 4 44 142 351 756 1480 2700 4708 8097 14248 26490 52673 110540 238385 515388 1099471 2297118 4692616 9389926
0 6 25 74 182 400 827 1669 3375 6951 14655 31438 67733 144521 302035 614015 1210114 2309892 4272837 7670034 13384480
4 4 19 61 137 257 453 819 1604 3423 7695 17472 38889 83542 172189 340268 645836 1180654 2085275 3569135 5936801
23 35 63 126 262 545 1119 2269 4556 9053 17729 34038 63788 116413 206897 358912 610506 1025617 1719513 2917815 5094961
-2 2 18 53 121 253 507 978 1808 3196 5408 8787 13763 20863 30721 44088 61842 84998 114718 152321 199293
7 30 82 181 345 604 1027 1764 3103 5542 9876 17299 29521 48900 78589 122698 186471 276478 400822 569361 793945
2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18
9 27 62 117 209 384 732 1402 2617 4689 8034 13187 20817 31742 46944 67584 95017 130807 176742 234849 307409
14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54
4 -2 2 38 132 311 614 1135 2124 4178 8555 17641 35601 69268 129400 232611 404624 686090 1143180 1886628 3105054
23 43 65 96 152 251 408 637 979 1607 3116 7197 18033 44964 107278 242436 519683 1061911 2079959 3925518 7171954
19 30 48 82 149 279 533 1042 2082 4223 8630 17649 35876 71974 141561 271527 506133 915180 1604388 2727868 4502175
-2 10 28 49 82 163 379 902 2034 4263 8331 15326 26840 45287 74538 121073 195819 316657 511115 817796 1283175
-1 6 21 56 143 340 732 1425 2531 4142 6291 8898 11699 14156 15346 13827 7479 -6682 -32719 -76020 -143577
-2 5 31 87 183 346 655 1303 2709 5736 12147 25576 53541 111459 230443 472374 959476 1933664 3877553 7761688 15543715
17 21 35 67 125 217 351 535 777 1085 1467 1931 2485 3137 3895 4767 5761 6885 8147 9555 11117
3 -3 -10 -3 61 271 784 1851 3847 7305 12954 21761 34977 54187 81364 118927 169803 237493 326142 440613 586565
9 14 23 31 27 -4 -60 -59 296 1760 5938 15871 36864 77606 151633 279185 489507 823642 1337761 2107071 3230337
2 -3 -6 -2 32 164 541 1440 3358 7187 14584 28795 56492 111724 223987 453837 921594 1857745 3687926 7171172 13617848
11 12 28 74 163 318 608 1232 2687 6079 13683 29941 63217 128815 254019 486241 905771 1645118 2917518 5057868 8580127
6 10 30 80 170 314 561 1060 2170 4641 9947 20986 43640 90222 186816 388245 807350 1670120 3415956 6874320 13566998