Compare commits

..

11 Commits

Author SHA1 Message Date
Dmitry Fedotov
88def4674b addition 2025-03-22 18:38:32 +03:00
Dmitry Fedotov
b0a982c64d refactor part 1 2024-01-05 04:44:15 +03:00
Dmitry Fedotov
ef41b90bec day 10 part one 2024-01-05 00:40:13 +03:00
Dmitry Fedotov
1e2477c4f6 add day 8 part one 2024-01-04 18:11:12 +03:00
Dmitry Fedotov
31b6a2fdbd add day 9 2024-01-04 18:03:33 +03:00
Dmitry Fedotov
3db681e55b half of day7 2024-01-03 15:11:01 +03:00
Dmitry Fedotov
79b7391d1e add day6 2023-12-17 13:07:02 +03:00
Dmitry Fedotov
143c00fc60 rm unused file 2023-12-17 12:20:27 +03:00
Dmitry Fedotov
0969cc1c42 add README.md explaining why two versions 2023-12-17 12:01:36 +03:00
Dmitry Fedotov
1ab7137882 add day5 2023-12-17 11:51:39 +03:00
Dmitry Fedotov
14e3008925 fix: optimize code 2023-12-16 14:56:58 +03:00
31 changed files with 3957 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
lib/__pycache__

194
day10/day10.py Normal file
View File

@@ -0,0 +1,194 @@
import sys
sys.path.append('../lib')
import tools
START = 'S'
class Direction(object):
def __init__(self, val: str):
self.val = val
def __eq__(self, other):
return self.val == other.val
def __hash__(self):
return hash(self.val)
def opposite(self):
if self == N:
return S
elif self == S:
return N
elif self == E:
return W
elif self == W:
return E
N = Direction('N')
E = Direction('E')
S = Direction('S')
W = Direction('W')
class Tile(object):
def __init__(self, val: str, x, y):
self.val = val
self.x = x
self.y = y
self.links = []
if val == '|':
self.links = [N, S]
elif val == '-':
self.links = [E, W]
elif val == 'L':
self.links = [N, E]
elif val == 'J':
self.links = [N, W]
elif val == '7':
self.links = [W, S]
elif val == 'F':
self.links = [S, E]
def __str__(self):
return f'{self.val}' # x: {self.x} y: {self.y}'
def __eq__(self, obj) -> bool:
return self.x == obj.x and self.y == obj.y
def __hash__(self):
return hash((self.x, self.y))
def opposite_pipe_end(self, d: Direction) -> Direction:
if not d in self.links:
return None
if d == self.links[0]:
return self.links[1]
else:
return self.links[0]
def has_link_from(self, d: Direction) -> bool:
return (d in self.links)
class Field(object):
def __init__(self, lines: list[str]):
self.grid = [list(l) for l in lines]
for y in range(len(self.grid)):
for x in range(len(self.grid[0])):
self.grid[y][x] = Tile(self.grid[y][x], x, y)
def __str__(self):
out = 'Field:\n'
for row in self.grid:
out += ''.join([str(tile) for tile in row]) + '\n'
return out
def _get(self, x, y: int) -> Tile:
if y < 0 or x < 0 or y >= len(self.grid) or x >= len(self.grid):
return None
return self.grid[y][x]
def get_adjacent(self, t: Tile, d: Direction) -> Tile:
x, y = t.x, t.y
if d == E:
x += 1
elif d == S:
y += 1
elif d == W:
x -= 1
elif d == N:
y -= 1
return self._get(x, y)
class Walker(Field):
def __init__(self, lines):
super().__init__(lines)
self.loop = []
self.visited = set()
def _get_start(self) -> Tile:
for y in range(len(self.grid)):
for x in range(len(self.grid[0])):
t = self._get(x, y)
if t.val == START:
return t
return None
def _find_loop(self):
start = self._get_start()
for d in [N, E, S, W]:
curr = start
dir = d
self.loop = []
while True:
self.loop.append(curr)
nxt = self.get_adjacent(curr, dir)
if not nxt:
break
if nxt.val == START:
return
if not nxt.has_link_from(dir.opposite()):
break
curr = nxt
dir = nxt.opposite_pipe_end(dir.opposite())
def find_max_steps_in_loop(self) -> int:
self._find_loop()
return len(self.loop) // 2
def find_captured_by_loop(self) -> int:
if not self.loop:
# this fills self.loop slice
# with loop tiles
self._find_loop()
self.visited = set(self.loop)
inside_loop = set()
for t in self.loop:
for d in [N, E, S, W]:
newt = self.get_adjacent(t, d)
if not newt or newt in self.visited:
continue
if self._is_inside_loop(newt, [N, E, S, W]):
inside_loop.add(newt)
self.visited.add(newt)
return len(inside_loop)
def _is_inside_loop(self, t: Tile, dirs: list[Direction]) -> bool:
if not t:
return False
if t in self.loop:
return True
for d in dirs:
newt = self.get_adjacent(t, d)
if not self._is_inside_loop(newt, [d]):
return False
return True
if __name__ == '__main__':
r = tools.Reader('test_input.txt')
lines = r.read()
w = Walker(lines)
print(w)
n = w.find_captured_by_loop()
print(n)
r = tools.Reader('input.txt')
lines = r.read()
w = Walker(lines)
steps = w.find_max_steps_in_loop()
print(steps)
n = w.find_captured_by_loop()
print(n)

140
day10/input.txt Normal file
View File

@@ -0,0 +1,140 @@
7.77F7F|-F.J-J7-LF|-7.FFL7F-L-7--7-JF-7F.LL.7-|FFF7..F-7-J777FF.77.L-FL-7-FF77-L7-F-F--FJFF|-F77F-7F7-.L-FFL-|-7-LJ77F7-F-FJ77.77J.J77F-L77.
F-F-J|FL-J7-L|.L|FJ|LF-7JL|J.|J.||LLJJLJ-.L7F7|L7|L7-L7J.|LJ-JJ-JJ-|F77.|.LLFJLLJ-JFJJF|-F-J7.LL7.J7J-7.7-|.LJFF.|-J7L--|..|-F--J||LF-|7.|-.
FF-JF77.L7--7F--JLF|LL-L-.7-|J-L7|7F|.J.L7.|.-7L-77J.L|.L--7-|..FL7LFJLF|7JLL|||J..|7|7.|L|F|7JFL-JF7-F-|.J-7F7..FJ|||L7F77.FL-|77JL|-FF-||7
|.||L7JFLF7L7.|J|LLJ7JF-JL-7|7-FL7L|J7JF--.|7||-FFJL|F|F|77F-|-|7L--|FLJ|L7.L|-J--.J-|-F|.LJ.-7LLJ7L7F|-F-|7LJ.FF|F||F|.||LF-L-|JL7FL.LLF-77
7F|-|L7JF|7JL.F-7.F-J-FJLJFLJ7J||L-|L--J|J--J|J|F77LF---7-F7F7FF7F|FJ7JLJ.J7F7LF|L7LF.|.LF-77|F-J|JLF7F777F-|J7FFL7|F7LJ777.-7F|.FJJ|7FL||||
L-JJJLJ-FJ-7FJ7FJ-F-7.L7F|F|7F7LJ7FL7|--|F7J.777||F7L-7FJFJ|||F7JF-J|77|L|JFLJ.FJF|7LJ-.F-JFF-J..|77|LJL77J.|LJ7.L--.L7--F-J||J-|L|JF-77LL7J
LL7F--7FJ.F--L77.|FF|-LJJF7-JFJLF77F7J|7FF7F7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F-JF7L---JFJL----JL7LJL----JFJL7||F7L-7||FJLJ|F77L-7FJLJ|FJ|FJLJLJ|L--7L-7FJLF---JF-JFJF7|F--------------7F7L-JL-JF-7FJF7|L7J.|JFL7
LL7.L-7FLJF-JL---7FJF-7F---7L-7F--7F-JF7|||||F7|LJL7F7LJL7F-J|F7F|L7||-F---JF--J7FJL-7|F-7FJF-JFJ||L7F7F------7F-7|||F7F7F7|.|L-J||FJJ.-7|--
..-7LL|7|LL-----7LJFJLLJF-7L-7|L-7|L-7||LJLJ|||L-7FJ||F-7|L-7LJL7L-JLJFJF7F7L--7FJF7FJ||FJ|-L-7|7LJFJ|LJF-----J|FJ|||||||||L7|F--J|||F-JLL-7
-F7F..|J7.LF-7F7L--J-FF7L7|F-J|F-JL--J|L7F--J||F7|L7||L7|L7FJF--JF7F-7L7|LJL7F7|L7|||FJ|L7L-7FJ|F7JL-JF7L-7F7F7|L7LJLJLJ|||FJ|L--7LJ-L7FJJ77
F-7|L7|.F-F|FJ|L----7FJL-J|L-7|L------JFJL7F7|||LJFJ|L7||FJL7L---J||FJJLJF--J|LJFJ|LJ|FJFJF-J|FJ|L----JL--J|||LJFJLF7F-7|||L7L7F-JF7JJLJ7.-7
7LLJ7LJFF--J|FJF---7|L---7|F7||F7F-----JF7LJLJ|L7FL7L7|||L7J|F7F-7LJL---7|F-7L7|L7L-7||LL7L-7||7|F-7F-7F-7F|||F-JF7|||FJLJL-J||L7|||L7J.L-||
L7L|LJ-FL--7|L-JF7J|L----JLJLJLJ|L------JL---7L7|F-JFJ|||FJFJ||L7L7F-7F7|LJ|L7L-7|F-J||F7L7FJ||FJL7LJ-|L7L-JLJL--JLJLJL---7JF7L-JFJL7J-F.-L-
|LFF.|.F---JL7F-JL-JF----------7|F7F-7F------JF||L7FJFJ|LJFJFJ|FJFJL7|||L--7FJF7|||F7LJ|L-JL7|||F-JJF7L-JF-7F-7F7F7F7F7F7FJFJL---JF-JJ.F7.|J
F--F77FL----7|L-----JF---------JLJLJL|L-------7||FJL7L7L7FJFJ-LJJ|F7|LJ|F-7|L7||||LJL-7L7F7FJ|||L7F-JL---J|LJLLJ||LJ||LJLJ7L7F---7L7JF-J|-77
|J-FF-7J.F--JL--7F7F7L7F7F7F7F7F----7|F7F7F--7|LJ|F7L7L7|L7L--7F7LJ|L-7||FJ|-|||||F7F-JL||||FJ|L7|L--7F7F-7F---7LJF7LJJF7F7FJ|F-7L-JFJF-J--J
L|LLL7|FFL-----7|||||FLJLJLJ||||F---J||LJ|L-7|L-7|||FJ7|L7|F7FJ|L7FJF7||||FJFJ|LJ||||F--J|LJL-JLLJF--J|LJFJ|F7FJF-JL--7|LJLJFJ|FJ|JL|FJ7.L|J
LL7-L||F7F7F-7FJLJLJL-7F7F7FJ|LJL7F7|LJF7L--JL--JLJ||F-JFJ|||L-JFJL7|LJLJLJFJFJF-J|||L--7|7F7.F--7L---JF7L-J||L7L7F---J|F---J|||F777||F7F7|J
.LFJL|LJLJ|L7LJF7F---7||||LJFJF7LLJL7F-JL---7FF7F-7LJL7FJFJ||F-7L7FJL---7F7L7L7|F7|||F--JL7|L7L-7||F77FJL---JL-JFJL7F7FJ|F7|F7|||L7FJLJLJL-7
--L7.L7F-7L-JF7|||F77||||L--J|||F7F-JL7F---7L-JLJFJFF-J|FJFJ||-L-JL-7F--J|||L7|LJ||LJL7F7FJL7|-FJL-JL7L----7-F-7|F-J||L7||L-J||||FJ|F---7F7|
|FLJL7LJFL---J||||||FJLJ|F----JLJ|L---JL--7L7F7F7L7FJF7|L7|FJL--7JF7|L---JL7FJL7FJ|F-7||||F7|L7|F-7F7L----7L7L7|||.FJL7|||F--J|||L-JL--7||LJ
FF.FFLFF-----7LJLJ|LJF-7|L----7F7L-------7L7||LJL7|L-JLJ7||L7F-7|FJ||F7F7F7|L7FJL-JL7|||LJ||L7LJL7LJL--7F7L7L7|||L-JF7LJLJ|F--JLJF7F7F7|||J7
L7.-|-FJF---7L----JF7|FJ|F7F--J|L-------7L-JLJF7FLJF-----J|FJ|J|LJFJ||||||LJFJL--7F-JLJ|F-JL-JF-7L7FF--J|L7L7LJLJF-7|L----J|F-7F-JLJ||LJLJ-7
FJJ.F.|FJF--JF-7F--JLJL7LJLJF7FJJF------JF--7FJL7F7L--7F7FJL7L7L7FJJLJ|||L7.L7F7FJ|F---JL----7|7L7|FJF--JFJ.L7F--J7|L------JL7|L---7LJJLL|-|
L7LF|-LJ|L-7FJ-LJLF----JF-7FJ||F7L----7F7L-7LJF7LJL--7|||L7L|FJFJL---7LJL7|F-J|||FLJF-7F-----JL-7||L7L7F-JF--J|F7F7L7F-7F7F-7||F7F-J.F7.JJLJ
LJ-J|LL-F--JL7F--7L----7|J|L7LJ|L----7LJL--JF-JL-----JLJL7|FJL7L7F7F7L7-FJ|L7FJ|L--7L7LJF--7F7F7||||L-JL-7L-7FJ|||L7|L7||||L||LJ|L7JF|L77.|7
.|..LFJ.L---7|L-7L-----J|FJFJF7|F---7L-----7|FF-----7F7F7LJL--JFJ||||FJLL7L7LJFJF--JFL-7|F-J|||||||F-----JF7|L-JLJFJ|FJ||||FJL-7L-JF-JFJJJ-L
-LJFLLF--LF-J|F-JF7F7F7FJL7|FJ|||F--JF7F--7LJFJF----J|||L7F--7FJFJ||LJ||LL-J|LL-JF7-F--J||F-J||LJLJL------J||F7F7FJ.LJ|||||L7F7L-7L|F-JJ|LFJ
L|-F77||..L--JL--JLJLJLJ.LLJL7LJ|L---JLJF-JF-JFJFF7F7||L7||F-J|FJ7||JJ|7-LJL|J7F-JL-JF7FJLJF7LJLF7F7F------JLJ|||L----7||||FJ||F7L-JL-7|L77J
F|-JLLJ-7.F7F7F-------7F7F--7L7FJF------JF-JF-JF7||||||FJLJL-7LJF7||7F|-7JJ.|.FJF-7F7|LJ|F-J|F--J||||F------7FLJL----7|LJLJL-JLJL7F-7FJ77|L-
LFJ-7J|.LFJ|||L------7LJ|L-7|.LJ|L-----7FJF7L--J||||||LJF-7F-JF-J|LJ7|||.|LFFFJFJJLJLJF-7L-7|L7F7|||LJF77F--JF77F7F7.||FF-------7|L7||||L77|
J.L.7-|7.L7LJL7F7F7F7|F-JF7||F--------7LJFJL7F7FJ|||||F7L7|L--JF7L-7JLJ7.J.FJ|FJFFF7F7|FJF7||JLJ|||L7FJ|FJF--JL-JLJL7LJFJF-7F-7FJL7||L77L7J7
.|.F||LF7LL--7LJLJLJLJL--J|||L-------7|F7L-7LJLJ-|LJLJ||FJL--7FJL7FJJ.|77.F--||--FJLJLJL-JLJL7F7||L7|L7|L7L7F---7F--JF7|FJLLJ|||JJLJL-JJL|.L
F|.F7|J|FL|F7L---7F7F---7FJ||F7F7F---JLJ|F-JF7F--JF7F-J|L---7|L-7||7.-JF---JLLJ7LL-7F-7F7F--7LJLJL-JL-JL-J-|L--7|L---J||L----7LJL7.FLJ|-L77|
||-LJ-7|LJFJL----J|||F--JL-JLJLJ|L---7F7|L--JLJF-7||L7FL---7|L--JLJ-|FJ||FLJ.J.77FFJ|FLJLJF7L-7F7F7F7F-7F--JF7FJL7F7F-J|F----JF|FF77JL7.LJ77
LJ.LL7JJ77L7F----7|||L7F-7F7F-7FJF7F7LJ|L7F-7F7L7LJL-JF7F7|LJ|F7F77.L|L|77.|FF-F--JFJF7F--JL--J|LJ|||||LJF-7|LJF7LJLJFFJL---7F7F7|L-7-777JL7
FJ-JJLJ.77FJ|F---J|||.|L7||||FJL-J|||F-JF|||||L7L-----JLJL-7F-JLJL--7J|LJLF|-|||F7FJFJLJF7F7F7FJF-J|||F--JFJL--JL7F7F7|F----J|LJ||F-J-LL|.7J
F7LFF7|F--JFJ|F7F7|||FJFJLJLJL-7F7LJ|L--7||FJL7|F---7F--7F7LJF-7F7F-J.7.L-7J7|-LJLJ|L--7|LJLJLJ.L--J||L--7L-----7LJLJ||L7LF-7|F-J|L-7FFJJFFJ
|7.FL|7L7F-JFJ|LJ||||L7|F------J||F7L---J|||F7||L--7|L-7|||F-J.||LJ|LJ-L--FJFJ7.||LFFF-JL-77F--7FF-7||7F7L-7F--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.LJF||F-7F7||F------7||F-JFJ||L-JL7LJ||L---JLJ||.||.|JJL.--.
F-F|-|F7.F|LJFJF7LJFJL--JF7F-7|JL7L-----7|FJL7FJF--7F-7F7F7|FJ|LJ-|7LJL.LJ.FLLFF7JFFJ|L7|||||L-----7|||L-7L7||F7F7L-7|L--7F7F7||F777..LLFJ|7
JFF--|F--L|F7|FJL--JF7F--JLJ|LJF7L-----7LJL-7|L7|F7LJ-LJLJLJL7|7JFJLF7JFLL-F7FF||F7L7|FJLJLJ|F-----JLJL-7L7LJ||LJL--JL--7LJLJ|LJ|L-7--F7J7L|
|7J|.L-7F7LJLJL----7|||F-------JL-----7L7F7FJL-JLJ|F7FF----7LLJ7LJJL-J77.FFF7-FJLJL7|LJF---7|L7F--7F7F-7L-JF7|L----7F7F7|F7F-JF-JF-J7J|F.JFJ
J|FL7|.7JF7||F-7F7L||||L--------7F---7L-J|LJF7F7F7LJL7L7F--J77|7-|JLF7-F-7F||FL--7FJL--JF--JL7LJF7LJLJFJF7-|||F-7F-J||||LJ|L--JF-J7L77LJFL|.
|L7FF--J-J7|FL7LJ|FJ|LJF--------J|F--JF7F|F7|||LJ|F7FJFJL7LF7F7.F-7.FLJL7|7||F77FJL--7JFJF--7L--JL7F7FJFJL7||LJ-LJLFJLJL7LL----JF777LFJL-JF.
F-J-J|J.|-F7F7L-7||FJ.FJF7F7F--7FJL---JL-J|LJ|L7FJ||L-JF7L-JLJL-7|F7JF77|L-JLJL7|F7F7L-JFJF-JF---7LJLJFJF-J|L------JF--7L----7FFJL7--..|.FL|
L7J-|77FLFJLJL-7||LJF7L-JLJ||F7LJ..F7F----JF7L-JL-J|F7FJ|F7F----JF-7-FLFL-----7|LJLJL7F-JFJF7|F--JF7F-J.L--JF-------JF7|F----JFJF-J||77F|--J
|||F.F-JJ|F---7LJL--JL----7LJ|L--7FJ|L---7FJL-----7LJ||LLJ|L-7LF-JFJF--F---7F-JL7F7F7LJF7L7|LJL---JLJF77F---J|F7LF-7F||LJ7F---JFJ7FLF7F7.7.7
F77JL.|FF||F-7L-----7F--7FJF7L--7|L7|F7F7LJF-----7L-7|L7F7|F-J.L-7|F7-LL--7|L-7FJ|LJL-7|L7LJF7F7F7J.FJL7L-----JL7L7L-JL--7|F-7FJLFJ|FJFL-JFJ
||L--7-JLLJL7L-----7LJLFJL-J|F7FJL-JLJ|||F7L----7L--JL-J|LJ|F77F7||||F---7|L7FJL7L---7||FJF-JLJLJL7FJF7L--------JFJF7F7F7LJL7||F7J||J.||7JFJ
|-7LL|JF--F-JF----7L-7FJF--7LJLJF7F--7LJ||L-7F-7L-7F7F77|F-J|L7|LJ|||L--7||FJL7FJF--7|LJL7L-7F-7F7LJFJL-----7F7F-JFJLJLJL---J|LJL7F7LFFF-F-7
|7|L||F|L||F7|F---JF7LJFJF-JF7F-JLJF7L-7|L-7|L7|F7||LJL7LJF7|FJ|F7||L7JFJ|||JFJL7L-7|L-7FJF7LJ7LJ|F7L7F-----J|||F-JJ7F7F----7L7F-JF7.|LFJ|||
--LFFJ7J7FLJ|||F7F7||F7|FJF-JLJF---JL7FJL--JL7|||LJ|F-7L7FJ||L7LJ||L7L-JFJ|L7|F7L7FJ|F7||-||F----J||FJL7F7F7FJLJL--7FJ||F---J-LJF7||-7FLFJJ.
LF7||L-7-FJFJ|LJ||||||LJL-JFF--JF--7.LJF----7LJ||F-J|7L-J|FJL7L7FJ|J|F--JFJFJLJ|FJL7||||L7|LJF--7FJ||F7LJLJLJF----7LJFJ|L-----7FJ|||77LF77L.
||LJJ7.J.L-L-JF7LJLJLJF-----JF--J|FJF--JF7F7|F7LJL-7L7F7||L-7|FJ|FJFJ|F7-L7|LF-JL--JLJ||FJL--JF7LJ|LJ||F7F7F7L---7|F-JFJF-7F--JL7LJL-77||7JF
L7LJ7-|-FF|JF-JL---7F7L--7F--JF7F7L-JF--JLJ|LJL7LF7|FJ|L7L7FJ||FJL7L7LJL-7|L7L--7F-7F-J|L7F7F7|L7F---JLJLJLJL-7F7|||F7L7|F|L---7L7F7FJJFJ|-7
|--L-F---7JLL----7FJ||7F-J|F--JLJL---JF7F7||F7FJFJ||L7|FJFJ|7||L-7L7|F---JL7L--7LJFJL-7|FJ|||||FJLS---------7|||||LJ|L-JL7|F---JFJ||L77L7-.|
|LF..L|LFL7.LF---JL-JL7L7FJL---------7|LJL7LJLJ7|FJ|FJ|L7L7|FJ|JFJFJ|L7FF7FJF--J-FJF--J||FJLJLJ|F7F77F7F---7L7||LJFFJF7F-J||F7-FJFJL-J7..LF7
|.|.FJ|L|L|7FL7F-----7L7LJF------7|F7LJF-7L7F--7|L7|L7L7|FJ|L7L7L7L7|FJFJ|L7|F77FJFJF-7|||F---7|||||FJLJF-7L-JLJF7FJFJ||F7LJ|L7L7L7F7F--7-F7
|7FFJ-L-J|F-JLLJF7FF7|FJF7L---7F7L-JL--JJL-JL7FJ|FJ|FJFJ|L7L7L7|.|FJ||JL7|FJ|||FJFJFJFJ||LJF7|||||||L---JFJ-F--7|LJFJ|LJ||F7|FJFJFJ|LJF7L7J|
.FJ|LF|-|7.||7-FJL-JLJL7||F--7LJL--7F-----7F7||FJL7||7L7|-L7L7||FJL-JL7FJLJFJ|||FJ7L7L7|L7FJL7|||LJL7F7F-JF7|F-JL7FJF7F7|||||L-JFJFJF7|L-JL-
-L-7-LL-L--7LF-JF7F7F-7|||L-7L-----J|F----J|LJ|L-7|||F-JL7J|FJ||L7F---JL--7|FJ||L-7.L7||FJL-7||||F--J|LJF-JLJ|F7FJL-JLJLJLJLJF-7L-JFJLJJ.|7.
|-FJ|.J7FL-|-L-7|||LJ||||L7FL-------JL-7.F7L-7L7-||||L-7FJFJL7||FJL7F7F-7J|||FJ|F-JF-J|||F7FJ||LJL7F7L--JF--7LJLJF7F--7F7F--7|-L7F7L-7JLFL|7
|-J-J-77FLF.F|-LJLJJF-J|L7|F7F------7F7L7|L7.L7|FJLJL7L||FJF-J||L7FJ||L7|FJ||L7||F7L-7|||||L7|L-7FJ||F---JF7L7F--J|L-7LJLJF7|L-7LJ|F7|-F-7LJ
-J.F|F-LJLF--7F7F---JF7L7||||L7F-7F7LJL-JL7L77||L-7F-JFJ|L7|F7||FJL7||FJ||FJ|FJ|LJ|F7|||||L7|L7FJL7||L----JL7LJF-7|F7L7F7F||L--JF7LJLJ|L-JLL
LF7|F-JL7|L7FJ||L----JL7LJLJL-J|L||L7F7F-7L7|FJL7FJL7FL7L7||||||L-7LJ||FJ|L7||FJF-J|||LJ||FJL7LJF-J||F-7F--7L--JFJLJL-J|L-JL---7|L7-||JFLJL|
L|JF7-7---FJ|FJ|F7F7|F7L7F7F-7FJFJ|FJ|||FJ7||L7FJ|F-JF7|FJ||||||F7L-7|||7L7|||L7|F7||L7FJ||F7|F-JF7||L7|L-7L---7|F--7F7|F------J|FJF7--J7-F|
7-FJL7LF--L7|L7LJLJL-JL-J|||FJ|JL-JL7|||L7FJL7||FJ|F7|||L7||||||||F7|||L7FJ||L7||||||FJ|FJ|||||F7|||L7||F7L---7|LJF-J|LJL-----7FJL-J|.-J|.F7
L-7---FJLFFJ|FL---7F-7F7FJLJL-JF----J|LJFJL7LLJ|L7LJ||||FJ|||LJLJ|||||L7LJL|L7||||LJ|L7|L7|||||||||L7|||||F7F-J|F7|F7|F-7F----J|F---J7J7F7F7
FF--JF-7.LL7L-----J|FJ|LJF--7F-JF--7FJF-JF-JF--JFJF-J|LJL7||L--7FJ|||L-JF--JFJ|||L7FJFJL7|||||LJ||L-JLJ|||||L7JLJ|LJLJ|-||-F---JL---7JFL7FJJ
L7JL-JJ|7|F|F7F7F7FJL7|F7|F7LJF7|F-J|FJF7L7.L7F7|FL7FJF--J|L7F7|L7|LJF--JF7FJFLJL7||FJF-J|LJ|L-7|L---7FJ|||L7L--7L7F-7L7LJFJF7F7F---JFJL|-|J
FF7L7|.LLF-J||||||L7FJ||LJ|L7FJ||L7FJL7|L-JF-J||L-7|L7L--7|FJ||L7LJF-JF--J|L-7JF-J|LJLL-7L-7|F-J|F---JL7||L7|F--J||L7L7L--J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Pipe Maze ---
You use the hang glider to ride the hot air from Desert Island all the way up to the floating metal island. This island is surprisingly cold and there definitely aren't any thermals to glide on, so you leave your hang glider behind.
You wander around for a while, but you don't find any people or animals. However, you do occasionally find signposts labeled "Hot Springs" pointing in a seemingly consistent direction; maybe you can find someone at the hot springs and ask them where the desert-machine parts are made.
The landscape here is alien; even the flowers and trees are made of metal. As you stop to admire some metal grass, you notice something metallic scurry away in your peripheral vision and jump into a big pipe! It didn't look like any animal you've ever seen; if you want a better look, you'll need to get ahead of it.
Scanning the area, you discover that the entire field you're standing on is densely packed with pipes; it was hard to tell at first because they're the same metallic silver color as the "ground". You make a quick sketch of all of the surface pipes you can see (your puzzle input).
The pipes are arranged in a two-dimensional grid of tiles:
| 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.
Based on the acoustics of the animal's scurrying, you're confident the pipe that contains the animal is one large, continuous loop.
For example, here is a square loop of pipe:
.....
.F-7.
.|.|.
.L-J.
.....
If the animal had entered this loop in the northwest corner, the sketch would instead look like this:
.....
.S-7.
.|.|.
.L-J.
.....
In the above diagram, the S tile is still a 90-degree F bend: you can tell because of how the adjacent pipes connect to it.
Unfortunately, there are also many pipes that aren't connected to the loop! This sketch shows the same loop as above:
-L|F7
7S-7|
L|7||
-L-J|
L|-JF
In the above diagram, you can still figure out which pipes form the main loop: they're the ones connected to S, pipes those pipes connect to, pipes those pipes connect to, and so on. Every pipe in the main loop connects to its two neighbors (including S, which will have exactly two pipes connecting to it, and which is assumed to connect back to those two pipes).
Here is a sketch that contains a slightly more complex main loop:
..F7.
.FJ|.
SJ.L7
|F--J
LJ...
Here's the same example sketch with the extra, non-main-loop pipe tiles also shown:
7-F7-
.FJ|7
SJLL7
|F--J
LJ.LJ
If you want to get out ahead of the animal, you should find the tile in the loop that is farthest from the starting position. Because the animal is in the pipe, it doesn't make sense to measure this by direct distance. Instead, you need to find the tile that would take the longest number of steps along the loop to reach from the starting point - regardless of which way around the loop the animal went.
In the first example with the square loop:
.....
.S-7.
.|.|.
.L-J.
.....
You can count the distance each tile in the loop is from the starting point like this:
.....
.012.
.1.3.
.234.
.....
In this example, the farthest point from the start is 4 steps away.
Here's the more complex loop again:
..F7.
.FJ|.
SJ.L7
|F--J
LJ...
Here are the distances for each tile on that loop:
..45.
.236.
01.78
14567
23...
Find the single giant loop starting at S. How many steps along the loop does it take to get from the starting position to the point farthest from the starting position?
Your puzzle answer was 6882.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
You quickly reach the farthest point of the loop, but the animal never emerges. Maybe its nest is within the area enclosed by the loop?
To determine whether it's even worth taking the time to search for such a nest, you should calculate how many tiles are contained within the loop. For example:
...........
.S-------7.
.|F-----7|.
.||.....||.
.||.....||.
.|L-7.F-J|.
.|..|.|..|.
.L--J.L--J.
...........
The above loop encloses merely four tiles - the two pairs of . in the southwest and southeast (marked I below). The middle . tiles (marked O below) are not in the loop. Here is the same loop again with those regions marked:
...........
.S-------7.
.|F-----7|.
.||OOOOO||.
.||OOOOO||.
.|L-7OF-J|.
.|II|O|II|.
.L--JOL--J.
.....O.....
In fact, there doesn't even need to be a full tile path to the outside for tiles to count as outside the loop - squeezing between pipes is also allowed! Here, I is still within the loop and O is still outside the loop:
..........
.S------7.
.|F----7|.
.||OOOO||.
.||OOOO||.
.|L-7F-J|.
.|II||II|.
.L--JL--J.
..........
In both of the above examples, 4 tiles are enclosed by the loop.
Here's a larger example:
.F----7F7F7F7F-7....
.|F--7||||||||FJ....
.||.FJ||||||||L7....
FJL7L7LJLJ||LJ.L-7..
L--J.L7...LJS7F-7L7.
....F-J..F7FJ|L7L7L7
....L7.F7||L7|.L7L7|
.....|FJLJ|FJ|F7|.LJ
....FJL-7.||.||||...
....L---J.LJ.LJLJ...
The above sketch has many random bits of ground, some of which are in the loop (I) and some of which are outside it (O):
OF----7F7F7F7F-7OOOO
O|F--7||||||||FJOOOO
O||OFJ||||||||L7OOOO
FJL7L7LJLJ||LJIL-7OO
L--JOL7IIILJS7F-7L7O
OOOOF-JIIF7FJ|L7L7L7
OOOOL7IF7||L7|IL7L7|
OOOOO|FJLJ|FJ|F7|OLJ
OOOOFJL-7O||O||||OOO
OOOOL---JOLJOLJLJOOO
In this larger example, 8 tiles are enclosed by the loop.
Any tile that isn't part of the main loop can count as being enclosed by the loop. Here's another example with many bits of junk pipe lying around that aren't connected to the main loop at all:
FF7FSF7F7F7F7F7F---7
L|LJ||||||||||||F--J
FL-7LJLJ||||||LJL-77
F--JF--7||LJLJ7F7FJ-
L---JF-JLJ.||-FJLJJ7
|F|F-JF---7F7-L7L|7|
|FFJF7L7F-JF7|JL---7
7-L-JL7||F7|L7F-7F7|
L.L7LFJ|||||FJL7||LJ
L7JLJL-JLJLJL--JLJ.L
Here are just the tiles that are enclosed by the loop marked with I:
FF7FSF7F7F7F7F7F---7
L|LJ||||||||||||F--J
FL-7LJLJ||||||LJL-77
F--JF--7||LJLJIF7FJ-
L---JF-JLJIIIIFJLJJ7
|F|F-JF---7IIIL7L|7|
|FFJF7L7F-JF7IIL---7
7-L-JL7||F7|L7F-7F7|
L.L7LFJ|||||FJL7||LJ
L7JLJL-JLJLJL--JLJ.L
In this last example, 10 tiles are enclosed by the loop.

5
day10/test_input.txt Normal file
View File

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

View File

@@ -7,8 +7,6 @@ class Card(object):
card_re = re.compile(r'Card +(\d+): ') card_re = re.compile(r'Card +(\d+): ')
def __init__(self, inp): def __init__(self, inp):
m = self.card_re.search(inp) m = self.card_re.search(inp)
if not m:
print(inp)
self.card_num = m.group(1) self.card_num = m.group(1)
inp = inp.replace(m.group(0), '') inp = inp.replace(m.group(0), '')
winning, have = inp.split('|') winning, have = inp.split('|')
@@ -55,12 +53,11 @@ class CardSet(object):
copies = [0 for _ in range(len(self.cards))] copies = [0 for _ in range(len(self.cards))]
for i in range(len(self.cards)): for i in range(len(self.cards)):
copies[i] += 1 copies[i] += 1
for _ in range(copies[i]): matching = self.cards[i]._count_winning_in_have()
matching = self.cards[i]._count_winning_in_have() if i + matching > len(self.cards):
if i + matching > len(self.cards): matching = len(self.cards) - 1 - i
matching = len(self.cards) - 1 - i for j in range(1, matching+1):
for j in range(1, matching+1): copies[i+j] += 1 * copies[i]
copies[i+j] += 1
return sum(copies) return sum(copies)
if __name__ == '__main__': if __name__ == '__main__':

3
day5/README.md Normal file
View File

@@ -0,0 +1,3 @@
I implemented this task both in Python ang Go because brute-force solution was too slow in Python.
The code in both languages is very similar. But Go version solved the problem in 3 minutes and 24 seconds while Python version worked for as long as 5 hours 49 minutes 30 seconds. Both versions are single threaded.

143
day5/day5.go Normal file
View File

@@ -0,0 +1,143 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
const MaxInt = int((^uint(0) >> 1))
type Range struct {
dst int
src int
len int
}
func (r Range) Map(n int) (int, bool) {
if n < r.src || n > (r.src+r.len-1) {
return 0, false
}
return r.dst - r.src + n, true
}
type Map struct {
name string
ranges []Range
}
func (m *Map) Append(r Range) {
m.ranges = append(m.ranges, r)
}
func (m *Map) Map(n int) int {
for i := range m.ranges {
x, ok := m.ranges[i].Map(n)
if ok {
return x
}
}
return n
}
type Almanac struct {
seeds []int
maps []*Map
}
func (a *Almanac) ParseFile(name string) error {
f, err := os.Open(name)
if err != nil {
return err
}
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Scan()
seedsStr := scanner.Text()
seeds := strToInts(seedsStr[7:])
a.seeds = seeds
scanner.Scan()
var m *Map
for scanner.Scan() {
s := scanner.Text()
s = strings.Trim(s, " \n")
if s == "" {
a.maps = append(a.maps, m)
continue
}
if s[0] > '9' {
m = &Map{
name: s,
ranges: []Range{},
}
continue
}
nums := strToInts(s)
r := Range{
dst: nums[0],
src: nums[1],
len: nums[2],
}
m.Append(r)
}
a.maps = append(a.maps, m)
return nil
}
func (a *Almanac) seedToLoc(n int) int {
for i := range a.maps {
n = a.maps[i].Map(n)
}
return n
}
func (a *Almanac) ClosestForSeeds() int {
result := MaxInt
for _, n := range a.seeds {
loc := a.seedToLoc(n)
if loc < result {
result = loc
}
}
return result
}
func (a *Almanac) ClosestForRanges() int {
result := MaxInt
for i := 0; i < (len(a.seeds) - 2); i += 2 {
for j := a.seeds[i]; j < (a.seeds[i] + a.seeds[i+1]); j++ {
loc := a.seedToLoc(j)
if loc < result {
result = loc
}
}
}
return result
}
func strToInts(s string) []int {
s = strings.Trim(s, " \n")
split := strings.Split(s, " ")
nums := []int{}
for _, x := range split {
n, err := strconv.Atoi(x)
if err != nil {
panic(err)
}
nums = append(nums, n)
}
return nums
}
func main() {
a := new(Almanac)
a.ParseFile("input.txt")
x := a.ClosestForSeeds()
fmt.Println(x)
y := a.ClosestForRanges()
fmt.Println(y)
}

103
day5/day5.py Normal file
View File

@@ -0,0 +1,103 @@
import sys
sys.path.append('../lib')
import tools
class Range(object):
def __init__(self, dst_start, src_start, lenght):
self.dst = dst_start
self.src = src_start
self.len = lenght
def __str__(self):
return f'range: {self.dst}, {self.src}, {self.len}'
def map(self, n: int) -> int:
if n < self.src or n > (self.src + self.len - 1):
return None
return self.dst - self.src + n
class Map(object):
def __init__(self, name):
self.name = name
self.ranges = []
def __str__(self):
out = f'map "{self.name}"\n'
for r in self.ranges:
out += str(r) + '\n'
return out
def append_range(self, r):
self.ranges.append(r)
def map(self, inp: int) -> int:
for r in self.ranges:
mapped = r.map(inp)
if mapped is not None:
return mapped
return inp
class Almanac(object):
def __init__(self, lines):
self.seeds = [int(n) for n in lines[0].replace('seeds: ', '').split()]
self.maps = list()
m = None
for line in lines[2:]:
if line == '':
self.maps.append(m)
continue
if line[0].isalpha():
m = Map(line)
continue
a, b, c = [int(n) for n in line.split()]
r = Range(a, b, c)
m.append_range(r)
self.maps.append(m)
def __str__(self):
out = 'The latest Island Island Almanac\n'
out += f'Seeds: {", ".join([str(n) for n in self.seeds])}\n'
for m in self.maps:
out += str(m)
return out
def _map_seed_to_location(self, seed: int) -> int:
for m in self.maps:
seed = m.map(seed)
return seed
def find_closest_location_for_seed_nums(self) -> int:
result = float('inf')
for seed in self.seeds:
loc = self._map_seed_to_location(seed)
if loc < result:
result = loc
return result
def find_closest_location_for_seed_ranges(self) -> int:
closest = float('inf')
for i in range(0, len(self.seeds), 2):
for n in range(self.seeds[i], self.seeds[i]+self.seeds[i+1]):
loc = self._map_seed_to_location(n)
if loc < closest:
closest = loc
return closest
if __name__ == '__main__':
r = tools.Reader('input.txt')
lines = r.read()
al = Almanac(lines)
x = al.find_closest_location_for_seed_nums()
print(x)
y = al.find_closest_location_for_seed_ranges()
print(y)

3
day5/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module day5
go 1.21.4

244
day5/input.txt Normal file
View File

@@ -0,0 +1,244 @@
seeds: 564468486 226119074 3264322485 135071952 3144185610 89794463 1560365167 555667043 2419038624 7808461 1264209624 9380035 105823719 425973940 4115473551 104486997 3784956593 300187503 975280918 257129208
seed-to-soil map:
1383244180 2567207479 366571891
3099137706 184794382 526583321
3625721027 2933779370 589006054
1749816071 838554248 828858952
4214727081 3750906360 80240215
2585129273 2301737819 265469660
919423459 3831146575 463820721
2850598933 2053199046 248538773
184794382 1667413200 385785846
570580228 3522785424 221666686
2578675023 3744452110 6454250
792246914 711377703 127176545
soil-to-fertilizer map:
1263133301 1101112301 247905608
0 1881569198 406369887
3891730222 4233430396 61536900
2723511851 1349017909 413665324
2115333016 1762683233 118885965
4272202829 4116902795 22764467
1668270240 169908659 417260703
4047030256 3891730222 225172573
1511038909 990025537 111086764
3953267122 4139667262 93763134
2085530943 960223464 29802073
1622125673 2601739738 46144567
2234218981 2647884305 489292870
481920846 0 169908659
406369887 587169362 75550959
651829505 2287939085 313800653
965630158 662720321 297503143
fertilizer-to-water map:
2026149150 1702247536 416569358
1701798124 875863088 283903191
4063252939 1683589413 18658123
3356033649 595896148 7346630
1335228099 2585783629 62193392
2537326742 2766720775 117696298
229675839 2982385208 35341780
2735250450 86353870 111979203
1461856743 642976733 131238213
3045992699 1159766279 201290966
731984354 397096119 63406721
3363380279 3994841151 232428641
3846842813 3635945469 205565478
149524933 3053740954 23094746
1990135184 3017726988 36013966
3627123568 460502840 135393308
2442718508 2709874611 56846164
4052408291 1672744765 10844648
4081911062 2647977021 57463721
1985701315 2705440742 4433869
1593094956 3841510947 108703168
4139374783 1361057245 90255266
2847229653 198333073 198763046
88714127 1451312511 32454860
265017619 2118816894 466966735
172619679 774214946 57056160
2499564672 2929579580 24449682
795391075 3096108445 336808580
2524014354 3981528763 13312388
2655023040 1483767371 80227410
3595808920 3950214115 31314648
86353870 4227269792 2360257
3247283665 1563994781 108749984
121168987 2954029262 28355946
1132199655 3432917025 203028444
1416694236 2884417073 45162507
3802250831 831271106 44591982
1397421491 3076835700 19272745
3762516876 603242778 39733955
water-to-light map:
3045192883 3405560724 233949223
2014949572 1677426106 1239699
4293597773 2746321393 1369523
3495751006 3639509947 92916249
4009877494 2908092253 257514030
661965443 153544727 24099928
553752491 24333950 108212952
0 585895182 65036937
1029728406 732437088 122957582
3335349669 2747690916 160401337
1516105110 1678665805 50370082
1287786410 564845618 21049564
1766185151 1350812289 80953114
1847138265 954947145 167811307
2517751097 4153636435 141330861
1406248256 1779785802 109856854
477432380 177644655 76320111
2912031646 3216191924 133161237
86034762 2124004905 98754160
357903034 1231282943 119529346
794589862 1431765403 127455713
1684680182 650932119 81504969
1188233935 855394670 99552475
2659081958 3170612752 19372923
65036937 132546902 20997825
3279142106 3349353161 56207563
922045575 481034939 83810679
184788922 0 24333950
1005856254 1889642656 23872152
1152685988 2088456958 35547947
1308835974 1729035887 50749915
686065371 1122758452 108524491
2016189271 1960177175 128279783
3588667255 3732426196 421210239
209122872 253964766 148780162
2144469054 402744928 78290011
1566475192 1559221116 118204990
4267391524 3189985675 26206249
1359585889 1913514808 46662367
2683461350 2517751097 228570296
2678454881 3165606283 5006469
light-to-temperature map:
1030392082 1321188955 165336990
0 44804161 150706826
1568567634 1516401258 330930043
2865769925 4113445018 181522278
1195729072 195510987 44463126
2000741875 3723797683 97726768
3123087526 3637587950 86209733
438054653 1116646106 202854548
1550843096 888600245 16036237
250959147 239974113 187095506
1566879333 1319500654 1688301
3209297259 3343689313 188836349
3398133608 2601040211 257482320
1497005983 1847331301 53837113
4193409024 2004480239 101558272
1899497677 1514730521 1670737
4135626915 3532525662 57782109
1240192198 904636482 212009624
1452201822 0 44804161
178911402 427069619 72047745
2360827259 3821524451 282320546
793597174 651805337 236794908
150706826 1486525945 28204576
3655615928 2134367609 466672602
4126026894 4103844997 9600021
2126797741 2858522531 234029518
640909201 499117364 152687973
4122288530 2000741875 3738364
3047292203 3590307771 47280179
3094572382 3315174169 28515144
2098468643 2106038511 28329098
2643147805 3092552049 222622120
temperature-to-humidity map:
2682018628 3211857150 7482265
2267967594 974505223 103462688
3164705039 622508404 112412801
807519675 3897720931 7401318
1258610757 1950164875 153606404
688770014 2493658816 117081461
585035426 1429176965 103734588
1412217161 3054430041 157427109
2620753111 1936669611 13495264
2371430282 3479240080 119868447
2689500893 1809328956 2558000
2491298729 2103771279 129454382
2634248375 132197744 47770253
0 3599108527 17467705
1715711200 510341852 112166552
324602271 2233225661 260433155
3277117840 4013788866 6258575
1569644270 3252822610 21284275
17467705 1625497048 183831908
805851475 1532911553 1668200
4192930018 4158778858 102037278
1880394968 3616576232 267437436
814920993 2610740277 443689764
4153948228 4125255449 33523409
2959571844 3274106885 205133195
3571697512 194189667 100397262
3804292518 294586929 215754923
3283376415 1077967911 288321097
2250849334 1608378788 17118260
201299613 1541225531 67153257
2147832404 1534579753 6645778
2154478182 3219339415 33483195
2705766156 734921205 239584018
2945350174 179967997 14221670
1590928545 1811886956 124782655
268452870 3905122249 56149401
3672094774 0 132197744
2692058893 3884013668 13707263
2187961377 1366289008 62887957
4125255449 4266274517 28692779
4187471637 4260816136 5458381
1827877752 3961271650 52517216
humidity-to-location map:
565280258 742633625 262999864
236814486 5872218 143216751
3086070204 1429025489 128855
1456030811 3501418909 61854477
3571235481 2009792978 141760052
1110445989 2596942754 8218306
2447073943 1299304357 102347512
2035751658 1880371400 1772758
437631438 1882144158 127648820
828280122 2605161060 197246445
0 149088969 236814486
1765728190 2802407505 40638372
1025526567 3833657987 66428167
1399091075 2151553030 56939736
2411817723 2843045877 35256220
2384444103 1401651869 27373620
1091954734 2997174931 18491255
1991811752 3900086154 43939906
2629520392 437631438 202995815
3811071540 3015666186 477873381
3497852258 1225921134 73383223
2832516207 2286969411 253553997
1753847939 1214040883 11880251
2037524416 2878302097 118872834
3721118285 4055275299 43341551
3268322772 1187757202 26283681
1299671458 4098616850 99419617
3764459836 4275368369 19598927
1197665086 640627253 102006372
4288944921 3827635612 6022375
3712995533 2588820002 8122752
1118664295 1429154344 79000791
1806366562 4198036467 50319125
2156397250 3635492981 192142631
3454152286 2208492766 43699972
1856685687 1508155135 135126065
1719071266 2252192738 34776673
3294606453 2540523408 48296594
3342903047 3944026060 111249239
1517885288 1643281200 201185978
2621641050 3493539567 7879342
380031237 0 5872218
2549421455 3563273386 72219595
2348539881 1844467178 35904222
3086199059 1005633489 182123713
3784058763 4248355592 27012777

116
day5/task.txt Normal file
View File

@@ -0,0 +1,116 @@
--- Day 5: If You Give A Seed A Fertilizer ---
You take the boat and find the gardener right where you were told he would be: managing a giant "garden" that looks more to you like a farm.
"A water source? Island Island is the water source!" You point out that Snow Island isn't receiving any water.
"Oh, we had to stop the water because we ran out of sand to filter it with! Can't make snow with dirty water. Don't worry, I'm sure we'll get more sand soon; we only turned off the water a few days... weeks... oh no." His face sinks into a look of horrified realization.
"I've been so busy making sure everyone here has food that I completely forgot to check why we stopped getting more sand! There's a ferry leaving soon that is headed over in that direction - it's much faster than your boat. Could you please go check it out?"
You barely have time to agree to this request when he brings up another. "While you wait for the ferry, maybe you can help us with our food production problem. The latest Island Island Almanac just arrived and we're having trouble making sense of it."
The almanac (your puzzle input) lists all of the seeds that need to be planted. It also lists what type of soil to use with each kind of seed, what type of fertilizer to use with each kind of soil, what type of water to use with each kind of fertilizer, and so on. Every type of seed, soil, fertilizer and so on is identified with a number, but numbers are reused by each category - that is, soil 123 and fertilizer 123 aren't necessarily related to each other.
For example:
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
The almanac starts by listing which seeds need to be planted: seeds 79, 14, 55, and 13.
The rest of the almanac contains a list of maps which describe how to convert numbers from a source category into numbers in a destination category. That is, the section that starts with seed-to-soil map: describes how to convert a seed number (the source) to a soil number (the destination). This lets the gardener and his team know which soil to use with which seeds, which water to use with which fertilizer, and so on.
Rather than list every source number and its corresponding destination number one by one, the maps describe entire ranges of numbers that can be converted. Each line within a map contains three numbers: the destination range start, the source range start, and the range length.
Consider again the example seed-to-soil map:
50 98 2
52 50 48
The first line has a destination range start of 50, a source range start of 98, and a range length of 2. This line means that the source range starts at 98 and contains two values: 98 and 99. The destination range is the same length, but it starts at 50, so its two values are 50 and 51. With this information, you know that seed number 98 corresponds to soil number 50 and that seed number 99 corresponds to soil number 51.
The second line means that the source range starts at 50 and contains 48 values: 50, 51, ..., 96, 97. This corresponds to a destination range starting at 52 and also containing 48 values: 52, 53, ..., 98, 99. So, seed number 53 corresponds to soil number 55.
Any source numbers that aren't mapped correspond to the same destination number. So, seed number 10 corresponds to soil number 10.
So, the entire list of seed numbers and their corresponding soil numbers looks like this:
seed soil
0 0
1 1
... ...
48 48
49 49
50 52
51 53
... ...
96 98
97 99
98 50
99 51
With this map, you can look up the soil number required for each initial seed number:
Seed number 79 corresponds to soil number 81.
Seed number 14 corresponds to soil number 14.
Seed number 55 corresponds to soil number 57.
Seed number 13 corresponds to soil number 13.
The gardener and his team want to get started as soon as possible, so they'd like to know the closest location that needs a seed. Using these maps, find the lowest location number that corresponds to any of the initial seeds. To do this, you'll need to convert each seed number through other categories until you can find its corresponding location number. In this example, the corresponding types are:
Seed 79, soil 81, fertilizer 81, water 81, light 74, temperature 78, humidity 78, location 82.
Seed 14, soil 14, fertilizer 53, water 49, light 42, temperature 42, humidity 43, location 43.
Seed 55, soil 57, fertilizer 57, water 53, light 46, temperature 82, humidity 82, location 86.
Seed 13, soil 13, fertilizer 52, water 41, light 34, temperature 34, humidity 35, location 35.
So, the lowest location number in this example is 35.
What is the lowest location number that corresponds to any of the initial seed numbers?
Your puzzle answer was 340994526.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
Everyone will starve if you only plant such a small number of seeds. Re-reading the almanac, it looks like the seeds: line actually describes ranges of seed numbers.
The values on the initial seeds: line come in pairs. Within each pair, the first value is the start of the range and the second value is the length of the range. So, in the first line of the example above:
seeds: 79 14 55 13
This line describes two ranges of seed numbers to be planted in the garden. The first range starts with seed number 79 and contains 14 values: 79, 80, ..., 91, 92. The second range starts with seed number 55 and contains 13 values: 55, 56, ..., 66, 67.
Now, rather than considering four seed numbers, you need to consider a total of 27 seed numbers.
In the above example, the lowest location number can be obtained from seed number 82, which corresponds to soil 84, fertilizer 84, water 84, light 77, temperature 45, humidity 46, and location 46. So, the lowest location number is 46.
Consider all of the initial seed numbers listed in the ranges on the first line of the almanac. What is the lowest location number that corresponds to any of the initial seed numbers?
Your puzzle answer was 52210644.
Both parts of this puzzle are complete! They provide two gold stars: **

33
day5/test_input.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

68
day6/day6.py Normal file
View File

@@ -0,0 +1,68 @@
import sys
sys.path.append('../lib')
import tools
class Race(object):
def __init__(self, duration, distance):
self.duration = duration
self.distance = distance
def __str__(self):
return f'Time: {self.duration}, Distance: {self.distance}'
def calc_winning_strategies(self) -> list:
winning_press_durations = []
for dur in range(1, self.duration):
if ((self.duration - dur) * dur) > self.distance:
winning_press_durations.append(dur)
return winning_press_durations
class RaceSet(object):
def __init__(self, inp, join_input=False):
if join_input:
times = [int(''.join([n for n in inp[0].split(':')[1].split()]))]
distances = [int(''.join([n for n in inp[1].split(':')[1].split()]))]
else:
times = [int(n) for n in inp[0].split(':')[1].split()]
distances = [int(n) for n in inp[1].split(':')[1].split()]
assert len(times) == len(distances)
self.races = []
for i in range(len(times)):
r = Race(times[i], distances[i])
self.races.append(r)
def __str__(self):
out = f'Set of {len(self.races)} races:\n'
out += "\n".join([str(r) for r in self.races])
return out
def calc_product_of_winning_strategies(self) -> int:
product = 1
for r in self.races:
strategies = r.calc_winning_strategies()
product *= len(strategies)
return product
if __name__ == '__main__':
r = tools.Reader('input.txt')
lines = r.read()
races = RaceSet(lines)
print(races)
x = races.calc_product_of_winning_strategies()
print(x)
races = RaceSet(lines, join_input=True)
print(races)
x = races.calc_product_of_winning_strategies()
print(x)

2
day6/input.txt Normal file
View File

@@ -0,0 +1,2 @@
Time: 59 68 82 74
Distance: 543 1020 1664 1022

66
day6/task.txt Normal file
View File

@@ -0,0 +1,66 @@
--- Day 6: Wait For It ---
The ferry quickly brings you across Island Island. After asking around, you discover that there is indeed normally a large pile of sand somewhere near here, but you don't see anything besides lots of water and the small island where the ferry has docked.
As you try to figure out what to do next, you notice a poster on a wall near the ferry dock. "Boat races! Open to the public! Grand prize is an all-expenses-paid trip to Desert Island!" That must be where the sand comes from! Best of all, the boat races are starting in just a few minutes.
You manage to sign up as a competitor in the boat races just in time. The organizer explains that it's not really a traditional race - instead, you will get a fixed amount of time during which your boat has to travel as far as it can, and you win if your boat goes the farthest.
As part of signing up, you get a sheet of paper (your puzzle input) that lists the time allowed for each race and also the best distance ever recorded in that race. To guarantee you win the grand prize, you need to make sure you go farther in each race than the current record holder.
The organizer brings you over to the area where the boat races are held. The boats are much smaller than you expected - they're actually toy boats, each with a big button on top. Holding down the button charges the boat, and releasing the button allows the boat to move. Boats move faster if their button was held longer, but time spent holding the button counts against the total race time. You can only hold the button at the start of the race, and boats don't move until the button is released.
For example:
Time: 7 15 30
Distance: 9 40 200
This document describes three races:
The first race lasts 7 milliseconds. The record distance in this race is 9 millimeters.
The second race lasts 15 milliseconds. The record distance in this race is 40 millimeters.
The third race lasts 30 milliseconds. The record distance in this race is 200 millimeters.
Your toy boat has a starting speed of zero millimeters per millisecond. For each whole millisecond you spend at the beginning of the race holding down the button, the boat's speed increases by one millimeter per millisecond.
So, because the first race lasts 7 milliseconds, you only have a few options:
Don't hold the button at all (that is, hold it for 0 milliseconds) at the start of the race. The boat won't move; it will have traveled 0 millimeters by the end of the race.
Hold the button for 1 millisecond at the start of the race. Then, the boat will travel at a speed of 1 millimeter per millisecond for 6 milliseconds, reaching a total distance traveled of 6 millimeters.
Hold the button for 2 milliseconds, giving the boat a speed of 2 millimeters per millisecond. It will then get 5 milliseconds to move, reaching a total distance of 10 millimeters.
Hold the button for 3 milliseconds. After its remaining 4 milliseconds of travel time, the boat will have gone 12 millimeters.
Hold the button for 4 milliseconds. After its remaining 3 milliseconds of travel time, the boat will have gone 12 millimeters.
Hold the button for 5 milliseconds, causing the boat to travel a total of 10 millimeters.
Hold the button for 6 milliseconds, causing the boat to travel a total of 6 millimeters.
Hold the button for 7 milliseconds. That's the entire duration of the race. You never let go of the button. The boat can't move until you let go of the button. Please make sure you let go of the button so the boat gets to move. 0 millimeters.
Since the current record for this race is 9 millimeters, there are actually 4 different ways you could win: you could hold the button for 2, 3, 4, or 5 milliseconds at the start of the race.
In the second race, you could hold the button for at least 4 milliseconds and at most 11 milliseconds and beat the record, a total of 8 different ways to win.
In the third race, you could hold the button for at least 11 milliseconds and no more than 19 milliseconds and still beat the record, a total of 9 ways you could win.
To see how much margin of error you have, determine the number of ways you can beat the record in each race; in this example, if you multiply these values together, you get 288 (4 * 8 * 9).
Determine the number of ways you could beat the record in each race. What do you get if you multiply these numbers together?
Your puzzle answer was 275724.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
As the race is about to start, you realize the piece of paper with race times and record distances you got earlier actually just has very bad kerning. There's really only one race - ignore the spaces between the numbers on each line.
So, the example from before:
Time: 7 15 30
Distance: 9 40 200
...now instead means this:
Time: 71530
Distance: 940200
Now, you have to figure out how many ways there are to win this single race. In this example, the race lasts for 71530 milliseconds and the record distance you need to beat is 940200 millimeters. You could hold the button anywhere from 14 to 71516 milliseconds and beat the record, a total of 71503 ways!
How many ways can you beat the record in this one much longer race?
Your puzzle answer was 37286485.
Both parts of this puzzle are complete! They provide two gold stars: **

2
day6/test_input.txt Normal file
View File

@@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200

188
day7/day7.py Normal file
View File

@@ -0,0 +1,188 @@
import sys
sys.path.append('../lib')
import tools
from functools import total_ordering
HIGH = 1
PAIR = 2
TPAIR = 3
THREE = 4
FHOUSE = 5
FOUR = 6
FIVE = 7
DEFAULT_DECK = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
JOKER_DECK = ['J', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'Q', 'K', 'A']
# using decorator for sorting
@total_ordering
class Hand(object):
def __init__(self, cards, bid, deck=DEFAULT_DECK):
self.cards = cards
self.bid = bid
self.card_values = deck
self.power = 0
def __str__(self):
return f'cards: {self.cards}, bid: {self.bid}, power: {self.power}'
def __lt__(self, obj):
if self.power < obj.power:
return True
elif self.power == obj.power:
for i in range(len(self.cards)):
if self.card_values.index(self.cards[i]) < self.card_values.index(obj.cards[i]):
return True
elif self.card_values.index(self.cards[i]) > self.card_values.index(obj.cards[i]):
return False
return False
def __eq__(self, obj):
if self.power != obj.power:
return False
return self.cards == obj.cards
class HandDefaultDeck(Hand):
def __init__ (self, cards, bid):
super().__init__(cards, bid, deck=DEFAULT_DECK)
self._power()
def _power(self):
counter = dict()
for i in range(1, 4):
counter[i] = set()
# man this is ugly :)
for label in self.cards:
c = self.cards.count(label)
if c == 5:
self.power = FIVE
return
elif c == 4:
self.power = FOUR
return
else:
counter[c].add(label)
# end even uglier :)
if len(counter[2]) > 0 and len(counter[3]) > 0:
self.power = FHOUSE
elif len(counter[3]) > 0:
self.power = THREE
elif len(counter[2]) > 1:
self.power = TPAIR
elif len(counter[2]) > 0:
self.power = PAIR
else:
self.power = HIGH
class HandJokerDeck(Hand):
def __init__ (self, cards, bid):
super().__init__(cards, bid, deck=JOKER_DECK)
self._power()
def _power(self):
counter = dict()
for i in range(1, 5):
counter[i] = set()
jokers_count = 0
# man this is ugly :)
for label in self.cards:
if label == 'J':
jokers_count += 1
continue
c = self.cards.count(label)
if c == 5:
# there are five cards of same label,
# no jokers, good
self.power = FIVE
return
# otherwise we'll just memorize the counts
else:
counter[c].add(label)
if len(counter[4]) > 0:
self.power = FOUR
if len(counter[2]) > 0 and len(counter[3]) > 0:
self.power = FHOUSE
elif len(counter[3]) > 0:
self.power = THREE
elif len(counter[2]) > 1:
self.power = TPAIR
elif len(counter[2]) > 0:
self.power = PAIR
else:
self.power = HIGH
# let's apply jokers
for _ in range(jokers_count):
if self.power == PAIR:
self.power = THREE
elif self.power == TPAIR:
self.power = FHOUSE
elif self.power == THREE:
self.power = FOUR
else:
self.power += 1
if self.power == FIVE:
break
class HandsSet(object):
def __init__(self, inp, hand_subclass=HandDefaultDeck):
self.hands = []
for line in inp:
s = line.split()
h = hand_subclass(s[0], int(s[1]))
self.hands.append(h)
def __str__(self):
return '\n'.join(str(h) for h in self.hands)
def sort(self):
self.hands = sorted(self.hands)
def get_total_winnings(self):
self.sort()
total = 0
for rank, hand in enumerate(self.hands, start=1):
total += (rank * hand.bid)
return total
if __name__ == '__main__':
r = tools.Reader('test_input.txt')
lines = r.read()
hs = HandsSet(lines)
x = hs.get_total_winnings()
print(x)
hs = HandsSet(lines, hand_subclass=HandJokerDeck)
hs.sort()
#print(hs)
y = hs.get_total_winnings()
print(y)
r = tools.Reader('input.txt')
lines = r.read()
hs = HandsSet(lines)
x = hs.get_total_winnings()
print(x)
hs = HandsSet(lines, hand_subclass=HandJokerDeck)
hs.sort()
#print(hs)
y = hs.get_total_winnings()
print(y)

1000
day7/input.txt Normal file

File diff suppressed because it is too large Load Diff

76
day7/task.txt Normal file
View File

@@ -0,0 +1,76 @@
--- Day 7: Camel Cards ---
Your all-expenses-paid trip turns out to be a one-way, five-minute ride in an airship. (At least it's a cool airship!) It drops you off at the edge of a vast desert and descends back to Island Island.
"Did you bring the parts?"
You turn around to see an Elf completely covered in white clothing, wearing goggles, and riding a large camel.
"Did you bring the parts?" she asks again, louder this time. You aren't sure what parts she's looking for; you're here to figure out why the sand stopped.
"The parts! For the sand, yes! Come with me; I will show you." She beckons you onto the camel.
After riding a bit across the sands of Desert Island, you can see what look like very large rocks covering half of the horizon. The Elf explains that the rocks are all along the part of Desert Island that is directly above Island Island, making it hard to even get there. Normally, they use big machines to move the rocks and filter the sand, but the machines have broken down because Desert Island recently stopped receiving the parts they need to fix the machines.
You've already assumed it'll be your job to figure out why the parts stopped when she asks if you can help. You agree automatically.
Because the journey will take a few days, she offers to teach you the game of Camel Cards. Camel Cards is sort of similar to poker except it's designed to be easier to play while riding a camel.
In Camel Cards, you get a list of hands, and your goal is to order them based on the strength of each hand. A hand consists of five cards labeled one of A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2. The relative strength of each card follows this order, where A is the highest and 2 is the lowest.
Every hand is exactly one type. From strongest to weakest, they are:
Five of a kind, where all five cards have the same label: AAAAA
Four of a kind, where four cards have the same label and one card has a different label: AA8AA
Full house, where three cards have the same label, and the remaining two cards share a different label: 23332
Three of a kind, where three cards have the same label, and the remaining two cards are each different from any other card in the hand: TTT98
Two pair, where two cards share one label, two other cards share a second label, and the remaining card has a third label: 23432
One pair, where two cards share one label, and the other three cards have a different label from the pair and each other: A23A4
High card, where all cards' labels are distinct: 23456
Hands are primarily ordered based on type; for example, every full house is stronger than any three of a kind.
If two hands have the same type, a second ordering rule takes effect. Start by comparing the first card in each hand. If these cards are different, the hand with the stronger first card is considered stronger. If the first card in each hand have the same label, however, then move on to considering the second card in each hand. If they differ, the hand with the higher second card wins; otherwise, continue with the third card in each hand, then the fourth, then the fifth.
So, 33332 and 2AAAA are both four of a kind hands, but 33332 is stronger because its first card is stronger. Similarly, 77888 and 77788 are both a full house, but 77888 is stronger because its third card is stronger (and both hands have the same first and second card).
To play Camel Cards, you are given a list of hands and their corresponding bid (your puzzle input). For example:
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
This example shows five hands; each hand is followed by its bid amount. Each hand wins an amount equal to its bid multiplied by its rank, where the weakest hand gets rank 1, the second-weakest hand gets rank 2, and so on up to the strongest hand. Because there are five hands in this example, the strongest hand will have rank 5 and its bid will be multiplied by 5.
So, the first step is to put the hands in order of strength:
32T3K is the only one pair and the other hands are all a stronger type, so it gets rank 1.
KK677 and KTJJT are both two pair. Their first cards both have the same label, but the second card of KK677 is stronger (K vs T), so KTJJT gets rank 2 and KK677 gets rank 3.
T55J5 and QQQJA are both three of a kind. QQQJA has a stronger first card, so it gets rank 5 and T55J5 gets rank 4.
Now, you can determine the total winnings of this set of hands by adding up the result of multiplying each hand's bid with its rank (765 * 1 + 220 * 2 + 28 * 3 + 684 * 4 + 483 * 5). So the total winnings in this example are 6440.
Find the rank of every hand in your set. What are the total winnings?
Your puzzle answer was 250254244.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
To make things a little more interesting, the Elf introduces one additional rule. Now, J cards are jokers - wildcards that can act like whatever card would make the hand the strongest type possible.
To balance this, J cards are now the weakest individual cards, weaker even than 2. The other cards stay in the same order: A, K, Q, T, 9, 8, 7, 6, 5, 4, 3, 2, J.
J cards can pretend to be whatever card is best for the purpose of determining hand type; for example, QJJQ2 is now considered four of a kind. However, for the purpose of breaking ties between two hands of the same type, J is always treated as J, not the card it's pretending to be: JKKK2 is weaker than QQQQ2 because J is weaker than Q.
Now, the above example goes very differently:
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
32T3K is still the only one pair; it doesn't contain any jokers, so its strength doesn't increase.
KK677 is now the only two pair, making it the second-weakest hand.
T55J5, KTJJT, and QQQJA are now all four of a kind! T55J5 gets rank 3, QQQJA gets rank 4, and KTJJT gets rank 5.
With the new joker rule, the total winnings in this example are 5905.
Using the new joker rule, find the rank of every hand in your set. What are the new total winnings?

5
day7/test_input.txt Normal file
View File

@@ -0,0 +1,5 @@
32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483

127
day8/day8.py Normal file
View File

@@ -0,0 +1,127 @@
import sys, re
sys.path.append('../lib')
import tools
LEFT = 'L'
RIGHT = 'R'
class Instructions(object):
def __init__(self, inp: str):
self.curr = 0
self.instructions = list(inp)
def __iter__(self):
return self
def __next__(self):
instruction = self.instructions[self.curr]
self.curr = (self.curr + 1) % len(self.instructions)
return instruction
def reset(self):
self.curr = 0
class Node(object):
def __init__(self, value, left, right):
self.value = value
self.l = left
self.r = right
class Network(object):
def __init__(self):
self.m = dict()
self.curr = None
for l in lines:
pass
def add(self, n: Node):
self.m[n.value] = n
def get(self, name: str) -> Node:
n = self.m[name]
return n
def get_starting_nodes(self) -> list[Node]:
n = list()
for name, node in self.m.items():
if name.endswith('A'):
n.append(node)
return n
class Solver(object):
def __init__(self, lines):
instr = Instructions(lines[0])
self.instructions = instr
self.network = Network()
r = re.compile(r"(\w{3}) = \((\w{3}), (\w{3})\)")
for l in lines[2:]:
m = r.search(l)
n = Node(m.group(1), m.group(2), m.group(3))
self.network.add(n)
def find_num_steps(self, start: str, end: str) -> int:
steps = 0
self.instructions.reset()
curr = self.network.get(start)
for instr in self.instructions:
if curr.value == end:
break
if instr == LEFT:
curr = self.network.get(curr.l)
elif instr == RIGHT:
curr = self.network.get(curr.r)
steps += 1
return steps
def find_num_steps_for_all(self) -> int:
steps = 0
self.instructions.reset()
curr_list = self.network.get_starting_nodes()
for instr in self.instructions:
done = 0
for i in range(len(curr_list)):
if curr_list[i].value.endswith('Z'):
done += 1
if len(curr_list) == done:
break
for i in range(len(curr_list)):
if instr == LEFT:
curr_list[i] = self.network.get(curr_list[i].l)
elif instr == RIGHT:
curr_list[i] = self.network.get(curr_list[i].r)
steps += 1
return steps
if __name__ == '__main__':
r = tools.Reader('test_input.txt')
lines = r.read()
slvr = Solver(lines)
x = slvr.find_num_steps('AAA', 'ZZZ')
print(x)
y = slvr.find_num_steps_for_all()
print(y)
r = tools.Reader('input.txt')
lines = r.read()
slvr = Solver(lines)
x = slvr.find_num_steps('AAA', 'ZZZ')
print(x)
# y = slvr.find_num_steps_for_all()
# print(y)

752
day8/input.txt Normal file
View File

@@ -0,0 +1,752 @@
LRRLRRLRRLRRRLRRLRRRLRRLRRRLRLRLLRLRLRRLLLRLRLRRRLRRLRLRRRLRRLRRLRRLLLRRLRRRLRRRLRLLRRLRLLRRLRRRLRRLRLRRRLRLRLRRLRLRRRLLRRRLLRRRLRLRRRLRRLLRRLRRRLRRLRRLLRRLRRLRRRLLLRRRLRRLRRLRRLRLRRRLRRLLLLRLRRLRRRLRLLRRLRLLRRLRRRLRRRLRRRLLRRLRRLRRLRRRLRRLRRRLLRLRRRLRRRLRRRLLRRRLRRLRRRR
LRL = (MCG, TRC)
TNJ = (LMV, PMP)
GQK = (MGD, DBP)
KVK = (LHC, NMM)
PQX = (SLC, LSD)
GRR = (XCR, BJT)
RBF = (VDM, BFG)
TKN = (VDH, HGQ)
MMJ = (LTR, CNQ)
CCX = (FJJ, FKD)
VHD = (JFQ, DDH)
NRL = (CTM, XTJ)
SNH = (QDH, PSQ)
JTM = (VFH, QBR)
BJT = (GJL, JXD)
LBJ = (JFQ, DDH)
FPN = (PBT, SJR)
CGR = (NJC, CNF)
RCM = (GTQ, BBT)
BQQ = (FNS, KPL)
NSF = (SLD, SJV)
QFQ = (XNX, GHT)
QCZ = (JPG, NLJ)
RJD = (QDT, NSG)
CNK = (SKK, NFL)
CBR = (QDT, NSG)
QMV = (HXG, FHS)
DNL = (XLX, RDT)
XRS = (DHT, RDP)
GHV = (FHS, HXG)
MJM = (GQB, XCC)
GQC = (NKG, NSF)
RKH = (KVG, JCQ)
DKT = (LTN, LTN)
THR = (PHF, VKN)
BQV = (BTS, SCG)
BJJ = (GQC, QRR)
CQL = (LHK, BCD)
LXX = (LCX, FJV)
NSG = (VSX, DFN)
LSD = (JRL, KXC)
QKB = (NLJ, JPG)
HSK = (CFN, NTM)
BLL = (JJQ, MSN)
SQD = (BLK, LBK)
KVP = (DBB, RHN)
MLJ = (QQR, HDH)
QVB = (GMN, TDP)
HJB = (GPG, XDT)
NBX = (NVT, SNB)
CLL = (PLG, LHS)
AAA = (JXS, MFQ)
CHN = (RNL, FHV)
JHT = (JQF, JQX)
KSB = (VDL, VBD)
HBT = (CKB, CCX)
JXH = (MQH, PRD)
DBB = (XHL, CHN)
PBD = (RDB, VHH)
SDV = (VMG, NTV)
BJS = (NNG, RQH)
SLM = (BRB, FLG)
VDH = (QPG, GKG)
KNS = (VQX, HFR)
HBF = (RQC, MXC)
JSF = (KPL, FNS)
HLS = (TJQ, TKM)
TRV = (BVN, GKF)
NLJ = (GBH, JCT)
SVM = (DKT, XLG)
THK = (NTM, CFN)
MDK = (DNL, VXV)
MHV = (DQQ, MQX)
CNF = (QQH, SLN)
XJK = (VFH, QBR)
FNT = (HXR, HXR)
KCT = (CPX, FXC)
BDB = (NMP, JGG)
LRZ = (JXC, TNJ)
JBQ = (NDL, KSJ)
LJQ = (GHT, XNX)
HKD = (HFH, VHJ)
VDM = (GTD, HRP)
QQH = (THC, THR)
PRD = (KFR, TJK)
KKH = (VTJ, LSR)
LQS = (SJQ, RHD)
RLF = (LCR, SGG)
JHK = (PDJ, TRV)
QHG = (VMS, PKS)
JRL = (GVJ, SKL)
XDV = (PJL, JRN)
TSV = (KCR, QJP)
JSN = (QFQ, LJQ)
RLA = (JSN, JVD)
KPD = (RDK, NSS)
HXP = (RQT, QTS)
DDB = (SFH, RHV)
JGG = (BJG, JTS)
VBD = (SGD, FRJ)
HRP = (RJD, CBR)
RRT = (MLJ, MLJ)
NVD = (KHM, RBF)
TNK = (QSX, KVD)
NST = (CDL, VGL)
FLF = (SNF, KRN)
LHS = (BSD, DTD)
NCV = (KSB, PTG)
FMX = (QKX, XFP)
KMB = (FDM, BSX)
CRH = (CVV, DDS)
VGL = (JLS, CPK)
DBF = (KGB, PXQ)
RNM = (HTP, LVL)
HKC = (XML, RTK)
JLC = (TKN, VSV)
FLB = (NNG, RQH)
QKH = (GQM, LSB)
DTD = (FTJ, HCK)
BXS = (HKD, FDK)
TKV = (RHN, DBB)
QBJ = (KNS, DXQ)
LBS = (BHT, SFM)
VMS = (CTJ, DDC)
FQJ = (FVQ, GKR)
RQC = (LRF, HCM)
SSG = (GQK, HDV)
KPL = (GQS, MDK)
GJN = (PNN, CPB)
LHK = (QPD, GSV)
KFR = (KPD, DTV)
QXC = (QVM, BHJ)
XRH = (PKM, FPN)
CKL = (BBT, GTQ)
FPK = (CRV, MGR)
LTK = (LVT, HXF)
BLK = (BRT, BQN)
BSX = (XMS, XJN)
MMR = (JCG, HHX)
DVM = (LHK, BCD)
RCJ = (BDB, CFK)
QLN = (DDB, LDQ)
GKF = (QLV, FNP)
BXQ = (NKT, FFN)
HCM = (FPK, KQB)
HKG = (GQK, HDV)
FNS = (GQS, MDK)
CTJ = (NST, HDJ)
QQS = (GQB, XCC)
ZZZ = (MFQ, JXS)
MGK = (CRH, BRV)
LCR = (FRD, KMK)
BKD = (BNR, BKM)
LDB = (KLM, SCC)
PLS = (PBL, CRG)
FQR = (PNR, NCV)
TNL = (CDT, MKC)
KVH = (FJQ, SHJ)
KPT = (KGB, PXQ)
GQM = (BXQ, VLP)
FDR = (GLC, KGF)
DDC = (NST, HDJ)
MTJ = (TMT, TMB)
PBJ = (LTK, VFB)
JXS = (SBL, CQB)
XML = (BMK, QBL)
XSK = (KSN, KSN)
TKM = (TKQ, NTX)
XFP = (HBX, RMX)
DXQ = (VQX, HFR)
KRN = (CNK, JDM)
TJQ = (TKQ, NTX)
VQX = (LBJ, VHD)
TGX = (HLK, LDJ)
MCX = (GDH, BNS)
DKM = (TVC, LPB)
VXD = (GCF, SVD)
FGB = (BKM, BNR)
VNN = (VCS, BSR)
FXX = (LHC, NMM)
JKR = (TQN, GXV)
FRJ = (TDK, PKQ)
MMQ = (SCC, KLM)
XGL = (MSN, JJQ)
GTQ = (DMV, LLK)
KML = (MCX, CTT)
LBH = (LSR, VTJ)
BDS = (XJK, JTM)
FVH = (TSV, HHC)
KXN = (LRL, QKK)
HND = (HNQ, FSG)
JQS = (QLL, RKH)
CKD = (TBT, HBT)
PXP = (NXC, TTK)
VHP = (QJC, QKH)
KQL = (BQV, RJR)
FSG = (JBH, GPH)
BVN = (QLV, FNP)
HNV = (XFH, BKL)
CNJ = (MNT, DCG)
VSV = (HGQ, VDH)
PXB = (RRT, RRT)
FNK = (TKC, LTM)
VTX = (LDJ, HLK)
KKG = (QDL, SNT)
CTT = (GDH, BNS)
FJJ = (FNT, FNT)
JCS = (DDB, LDQ)
GDH = (TPG, DND)
FMF = (XHB, BNH)
QLL = (JCQ, KVG)
NJK = (RDB, VHH)
LHC = (QDS, SXP)
QHS = (KQL, SXQ)
BJQ = (BXB, HQT)
GJL = (BTX, GJC)
BNR = (NJK, PBD)
NFL = (NSC, FTL)
SKK = (FTL, NSC)
MQN = (FMF, KPC)
XHB = (DCS, SQD)
MDT = (TDP, GMN)
XBL = (TMT, TMB)
HFH = (XDV, DMD)
BSR = (VTX, TGX)
LDH = (BJQ, XJJ)
GXX = (KKL, RCJ)
PQZ = (HDH, QQR)
CXH = (VXD, SGC)
HPB = (VHR, FNQ)
LLF = (QVM, BHJ)
VQQ = (FQD, MQN)
GSV = (NDT, SLM)
GLR = (HVD, DMF)
SLC = (JRL, KXC)
RHV = (HBC, TFR)
PVX = (PLS, SJS)
LLK = (BDC, PNK)
SLL = (FJQ, SHJ)
LKT = (VPF, SSC)
MXC = (LRF, HCM)
FTL = (QSR, SVH)
GCF = (JTF, HJB)
VHZ = (RRN, TSH)
LNB = (DQQ, MQX)
DRQ = (XML, RTK)
XLG = (LTN, VLD)
LBL = (VVF, SPR)
MBB = (NFG, NFG)
QJC = (GQM, LSB)
LSR = (BJS, FLB)
MQH = (TJK, KFR)
DFN = (LXG, LLL)
MSN = (KXN, MPV)
JCT = (MHV, LNB)
TPG = (CJJ, RRD)
GCV = (NVT, SNB)
LNL = (GXX, DJM)
XFT = (TSH, RRN)
FSS = (SLC, LSD)
TKT = (TVC, LPB)
XBN = (NBX, GCV)
RQT = (QKF, XRS)
XCC = (MXL, RLF)
RTH = (QVB, MDT)
DBP = (HNV, XCG)
QQB = (JMF, PBJ)
KSJ = (NCS, RNM)
GNQ = (CPX, FXC)
HHX = (JKT, SVM)
SGG = (KMK, FRD)
SMM = (SJS, PLS)
VPK = (LTM, TKC)
VLD = (QKB, QCZ)
LTR = (TFX, FVN)
VCL = (DKM, TKT)
HXG = (MTG, SNM)
KGB = (MRV, LFD)
JGK = (CNJ, RXF)
FMV = (FRT, MNF)
SLD = (KVH, SLL)
VVL = (TNJ, JXC)
GDP = (RBF, KHM)
XDT = (RML, JHK)
JKP = (NDL, KSJ)
BNH = (SQD, DCS)
LFD = (LQC, HLS)
NHC = (JHT, SSM)
VPF = (NRN, LBL)
BHT = (LQS, MCP)
SNT = (RHL, BDS)
BQN = (XGL, BLL)
FVN = (HGP, QKM)
NXC = (KQJ, FMV)
NKG = (SJV, SLD)
HSF = (HPB, NFR)
QKM = (RRR, PMK)
PJL = (XBN, PFX)
MRP = (LCX, FJV)
XSQ = (FDK, HKD)
TVC = (GHN, QQC)
XLX = (DKJ, NNT)
VSX = (LLL, LXG)
FQD = (FMF, KPC)
PNJ = (XCR, BJT)
QDV = (QRJ, BFS)
QVG = (GLC, KGF)
BMK = (RJS, FLF)
SXQ = (BQV, RJR)
BGL = (CSB, SBH)
BJG = (CNH, PQJ)
RSG = (QFT, VPD)
VVF = (DRQ, HKC)
BBT = (LLK, DMV)
HGQ = (GKG, QPG)
HMD = (PHT, PCD)
PPL = (CKL, RCM)
QLA = (TSH, RRN)
KBG = (HBT, TBT)
RHD = (HKG, SSG)
GQB = (RLF, MXL)
QFA = (QQR, HDH)
KPC = (BNH, XHB)
XNX = (FVH, MNH)
HBX = (NFD, VJF)
SVD = (HJB, JTF)
DMD = (JRN, PJL)
PKJ = (BJQ, XJJ)
TFX = (HGP, QKM)
MCH = (PKD, PFF)
SGD = (PKQ, TDK)
RRJ = (KCT, GNQ)
PJD = (VLM, JJZ)
PHF = (PQX, FSS)
PKQ = (NTP, MMR)
VPD = (QHB, NHC)
FRD = (GDP, NVD)
SFH = (HBC, TFR)
JRN = (XBN, PFX)
HSB = (MRP, LXX)
RMX = (NFD, VJF)
SBH = (JXH, TSQ)
NTP = (JCG, HHX)
PSX = (FMX, PCR)
LCQ = (PKS, VMS)
LKV = (SMM, PVX)
SGC = (SVD, GCF)
CQB = (LDD, QDV)
FRT = (XCV, HSF)
KGT = (SGC, VXD)
TRC = (PSX, NQC)
BSG = (PKD, PFF)
CKB = (FJJ, FKD)
SSM = (JQF, JQX)
DKJ = (BKD, FGB)
TKC = (TXS, FQJ)
JQX = (DVQ, NLN)
BDC = (KNL, DSV)
FJV = (MTJ, XBL)
DND = (CJJ, RRD)
PPH = (MMQ, LDB)
FTJ = (LKT, GNX)
JKV = (RFM, MGK)
KCR = (LLF, QXC)
RFN = (LJL, CFX)
HCF = (NFG, HSR)
NTV = (JXG, VHP)
QQR = (DTX, HND)
BTX = (QVG, FDR)
JQK = (SXQ, KQL)
NJC = (SLN, QQH)
RML = (PDJ, TRV)
SNF = (JDM, CNK)
KMK = (GDP, NVD)
XSH = (DXQ, KNS)
DTX = (HNQ, FSG)
BNS = (TPG, DND)
KHM = (BFG, VDM)
SBF = (MGK, RFM)
NFD = (PKJ, LDH)
BHJ = (VNN, CGL)
TXS = (FVQ, GKR)
CRV = (NTQ, SDV)
GHT = (FVH, MNH)
RBN = (RQC, MXC)
KKL = (BDB, CFK)
NLN = (RBN, HBF)
QFT = (NHC, QHB)
QBL = (FLF, RJS)
RHG = (PNN, CPB)
MNF = (XCV, HSF)
SJS = (CRG, PBL)
FDK = (VHJ, HFH)
HXM = (JJD, JJD)
PNN = (QDK, MMJ)
GCS = (TTK, NXC)
VJF = (LDH, PKJ)
GTD = (CBR, RJD)
RRD = (TPL, XVR)
JXC = (LMV, PMP)
NXH = (MKC, CDT)
HCK = (GNX, LKT)
BRC = (QLL, RKH)
KQB = (CRV, MGR)
TMB = (MCH, BSG)
XJN = (RSX, JGK)
HQP = (SFM, BHT)
HQT = (MBB, HCF)
THC = (VKN, PHF)
TPL = (NGD, QQB)
NGD = (PBJ, JMF)
GVJ = (RNT, LKV)
QDK = (LTR, CNQ)
JXG = (QKH, QJC)
TQN = (KRL, QCV)
RDB = (JQS, BRC)
MPV = (LRL, QKK)
SJQ = (HKG, SSG)
XHL = (RNL, FHV)
LRF = (KQB, FPK)
GNX = (SSC, VPF)
VXV = (XLX, RDT)
MTG = (CCR, CRR)
NFG = (BHH, BHH)
DSV = (PXB, PJN)
CVT = (KPT, DBF)
RHL = (JTM, XJK)
CBQ = (GXL, PQB)
BHH = (JXS, MFQ)
DMV = (BDC, PNK)
NSS = (HQP, LBS)
FVM = (PRP, RFN)
NCS = (HTP, LVL)
QPD = (NDT, SLM)
GJC = (FDR, QVG)
CFK = (JGG, NMP)
HDV = (MGD, DBP)
PNB = (PQB, GXL)
RXA = (NLJ, JPG)
CNH = (JSF, BQQ)
VXL = (HXR, XQQ)
QKF = (RDP, DHT)
QTS = (QKF, XRS)
VDL = (SGD, FRJ)
FCM = (TQN, GXV)
BHQ = (GQC, QRR)
BSD = (FTJ, HCK)
CJJ = (TPL, XVR)
PLG = (DTD, BSD)
LQC = (TKM, TJQ)
NTM = (KLG, PPL)
SHJ = (NRL, NMS)
QDL = (BDS, RHL)
PCR = (XFP, QKX)
XCG = (XFH, BKL)
LMV = (GCS, PXP)
JJD = (QQV, QQV)
HGP = (PMK, RRR)
TNF = (RQT, QTS)
SFM = (MCP, LQS)
MNR = (RFN, PRP)
LLL = (CBQ, PNB)
RJS = (SNF, KRN)
BRV = (CVV, DDS)
GGK = (LHS, PLG)
HVD = (GBJ, VQQ)
KQJ = (FRT, MNF)
PMK = (CGR, PQR)
MFB = (GGK, CLL)
HLK = (NTG, KMB)
BKL = (CQL, DVM)
SVT = (CSB, SBH)
FGD = (PNR, NCV)
LVT = (VCL, XTQ)
MFQ = (SBL, CQB)
SCC = (KKH, LBH)
JMF = (VFB, LTK)
GLC = (FBS, DNB)
HFT = (MMQ, LDB)
PNR = (PTG, KSB)
SNM = (CRR, CCR)
TJK = (DTV, KPD)
PQR = (NJC, CNF)
VPM = (QDL, SNT)
DHT = (KGT, CXH)
RPK = (KML, XRL)
VFH = (HSB, QBV)
FNP = (JBQ, JKP)
JLS = (QLN, JCS)
XMS = (JGK, RSX)
FRK = (GGK, CLL)
PDJ = (GKF, BVN)
QDH = (JLC, QTG)
PFX = (GCV, NBX)
BXB = (MBB, MBB)
TTK = (KQJ, FMV)
PKS = (DDC, CTJ)
KLG = (RCM, CKL)
CSV = (QVB, MDT)
NNG = (DXR, BPD)
HHC = (KCR, QJP)
LVL = (CSQ, TKJ)
QHB = (JHT, SSM)
JDM = (SKK, NFL)
JCQ = (TNK, LPJ)
TSQ = (MQH, PRD)
JTS = (PQJ, CNH)
RCR = (KCT, GNQ)
LXG = (CBQ, PNB)
TKQ = (HXP, TNF)
PKM = (PBT, SJR)
GXV = (QCV, KRL)
HJS = (BBX, RPK)
CPX = (XSK, XSK)
JXD = (BTX, GJC)
CVV = (HXM, VDB)
SBL = (LDD, QDV)
HBC = (VPM, KKG)
DXR = (CVT, KKS)
VDB = (JJD, BVS)
XQQ = (VVL, LRZ)
PQB = (BXS, XSQ)
NTX = (HXP, TNF)
SCG = (VMQ, HJS)
GHN = (SBF, JKV)
VXR = (SGL, LMC)
NQF = (VPD, QFT)
DDS = (HXM, VDB)
KLM = (LBH, KKH)
SGL = (QRL, KLQ)
GKR = (CSV, RTH)
QDT = (DFN, VSX)
MNT = (SNH, FPP)
TDP = (TKV, KVP)
KNL = (PXB, PXB)
GMN = (KVP, TKV)
MXL = (SGG, LCR)
PKD = (FXX, KVK)
SXP = (FNK, VPK)
NTG = (BSX, FDM)
QSR = (KBG, CKD)
FHV = (XCL, MBP)
RDT = (NNT, DKJ)
SPR = (HKC, DRQ)
FFN = (JHD, GLR)
FBS = (QXL, FTF)
VLP = (FFN, NKT)
KXC = (SKL, GVJ)
TKJ = (FQR, FGD)
LHH = (PHT, PCD)
CTM = (GHV, QMV)
VHH = (JQS, BRC)
MQX = (MJM, QQS)
BBX = (XRL, KML)
LKK = (PKM, FPN)
RNT = (PVX, SMM)
JSA = (TNJ, JXC)
RDK = (LBS, HQP)
RXF = (MNT, DCG)
HDH = (HND, DTX)
VKN = (FSS, PQX)
LSB = (VLP, BXQ)
BPD = (CVT, KKS)
TMT = (BSG, MCH)
QLV = (JBQ, JKP)
LPJ = (KVD, QSX)
QDS = (VPK, FNK)
GQS = (VXV, DNL)
DTV = (NSS, RDK)
SNB = (JLB, LLV)
NMM = (SXP, QDS)
CSB = (TSQ, JXH)
PFF = (FXX, KVK)
VHJ = (XDV, DMD)
XFX = (KSN, THB)
CCR = (NQF, RSG)
VMQ = (BBX, RPK)
HXR = (VVL, VVL)
SJV = (KVH, SLL)
CFN = (KLG, PPL)
DDH = (RHG, GJN)
FLG = (HMD, LHH)
FVQ = (RTH, CSV)
RTK = (BMK, QBL)
NSC = (SVH, QSR)
MKC = (FCM, JKR)
XTJ = (GHV, QMV)
CNQ = (FVN, TFX)
SJR = (BJJ, BHQ)
MGR = (NTQ, SDV)
XFH = (DVM, CQL)
QSX = (GRR, PNJ)
QKX = (HBX, RMX)
LBK = (BQN, BRT)
PXQ = (MRV, LFD)
LDQ = (SFH, RHV)
MNH = (HHC, TSV)
XCV = (HPB, NFR)
KLQ = (QBJ, XSH)
FTF = (SCQ, RGC)
JJQ = (MPV, KXN)
LJL = (VDV, SJJ)
DNB = (FTF, QXL)
CFX = (VDV, SJJ)
JKT = (DKT, DKT)
SJJ = (THK, HSK)
CDL = (JLS, CPK)
QCV = (XRH, LKK)
XCR = (GJL, JXD)
KMJ = (MLJ, PQZ)
MPS = (DJM, GXX)
GBJ = (MQN, FQD)
PNK = (KNL, DSV)
BRB = (HMD, LHH)
PBT = (BJJ, BHQ)
JPG = (JCT, GBH)
HSR = (BHH, ZZZ)
DQQ = (QQS, MJM)
MCP = (SJQ, RHD)
LTM = (TXS, FQJ)
KKS = (KPT, DBF)
DCG = (FPP, SNH)
TDK = (MMR, NTP)
QJP = (LLF, QXC)
NFR = (FNQ, VHR)
FKD = (FNT, VXL)
LMC = (KLQ, QRL)
PBL = (FVM, MNR)
JHD = (DMF, HVD)
CRR = (RSG, NQF)
JJZ = (JVD, JSN)
RQH = (DXR, BPD)
HXF = (VCL, XTQ)
CRG = (MNR, FVM)
VHR = (QHG, LCQ)
VCS = (VTX, TGX)
FPP = (QDH, PSQ)
KSN = (XFT, XFT)
BVS = (QQV, PJD)
RSX = (RXF, CNJ)
FXC = (XSK, XFX)
HDJ = (CDL, VGL)
QQC = (SBF, JKV)
LPB = (GHN, QQC)
LRJ = (QHS, JQK)
SCQ = (RCR, RRJ)
PQJ = (JSF, BQQ)
GKG = (VMJ, LRJ)
SSC = (NRN, LBL)
NVT = (JLB, LLV)
KVD = (GRR, PNJ)
XRL = (CTT, MCX)
BTS = (VMQ, HJS)
KRL = (XRH, LKK)
RRN = (BGL, SVT)
FHS = (SNM, MTG)
QPG = (VMJ, LRJ)
QKK = (TRC, MCG)
VDV = (THK, HSK)
GPH = (VXR, GKQ)
RNL = (XCL, MBP)
SLN = (THC, THR)
CPB = (MMJ, QDK)
NMS = (XTJ, CTM)
RJR = (BTS, SCG)
CGL = (VCS, BSR)
MBP = (MFB, FRK)
NNT = (FGB, BKD)
HTP = (CSQ, TKJ)
GPG = (RML, JHK)
QRL = (QBJ, XSH)
BCD = (GSV, QPD)
QQV = (VLM, VLM)
PRP = (CFX, LJL)
TFR = (KKG, VPM)
LDD = (QRJ, BFS)
QVM = (VNN, CGL)
KGF = (FBS, DNB)
GBH = (MHV, LNB)
JCG = (JKT, SVM)
FJQ = (NMS, NRL)
QXL = (RGC, SCQ)
NRN = (SPR, VVF)
FDM = (XMS, XJN)
RFM = (BRV, CRH)
NKT = (GLR, JHD)
HFR = (VHD, LBJ)
THB = (XFT, VHZ)
XJJ = (BXB, HQT)
QTG = (VSV, TKN)
NQC = (PCR, FMX)
JLB = (HFT, PPH)
GXL = (BXS, XSQ)
PSQ = (QTG, JLC)
NDT = (BRB, FLG)
PJN = (RRT, KMJ)
TBT = (CKB, CCX)
JBH = (GKQ, VXR)
XVR = (QQB, NGD)
BRT = (XGL, BLL)
PCD = (MPS, LNL)
SKL = (RNT, LKV)
TSH = (BGL, SVT)
JQF = (DVQ, NLN)
DVQ = (RBN, HBF)
RGC = (RCR, RRJ)
QRJ = (TNL, NXH)
XCL = (MFB, FRK)
VLM = (JSN, JVD)
RDP = (KGT, CXH)
VTJ = (FLB, BJS)
LCX = (XBL, MTJ)
JVD = (QFQ, LJQ)
BKM = (NJK, PBD)
VMJ = (QHS, JQK)
DMF = (VQQ, GBJ)
CDT = (FCM, JKR)
NTQ = (NTV, VMG)
QRR = (NSF, NKG)
NDL = (RNM, NCS)
KVG = (LPJ, TNK)
DCS = (BLK, LBK)
JFQ = (RHG, GJN)
GKQ = (SGL, LMC)
JTF = (GPG, XDT)
SVH = (CKD, KBG)
RRR = (PQR, CGR)
RHN = (CHN, XHL)
HNQ = (GPH, JBH)
BFG = (GTD, HRP)
LLV = (PPH, HFT)
NMP = (BJG, JTS)
CSQ = (FQR, FGD)
MRV = (HLS, LQC)
LDJ = (KMB, NTG)
PHT = (LNL, MPS)
DJM = (RCJ, KKL)
PTG = (VBD, VDL)
PMP = (PXP, GCS)
LTN = (QKB, QKB)
BFS = (NXH, TNL)
MGD = (XCG, HNV)
QBV = (MRP, LXX)
VFB = (LVT, HXF)
XTQ = (TKT, DKM)
QBR = (QBV, HSB)
CPK = (QLN, JCS)
MCG = (NQC, PSX)
VMG = (VHP, JXG)
FNQ = (LCQ, QHG)

66
day8/task.txt Normal file
View File

@@ -0,0 +1,66 @@
--- Day 8: Haunted Wasteland ---
You're still riding a camel across Desert Island when you spot a sandstorm quickly approaching. When you turn to warn the Elf, she disappears before your eyes! To be fair, she had just finished warning you about ghosts a few minutes ago.
One of the camel's pouches is labeled "maps" - sure enough, it's full of documents (your puzzle input) about how to navigate the desert. At least, you're pretty sure that's what they are; one of the documents contains a list of left/right instructions, and the rest of the documents seem to describe some kind of network of labeled nodes.
It seems like you're meant to use the left/right instructions to navigate the network. Perhaps if you have the camel follow the same instructions, you can escape the haunted wasteland!
After examining the maps for a bit, two nodes stick out: AAA and ZZZ. You feel like AAA is where you are now, and you have to follow the left/right instructions until you reach ZZZ.
This format defines each node of the network individually. For example:
RL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)
Starting with AAA, you need to look up the next element based on the next left/right instruction in your input. In this example, start with AAA and go right (R) by choosing the right element of AAA, CCC. Then, L means to choose the left element of CCC, ZZZ. By following the left/right instructions, you reach ZZZ in 2 steps.
Of course, you might not find ZZZ right away. If you run out of left/right instructions, repeat the whole sequence of instructions as necessary: RL really means RLRLRLRLRLRLRLRL... and so on. For example, here is a situation that takes 6 steps to reach ZZZ:
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)
Starting at AAA, follow the left/right instructions. How many steps are required to reach ZZZ?
Your puzzle answer was 18157.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
The sandstorm is upon you and you aren't any closer to escaping the wasteland. You had the camel follow the instructions, but you've barely left your starting position. It's going to take significantly more steps to escape!
What if the map isn't for people - what if the map is for ghosts? Are ghosts even bound by the laws of spacetime? Only one way to find out.
After examining the maps a bit longer, your attention is drawn to a curious fact: the number of nodes with names ending in A is equal to the number ending in Z! If you were a ghost, you'd probably just start at every node that ends with A and follow all of the paths at the same time until they all simultaneously end up at nodes that end with Z.
For example:
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)
Here, there are two starting nodes, 11A and 22A (because they both end with A). As you follow each left/right instruction, use that instruction to simultaneously navigate away from both nodes you're currently on. Repeat this process until all of the nodes you're currently on end with Z. (If only some of the nodes you're on end with Z, they act like any other node and you continue as normal.) In this example, you would proceed as follows:
Step 0: You are at 11A and 22A.
Step 1: You choose all of the left paths, leading you to 11B and 22B.
Step 2: You choose all of the right paths, leading you to 11Z and 22C.
Step 3: You choose all of the left paths, leading you to 11B and 22Z.
Step 4: You choose all of the right paths, leading you to 11Z and 22B.
Step 5: You choose all of the left paths, leading you to 11B and 22C.
Step 6: You choose all of the right paths, leading you to 11Z and 22Z.
So, in this example, you end up entirely on nodes that end in Z after 6 steps.
Simultaneously start on every node that ends with A. How many steps does it take before you're only on nodes that end with Z?

5
day8/test_input.txt Normal file
View File

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

10
day8/test_input2.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)

98
day9/day9.py Normal file
View File

@@ -0,0 +1,98 @@
import sys
sys.path.append('../lib')
import tools
class History(object):
def __init__(self, nums: list[int]):
self.history = nums
def __str__(self):
return ' '.join(str(n) for n in self.history)
def extrapolate_forward(self):
ends = list()
curr = self.history.copy()
while not all([True if n == 0 else False for n in curr]):
ends.append(curr[-1])
curr = [curr[i+1] - curr[i] for i in range(len(curr)-1)]
new_val = sum(ends)
self.history.append(new_val)
def extrapolate_backward(self):
starts = list()
curr = self.history.copy()
while not all([True if n == 0 else False for n in curr]):
starts.append(curr[0])
curr = [curr[i+1] - curr[i] for i in range(len(curr)-1)]
new_val = 0
for n in reversed(starts):
new_val = n - new_val
self.history.insert(0, new_val)
def get_last_value(self):
return self.history[-1]
def get_first_value(self):
return self.history[0]
class Report(object):
def __init__(self, lines):
self.histories = list()
for line in lines:
values = [int(n) for n in line.split()]
h = History(values)
self.histories.append(h)
def __str__(self):
out = f'Histories:\n'
for h in self.histories:
out += str(h) + '\n'
return out
def extrapolate_all_forward(self):
for h in self.histories:
h.extrapolate_forward()
def extapolate_all_backwards(self):
for h in self.histories:
h.extrapolate_backward()
def get_sum_of_last_values(self) -> int:
total = sum([h.get_last_value() for h in self.histories])
return total
def get_sum_of_first_values(self) -> int:
total = sum([h.get_first_value() for h in self.histories])
return total
if __name__ == '__main__':
r = tools.Reader('test_input.txt')
lines = r.read()
r = Report(lines)
r.extrapolate_all_forward()
r.extapolate_all_backwards()
print(r)
x = r.get_sum_of_last_values()
print(x)
y = r.get_sum_of_first_values()
print(y)
r = tools.Reader('input.txt')
lines = r.read()
r = Report(lines)
r.extrapolate_all_forward()
r.extapolate_all_backwards()
x = r.get_sum_of_last_values()
print(x)
y = r.get_sum_of_first_values()
print(y)

200
day9/input.txt Normal file
View File

@@ -0,0 +1,200 @@
25 43 75 138 255 455 773 1250 1933 2875 4135 5778 7875 10503 13745 17690 22433 28075 34723 42490 51495
15 22 50 114 229 410 672 1030 1499 2094 2830 3722 4785 6034 7484 9150 11047 13190 15594 18274 21245
25 37 45 57 103 257 670 1617 3564 7271 13964 25633 45561 79327 136917 237555 421062 774117 1488793 2987794 6182124
3 17 54 120 230 425 791 1489 2829 5466 10872 22355 47064 99648 208537 426194 845159 1622279 3014202 5428018 9491866
25 47 77 111 155 235 402 724 1251 1932 2462 2054 -809 -8433 -23232 -45063 -64008 -43580 115154 646196 2060426
9 15 39 95 208 426 851 1716 3546 7461 15730 32813 67431 136877 276189 557604 1131039 2306127 4713741 9615035 19476706
1 -6 -8 15 106 342 853 1867 3810 7496 14449 27435 51408 95395 176521 328632 620115 1188930 2308050 4502051 8746226
12 17 22 27 32 37 42 47 52 57 62 67 72 77 82 87 92 97 102 107 112
17 18 18 15 3 -16 -9 122 585 1754 4236 8949 17211 30840 52265 84648 132017 199410 293030 420411 590595
-4 10 52 139 306 624 1231 2386 4556 8546 15682 28057 48850 82728 136341 218920 342988 525194 787280 1157191 1670338
-1 9 22 33 37 29 4 -43 -117 -223 -366 -551 -783 -1067 -1408 -1811 -2281 -2823 -3442 -4143 -4931
12 25 38 51 64 77 90 103 116 129 142 155 168 181 194 207 220 233 246 259 272
4 13 46 121 263 512 939 1685 3051 5677 10848 20953 40109 74975 135876 238622 407970 684713 1140118 1904165 3218119
9 5 4 10 27 59 110 184 285 417 584 790 1039 1335 1682 2084 2545 3069 3660 4322 5059
11 17 31 60 115 216 406 790 1625 3499 7665 16678 35706 75431 158678 335480 716439 1544189 3341367 7207300 15395413
1 3 12 42 111 241 458 792 1277 1951 2856 4038 5547 7437 9766 12596 15993 20027 24772 30306 36711
8 14 20 26 32 38 44 50 56 62 68 74 80 86 92 98 104 110 116 122 128
2 17 45 90 167 309 573 1045 1844 3125 5081 7944 11985 17513 24873 34443 46630 61865 80597 103286 130395
3 5 8 25 83 230 541 1117 2066 3459 5278 7432 10045 14499 26326 62366 167432 451676 1172223 2907858 6925638
15 31 53 81 115 155 201 253 311 375 445 521 603 691 785 885 991 1103 1221 1345 1475
24 43 79 142 248 434 777 1425 2670 5120 10065 20208 41107 84069 172095 352295 721984 1483393 3057187 6314066 13037102
13 27 44 74 134 244 434 784 1532 3314 7658 17954 41277 91663 195742 402030 795687 1521173 2815992 5059618 8842760
-5 6 26 65 149 320 644 1246 2412 4831 10091 21583 45992 95545 191119 366158 671073 1177364 1980064 3196213 4955871
14 20 31 51 92 179 352 674 1274 2485 5189 11576 26705 61603 139298 306401 655034 1363686 2771955 5514593 10757022
8 20 31 43 76 193 546 1449 3498 7798 16438 33501 67151 133785 266032 527840 1042692 2046618 3989373 7731849 14939606
-2 13 44 108 239 501 1024 2092 4340 9158 19454 40995 84625 169752 329602 618857 1124426 1980243 3387144 5639046 9156835
15 23 45 84 135 188 234 271 307 357 431 510 507 210 -796 -3231 -8249 -17597 -33807 -60424 -102273
19 24 29 34 39 44 49 54 59 64 69 74 79 84 89 94 99 104 109 114 119
16 22 33 66 144 295 567 1067 2029 3920 7606 14625 27670 51529 95095 175938 330930 640746 1285035 2662828 5646480
18 20 33 73 155 290 482 725 1000 1272 1487 1569 1417 902 -136 -1891 -4594 -8516 -13971 -21319 -30969
9 23 52 101 177 296 489 820 1443 2739 5588 11845 25103 51840 103061 196560 359941 634551 1080492 1782893 2859637
23 37 52 75 129 267 593 1301 2757 5675 11489 23130 46640 94494 192307 391989 796663 1606149 3197006 6258585 12016967
5 25 58 104 163 235 320 418 529 653 790 940 1103 1279 1468 1670 1885 2113 2354 2608 2875
7 22 47 94 178 326 611 1226 2620 5742 12503 26703 55923 115304 234789 472363 937173 1828238 3496871 6544044 11967856
-2 6 24 52 90 138 196 264 342 430 528 636 754 882 1020 1168 1326 1494 1672 1860 2058
15 36 70 118 185 296 529 1079 2385 5385 12023 26230 55766 115612 234193 464886 907519 1748686 3336864 6320194 11893675
18 42 88 181 356 667 1211 2170 3871 6868 12079 21090 36899 65655 120396 228459 445184 877830 1725338 3341795 6334262
10 26 46 67 86 100 106 101 82 46 -10 -89 -194 -328 -494 -695 -934 -1214 -1538 -1909 -2330
1 1 13 54 148 337 710 1457 2948 5823 11054 19900 33617 52703 75349 94627 93771 38693 -133381 -530574 -1330094
7 18 39 90 201 408 744 1225 1831 2482 3009 3120 2361 72 -4662 -13065 -26729 -47678 -78437 -122106 -182439
7 0 1 27 100 247 500 896 1477 2290 3387 4825 6666 8977 11830 15302 19475 24436 30277 37095 44992
0 0 1 1 -1 -2 7 42 127 297 606 1144 2068 3653 6370 10999 18786 31654 52479 85443 136477
24 34 41 55 97 200 413 808 1490 2610 4381 7097 11155 17080 25553 37442 53836 76082 105825 145051 196133
6 4 19 65 166 375 815 1766 3846 8378 18116 38645 80997 166359 334236 656234 1259234 2365352 4364329 7951905 14404284
11 12 16 29 58 106 167 221 229 128 -174 -803 -1924 -3746 -6527 -10579 -16273 -24044 -34396 -47907 -65234
14 27 63 147 328 703 1456 2923 5710 10912 20507 38030 69668 125958 224316 392676 674574 1136073 1874991 3032965 4810960
13 25 30 25 4 -32 -43 124 895 3293 9553 24231 56132 121576 249820 491898 934777 1723609 3096048 5434165 9341508
8 16 42 96 184 318 544 1000 2022 4316 9216 19077 37959 73044 137896 260121 498946 984006 1997384 4140260 8659152
4 20 57 125 234 394 615 907 1280 1744 2309 2985 3782 4710 5779 6999 8380 9932 11665 13589 15714
18 36 76 154 300 567 1040 1845 3158 5214 8316 12844 19264 28137 40128 56015 76698 103208 136716 178542 230164
6 17 34 72 167 394 893 1903 3804 7167 12812 21874 35877 56816 87247 130385 190210 271581 380358 523532 709363
16 17 14 0 -26 -49 -17 202 891 2575 6106 12709 23985 41967 69541 111931 180570 301613 532678 993222 1916376
24 36 60 106 189 342 632 1188 2268 4418 8811 17901 36591 74202 147651 286411 540048 989424 1763038 3060468 5185497
14 21 28 35 42 49 56 63 70 77 84 91 98 105 112 119 126 133 140 147 154
8 14 15 5 -26 -94 -224 -454 -840 -1462 -2431 -3897 -6058 -9170 -13558 -19628 -27880 -38922 -53485 -72439 -96810
9 8 8 30 120 366 922 2039 4103 7680 13568 22856 36990 57846 87810 129865 187685 265736 369384 505010 680132
2 3 14 59 175 416 867 1692 3257 6397 12943 26699 55168 112478 224162 434708 819124 1500167 2673372 4642595 7869461
14 22 53 124 254 464 777 1218 1814 2594 3589 4832 6358 8204 10409 13014 16062 19598 23669 28324 33614
4 15 31 65 143 306 624 1245 2523 5296 11418 24688 52364 107501 212409 403590 738582 1305213 2233849 3713307 6011197
20 29 45 77 136 238 423 800 1644 3609 8197 18762 42564 94764 205819 434557 890356 1769397 3411997 6390651 11641728
2 -5 -12 -3 49 194 530 1239 2632 5201 9676 17085 28815 46672 72938 110423 162510 233191 327092 449485 606285
27 48 74 110 170 277 463 769 1245 1950 2952 4328 6164 8555 11605 15427 20143 25884 32790 41010 50702
15 28 57 105 168 238 317 459 883 2244 6224 16734 42234 100024 223888 477248 975079 1919332 3654603 6753375 12143460
16 34 66 112 172 246 334 436 552 682 826 984 1156 1342 1542 1756 1984 2226 2482 2752 3036
10 12 26 68 166 373 788 1585 3050 5626 9966 16994 27974 44587 69016 104039 153130 220568 311554 432336 590342
9 33 82 178 362 705 1335 2492 4623 8529 15576 27982 49192 84353 140901 229272 363749 563457 853518 1266378 1843318
10 8 21 71 194 447 915 1718 3018 5026 8009 12297 18290 26465 37383 51696 70154 93612 123037 159515 204258
2 17 51 109 205 370 663 1197 2198 4121 7853 15039 28573 53302 96997 171651 295170 493529 803471 1275833 1979589
12 20 44 98 202 398 780 1550 3128 6369 12986 26380 53305 107260 215363 431941 864440 1720854 3393084 6597914 12607128
21 51 110 218 400 684 1110 1765 2865 4914 8996 17324 34313 68700 137643 274332 541473 1054089 2016438 3779482 6927242
18 32 46 60 74 88 102 116 130 144 158 172 186 200 214 228 242 256 270 284 298
-8 -12 -10 0 23 86 280 848 2350 5938 13767 29549 59223 111662 199265 338185 547820 849040 1260436 1791654 2432615
18 35 57 78 83 57 7 -3 196 939 2801 6684 13917 26369 46575 77875 124566 192067 287097 417866 594279
6 9 15 24 43 93 223 543 1291 2952 6450 13437 26706 50758 92556 162502 275676 453379 725025 1130430 1722549
11 12 20 55 160 420 998 2194 4525 8817 16309 28822 49187 82417 138630 239583 431979 812594 1572886 3074249 5969622
13 20 31 46 58 58 47 59 217 882 3020 9022 24420 61383 145852 332290 734422 1589037 3386318 7129763 14840179
-3 3 20 48 87 137 198 270 353 447 552 668 795 933 1082 1242 1413 1595 1788 1992 2207
16 30 55 106 201 363 639 1146 2154 4216 8355 16318 30907 56397 99051 167742 274692 436338 674335 1016706 1499149
18 37 74 140 247 401 590 765 826 655 298 511 4079 18621 62034 172324 424330 956761 2014010 4008334 7609119
11 17 23 29 35 41 47 53 59 65 71 77 83 89 95 101 107 113 119 125 131
21 34 52 89 171 342 674 1282 2364 4316 8023 15535 31590 67018 146244 323350 715118 1566195 3372779 7110296 14643524
4 14 29 52 97 209 496 1173 2618 5440 10559 19298 33487 55579 88778 137179 205920 301346 431185 604736 833069
17 23 38 66 104 143 181 269 628 1909 5729 15718 39484 92203 203086 427013 865693 1706967 3299762 6300778 11967458
6 15 27 46 88 204 522 1314 3104 6852 14277 28419 54586 101887 185616 330825 577506 987893 1656495 2723580 4392948
8 13 24 43 71 112 173 263 401 662 1333 3330 9154 24851 63700 152696 343334 728747 1469918 2834485 5252601
15 28 54 115 244 488 911 1597 2653 4212 6436 9519 13690 19216 26405 35609 47227 61708 79554 101323 127632
21 36 66 119 213 398 801 1708 3700 7863 16095 31536 59150 106491 184688 309687 503791 797542 1231992 1861413 2756499
11 37 85 163 276 427 625 916 1462 2699 5608 12133 25777 52401 101242 186154 327061 551593 896855 1411255 2156290
-8 3 34 100 228 459 847 1467 2465 4216 7711 15396 32890 72420 159609 346723 738050 1537353 3134140 6255932 12229220
8 19 35 63 128 277 592 1224 2460 4835 9301 17465 31908 56597 97402 162730 264288 417987 644999 972979 1437464
-6 -10 -20 -45 -104 -225 -441 -771 -1154 -1267 -94 4992 20051 58048 145352 333842 723414 1503576 3029356 5957273 11483438
14 23 37 65 133 309 745 1746 3887 8218 16642 32656 62862 120056 229382 440113 847236 1629345 3112587 5874795 10909747
5 -2 -10 -5 46 203 566 1294 2628 4921 8693 14759 24538 40772 69130 121701 224611 434984 879612 1844031 3975938
3 21 52 98 164 258 391 577 833 1179 1638 2236 3002 3968 5169 6643 8431 10577 13128 16134 19648
7 8 19 43 82 153 318 734 1746 4081 9271 20562 44795 96170 203655 425577 878602 1795615 3640864 7335774 14692157
21 30 39 48 57 66 75 84 93 102 111 120 129 138 147 156 165 174 183 192 201
-4 8 31 65 110 166 233 311 400 500 611 733 866 1010 1165 1331 1508 1696 1895 2105 2326
18 41 91 193 391 753 1374 2377 3912 6153 9293 13537 19093 26161 34920 45513 58030 72489 88815 106817 126163
-4 -13 -21 -20 7 104 372 1011 2374 5033 9857 18102 31513 52438 83954 130005 195552 286735 411047 577520 796923
10 21 38 65 122 269 649 1560 3571 7704 15715 30537 57037 103464 184452 327378 585520 1064159 1969964 3700241 6997588
11 25 53 95 151 221 305 403 515 641 781 935 1103 1285 1481 1691 1915 2153 2405 2671 2951
19 27 37 67 155 366 799 1594 2939 5077 8313 13021 19651 28736 40899 56860 77443 103583 136333 176871 226507
9 15 21 27 33 39 45 51 57 63 69 75 81 87 93 99 105 111 117 123 129
3 2 4 8 26 103 342 932 2177 4524 8588 15172 25280 40121 61102 89808 127967 177398 239940 317360 411238
0 7 22 49 97 192 400 861 1834 3753 7294 13453 23635 39754 64344 100681 152916 226219 326934 462745 642853
11 5 1 12 65 214 560 1278 2651 5111 9287 16060 26625 42560 65902 99230 145755 209417 294989 408188 555793
-3 -7 -1 22 71 172 404 980 2426 5953 14170 32348 70514 146728 291973 557166 1022875 1812401 3108953 5177706 8393585
4 9 33 104 270 605 1221 2293 4106 7135 12171 20508 34208 56463 92075 148077 234520 365453 560125 844440 1252698
3 13 32 65 140 331 798 1866 4176 8959 18520 37081 72229 137365 255798 467604 841455 1496343 2644958 4686847 8416272
-4 9 37 80 138 211 299 402 520 653 801 964 1142 1335 1543 1766 2004 2257 2525 2808 3106
5 0 -5 -5 5 30 75 145 245 380 555 775 1045 1370 1755 2205 2725 3320 3995 4755 5605
25 43 78 151 294 549 981 1731 3161 6185 12948 28136 61426 132001 276787 565292 1125873 2191223 4175226 7799525 14296726
9 23 54 104 171 247 318 383 521 1055 2904 8310 22339 55989 132571 300568 658990 1406445 2934993 6008892 12105512
7 15 24 30 43 106 335 996 2636 6286 13755 28035 53838 98287 171784 289079 470565 743825 1145458 1723212 2538453
0 -1 10 60 204 537 1214 2494 4829 9024 16499 29689 52623 91728 156909 262961 431374 692597 1088832 1677434 2534998
17 40 84 169 335 649 1215 2194 3851 6665 11565 20397 36818 68040 128383 246740 482281 956726 1918286 3863249 7757949
24 34 37 44 77 177 417 926 1945 3956 7950 15941 31926 63720 126631 251103 498806 996122 2002039 4041362 8157171
10 7 20 65 159 334 677 1412 3045 6604 14025 28763 56755 107970 199046 358139 634506 1118355 1982836 3573131 6593957
-5 -9 -13 -17 -21 -25 -29 -33 -37 -41 -45 -49 -53 -57 -61 -65 -69 -73 -77 -81 -85
3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43
5 9 28 84 209 461 953 1906 3755 7374 14556 29001 58243 117200 234373 462165 893353 1686439 3103444 5564706 9726413
-3 0 6 27 91 255 623 1366 2741 5106 8928 14781 23331 35305 51441 72416 98749 130676 167994 209871 254619
19 35 54 75 105 168 319 665 1404 2927 6101 12983 28438 63494 141816 311463 665149 1373687 2739636 5282855 9880339
9 21 42 94 206 409 729 1184 1806 2730 4424 8196 17247 38823 88604 199621 440159 948983 2002842 4141990 8396292
2 10 25 52 109 229 473 974 2037 4330 9220 19343 39571 78721 152826 292003 555888 1069234 2103267 4256230 8838981
7 13 27 53 113 265 622 1380 2878 5733 11118 21281 40438 76213 141843 259416 464465 812301 1386533 2310293 3760759
2 4 18 66 183 417 835 1536 2679 4547 7696 13317 24160 46931 98382 220159 513320 1214890 2860322 6614548 14921901
20 42 89 187 375 705 1247 2114 3529 5965 10401 18760 34661 64809 121837 230509 441382 860016 1706553 3431097 6926055
-6 5 41 118 257 497 927 1758 3479 7170 15084 31669 65309 131290 256992 491376 923096 1716263 3182439 5926360 11139249
15 28 50 104 234 511 1047 2038 3883 7461 14703 29703 60831 124753 254153 512771 1025137 2036155 4031423 7980034 15819960
10 6 9 29 78 167 305 517 915 1884 4505 11474 29080 71443 169472 389344 869428 1891498 4013213 8306107 16769254
10 9 13 26 47 67 72 60 80 301 1119 3310 8237 18119 36370 68016 120198 202769 328993 516354 787483
11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51
22 49 104 198 350 603 1059 1958 3838 7824 16114 32786 65193 126523 240683 451628 840658 1556967 2868476 5240830 9450668
16 39 79 153 287 511 853 1343 2046 3153 5181 9391 18683 39591 86823 193521 433828 970699 2153123 4705917 10086151
5 16 35 58 78 83 57 -1 -19 264 1480 4880 12692 28852 61020 126369 267104 588917 1350257 3159230 7390503
18 28 39 54 85 169 397 952 2164 4623 9465 19094 38871 80748 170523 361426 758214 1557966 3116451 6052430 11406697
3 5 19 48 91 146 221 356 666 1430 3272 7505 16736 35857 73572 144631 272957 495859 869521 1475942 2431473
30 41 45 51 93 250 668 1574 3282 6229 11158 19698 35791 68696 138673 286929 592006 1195521 2341043 4430925 8107113
11 22 53 115 230 453 910 1857 3765 7436 14155 25883 45496 77075 126252 200617 310191 467970 690545 998803 1418714
5 15 35 70 138 276 563 1187 2595 5777 12747 27296 56104 110310 207651 375293 653489 1100211 1796915 2855610 4427414
13 15 18 28 59 132 275 532 1003 1974 4268 10067 24633 59605 138881 308521 652641 1317921 2550134 4747030 8532991
19 31 39 37 30 50 187 653 1901 4825 11071 23493 46792 88380 159515 276757 463799 753731 1191799 1838725 2774658
4 -4 -5 12 63 178 426 964 2108 4408 8686 15974 27291 43265 63797 88353 118140 162456 252973 471660 1000479
8 26 56 102 170 269 420 688 1275 2754 6596 16260 39305 91285 202677 430899 880826 1739482 3334372 6231134 11396188
11 23 35 47 59 71 83 95 107 119 131 143 155 167 179 191 203 215 227 239 251
17 23 29 48 111 275 640 1382 2809 5447 10163 18332 32055 54435 89918 144706 227249 348823 524201 772424 1117679
5 12 24 46 90 177 332 567 849 1058 963 297 -884 -1191 4419 29378 104397 293136 718466 1604688 3343062
10 24 38 53 80 146 294 583 1116 2156 4430 9770 22312 50621 111465 236805 487438 980612 1946642 3844527 7595464
4 -1 2 29 103 254 519 942 1574 2473 3704 5339 7457 10144 13493 17604 22584 28547 35614 43913 53579
5 3 8 25 54 90 123 138 115 29 -150 -457 -932 -1620 -2571 -3840 -5487 -7577 -10180 -13371 -17230
19 30 46 85 184 416 929 2025 4306 8935 18119 36059 70900 138785 272218 537010 1065858 2123285 4228117 8378734 16457241
4 12 21 29 29 14 -11 -8 139 735 2539 7342 19120 46167 104805 225519 462686 909470 1719953 3141179 5558519
12 17 33 83 215 524 1191 2554 5245 10458 20461 39545 75752 144023 272029 511254 958606 1799275 3392061 6437763 12305329
10 26 62 133 273 562 1163 2376 4720 9059 16803 30264 53379 93309 164006 293873 541334 1024736 1976820 3839359 7420837
26 38 50 62 74 86 98 110 122 134 146 158 170 182 194 206 218 230 242 254 266
17 33 59 102 172 282 448 689 1027 1487 2097 2888 3894 5152 6702 8587 10853 13549 16727 20442 24752
14 31 60 120 251 526 1063 2037 3692 6353 10438 16470 25089 37064 53305 74875 103002 139091 184736 241732 312087
23 39 58 80 105 133 164 198 235 275 318 364 413 465 520 578 639 703 770 840 913
21 45 93 181 329 569 959 1612 2762 4916 9199 18122 37251 78725 168410 359900 760925 1581649 3221326 6423446 12558361
-5 -6 8 60 185 441 929 1831 3495 6640 12841 25616 52734 110904 234974 495463 1031149 2108352 4226908 8307194 16017545
13 24 53 117 244 473 854 1448 2327 3574 5283 7559 10518 14287 19004 24818 31889 40388 50497 62409 76328
23 40 64 104 189 396 894 2017 4403 9279 19055 38564 77656 156620 317410 646440 1319635 2688726 5441230 10887612 21461091
15 35 59 84 104 107 73 -29 -252 -702 -1606 -3439 -7137 -14428 -28318 -53774 -98651 -174915 -300219 -499894 -809422
0 7 22 50 96 165 262 392 560 771 1030 1342 1712 2145 2646 3220 3872 4607 5430 6346 7360
2 12 37 84 178 378 809 1720 3572 7147 13653 24792 42771 70275 110468 167082 244466 346870 474873 614196 707420
19 35 73 159 337 676 1293 2416 4518 8558 16368 31226 58654 107477 191174 329545 550709 893437 1409811 2168185 3256407
9 10 18 54 150 354 744 1462 2789 5290 10064 19142 36094 66946 121586 215974 375689 641674 1079510 1794198 2953294
-8 -9 1 44 170 476 1137 2452 4909 9283 16817 29640 51840 92218 171054 335896 696763 1501852 3296020 7246003 15797579
27 37 57 108 228 494 1063 2249 4674 9561 19276 38271 74625 142426 265316 481736 852989 1476613 2510427 4218046 7056162
0 4 9 15 22 30 39 49 60 72 85 99 114 130 147 165 184 204 225 247 270
24 41 71 123 206 329 501 731 1028 1401 1859 2411 3066 3833 4721 5739 6896 8201 9663 11291 13094
16 28 54 121 284 652 1429 2986 6003 11753 22654 43318 82532 157006 298461 566931 1075374 2034406 3832134 7174207 13325792
9 2 -1 22 122 403 1062 2465 5288 10752 20979 39509 72072 127838 221613 377857 638023 1073610 1808547 3056140 5177882
8 6 -4 -16 -3 97 412 1212 3075 7218 16131 34785 72949 149641 301604 599185 1175500 2278885 4365104 8255185 15396599
-1 0 -2 -4 0 18 58 136 333 985 3169 9798 27930 73457 180383 418770 928688 1983079 4101909 8255993 16225829
10 7 18 60 154 341 715 1481 3050 6188 12243 23483 43588 78348 136624 231626 382546 616549 971064 1496222 2257150
-2 2 23 87 236 541 1124 2188 4054 7204 12329 20381 32628 50711 76702 113162 163198 230518 319483 435155 583340
-4 -5 -9 -13 -5 34 136 384 1018 2657 6697 15957 35657 74824 148234 279010 502008 868135 1449755 2347351 3697623
16 14 9 16 60 175 409 841 1620 3040 5669 10554 19528 35649 63805 111523 190024 315570 511153 808580 1251012
-10 -17 -26 -37 -50 -65 -82 -101 -122 -145 -170 -197 -226 -257 -290 -325 -362 -401 -442 -485 -530
-2 -3 2 27 101 292 744 1727 3700 7387 13866 24671 41907 68378 107728 164595 244778 355417 505186 704499 965729
14 19 26 35 46 59 74 91 110 131 154 179 206 235 266 299 334 371 410 451 494
7 12 28 64 131 242 412 658 999 1456 2052 2812 3763 4934 6356 8062 10087 12468 15244 18456 22147
14 28 39 55 110 281 718 1708 3804 8057 16389 32139 60822 111236 197437 343264 594082 1047282 1927607 3762071 7762782
5 25 56 98 154 234 364 613 1160 2436 5396 12008 26111 54967 112318 225021 448287 900835 1843624 3848550 8143064
10 35 77 139 224 335 475 647 854 1099 1385 1715 2092 2519 2999 3535 4130 4787 5509 6299 7160
7 14 17 19 45 153 454 1150 2598 5424 10768 20884 40634 81060 167480 356960 774538 1685999 3640496 7744350 16177032
0 2 19 63 160 370 813 1711 3477 6920 13712 27414 55642 114484 237295 492021 1015343 2080463 4232825 8563395 17259507
12 41 89 163 277 462 780 1342 2329 4016 6810 11357 18909 32508 60437 125397 287091 694318 1698939 4095063 9606004
21 27 27 26 46 130 358 886 2028 4432 9463 20008 42069 87719 180272 362870 712127 1359001 2519699 4540166 7958576
16 12 8 10 25 61 127 233 390 610 906 1292 1783 2395 3145 4051 5132 6408 7900 9630 11621
4 20 49 89 144 249 517 1225 2979 7045 16029 35280 75762 159850 332827 685291 1396165 2814424 5613910 11087815 21714227
6 22 55 114 213 377 658 1168 2136 3996 7513 13954 25311 44583 76124 126064 202810 317634 485355 725122 1061305
1 3 7 17 57 186 511 1189 2411 4377 7310 11626 18478 31019 56865 112353 229233 464339 912461 1721971 3111595
27 41 63 115 229 447 829 1486 2678 5049 10112 21147 44734 93211 188424 367222 689245 1247657 2183589 3705179 6112227
22 38 68 121 204 333 552 971 1841 3684 7487 14956 28841 53475 96109 170733 308506 583836 1174568 2492081 5448060
1 14 38 81 162 330 694 1461 2976 5757 10528 18293 30599 50369 84163 147660 277931 559352 1175870 2512485 5345816
2 6 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 78 82
10 23 57 123 244 483 982 2019 4099 8102 15522 28868 52407 93688 166813 299382 546656 1019041 1932855 3699937 7079518

110
day9/task.txt Normal file
View File

@@ -0,0 +1,110 @@
--- Day 9: Mirage Maintenance ---
You ride the camel through the sandstorm and stop where the ghost's maps told you to stop. The sandstorm subsequently subsides, somehow seeing you standing at an oasis!
The camel goes to get some water and you stretch your neck. As you look up, you discover what must be yet another giant floating island, this one made of metal! That must be where the parts to fix the sand machines come from.
There's even a hang glider partially buried in the sand here; once the sun rises and heats up the sand, you might be able to use the glider and the hot air to get all the way up to the metal island!
While you wait for the sun to rise, you admire the oasis hidden here in the middle of Desert Island. It must have a delicate ecosystem; you might as well take some ecological readings while you wait. Maybe you can report any environmental instabilities you find to someone so the oasis can be around for the next sandstorm-worn traveler.
You pull out your handy Oasis And Sand Instability Sensor and analyze your surroundings. The OASIS produces a report of many values and how they are changing over time (your puzzle input). Each line in the report contains the history of a single value. For example:
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
To best protect the oasis, your environmental report should include a prediction of the next value in each history. To do this, start by making a new sequence from the difference at each step of your history. If that sequence is not all zeroes, repeat this process, using the sequence you just generated as the input sequence. Once all of the values in your latest sequence are zeroes, you can extrapolate what the next value of the original history should be.
In the above dataset, the first history is 0 3 6 9 12 15. Because the values increase by 3 each step, the first sequence of differences that you generate will be 3 3 3 3 3. Note that this sequence has one fewer value than the input sequence because at each step it considers two numbers from the input. Since these values aren't all zero, repeat the process: the values differ by 0 at each step, so the next sequence is 0 0 0 0. This means you have enough information to extrapolate the history! Visually, these sequences can be arranged like this:
0 3 6 9 12 15
3 3 3 3 3
0 0 0 0
To extrapolate, start by adding a new zero to the end of your list of zeroes; because the zeroes represent differences between the two values above them, this also means there is now a placeholder in every sequence above it:
0 3 6 9 12 15 B
3 3 3 3 3 A
0 0 0 0 0
You can then start filling in placeholders from the bottom up. A needs to be the result of increasing 3 (the value to its left) by 0 (the value below it); this means A must be 3:
0 3 6 9 12 15 B
3 3 3 3 3 3
0 0 0 0 0
Finally, you can fill in B, which needs to be the result of increasing 15 (the value to its left) by 3 (the value below it), or 18:
0 3 6 9 12 15 18
3 3 3 3 3 3
0 0 0 0 0
So, the next value of the first history is 18.
Finding all-zero differences for the second history requires an additional sequence:
1 3 6 10 15 21
2 3 4 5 6
1 1 1 1
0 0 0
Then, following the same process as before, work out the next value in each sequence from the bottom up:
1 3 6 10 15 21 28
2 3 4 5 6 7
1 1 1 1 1
0 0 0 0
So, the next value of the second history is 28.
The third history requires even more sequences, but its next value can be found the same way:
10 13 16 21 30 45 68
3 3 5 9 15 23
0 2 4 6 8
2 2 2 2
0 0 0
So, the next value of the third history is 68.
If you find the next value for each history in this example and add them together, you get 114.
Analyze your OASIS report and extrapolate the next value for each history. What is the sum of these extrapolated values?
Your puzzle answer was 1884768153.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
Of course, it would be nice to have even more history included in your report. Surely it's safe to just extrapolate backwards as well, right?
For each history, repeat the process of finding differences until the sequence of differences is entirely zero. Then, rather than adding a zero to the end and filling in the next values of each previous sequence, you should instead add a zero to the beginning of your sequence of zeroes, then fill in new first values for each previous sequence.
In particular, here is what the third example history looks like when extrapolating back in time:
5 10 13 16 21 30 45
5 3 3 5 9 15
-2 0 2 4 6
2 2 2 2
0 0 0
Adding the new values on the left side of each sequence from bottom to top eventually reveals the new left-most history value: 5.
Doing this for the remaining example data above results in previous values of -3 for the first history and 0 for the second history. Adding all three new values together produces 2.
Analyze your OASIS report again, this time extrapolating the previous value for each history. What is the sum of these extrapolated values?
--- Part Two ---
Of course, it would be nice to have even more history included in your report. Surely it's safe to just extrapolate backwards as well, right?
For each history, repeat the process of finding differences until the sequence of differences is entirely zero. Then, rather than adding a zero to the end and filling in the next values of each previous sequence, you should instead add a zero to the beginning of your sequence of zeroes, then fill in new first values for each previous sequence.
In particular, here is what the third example history looks like when extrapolating back in time:
5 10 13 16 21 30 45
5 3 3 5 9 15
-2 0 2 4 6
2 2 2 2
0 0 0
Adding the new values on the left side of each sequence from bottom to top eventually reveals the new left-most history value: 5.
Doing this for the remaining example data above results in previous values of -3 for the first history and 0 for the second history. Adding all three new values together produces 2.
Analyze your OASIS report again, this time extrapolating the previous value for each history. What is the sum of these extrapolated values?
Your puzzle answer was 1031.
Both parts of this puzzle are complete! They provide two gold stars: **

3
day9/test_input.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