Compare commits

...

31 commits

Author SHA1 Message Date
Bruno BELANYI 5b084a755b 2024: d19: ex2: add solution 2024-12-19 00:11:14 -05:00
Bruno BELANYI a363dd9172 2024: d19: ex2: add input 2024-12-19 00:11:08 -05:00
Bruno BELANYI aff6966078 2024: d19: ex1: add solution 2024-12-19 00:11:03 -05:00
Bruno BELANYI 37470beec0 2024: d19: ex1: add input 2024-12-19 00:10:57 -05:00
Bruno BELANYI a83c7cb441 2024: d18: ex2: add solution 2024-12-18 00:25:04 -05:00
Bruno BELANYI b69cbd0e62 2024: d18: ex2: add input 2024-12-18 00:24:53 -05:00
Bruno BELANYI 6dc74c4dcb 2024: d18: ex1: add solution 2024-12-18 00:24:47 -05:00
Bruno BELANYI ed1cccab46 2024: d18: ex1: add input 2024-12-18 00:24:40 -05:00
Bruno BELANYI 5a6658764d 2024: d17: ex2: add solution 2024-12-17 13:11:08 -05:00
Bruno BELANYI c1c1429deb 2024: d17: ex2: add input 2024-12-17 13:10:57 -05:00
Bruno BELANYI 8c1cdd2b7d 2024: d17: ex1: add solution 2024-12-17 13:10:51 -05:00
Bruno BELANYI 5154037cf9 2024: d17: ex1: add input 2024-12-17 13:10:44 -05:00
Bruno BELANYI 1468ef5a9b 2024: d16: ex2: add solution 2024-12-16 14:54:20 -05:00
Bruno BELANYI 93bbb5bae6 2024: d16: ex2: add input 2024-12-16 14:54:15 -05:00
Bruno BELANYI 32a92bd813 2024: d16: ex1: add solution 2024-12-16 14:54:09 -05:00
Bruno BELANYI f2751ddee8 2024: d16: ex1: add input 2024-12-16 14:54:04 -05:00
Bruno BELANYI f761721daf 2024: d15: ex2: add solution 2024-12-15 11:01:06 -05:00
Bruno BELANYI bfdbdf6499 2024: d15: ex2: add input 2024-12-15 11:01:01 -05:00
Bruno BELANYI d0dd6a1bbb 2024: d15: ex1: add solution 2024-12-15 11:00:54 -05:00
Bruno BELANYI 7bd3033950 2024: d15: ex1: add input 2024-12-15 11:00:49 -05:00
Bruno BELANYI 135980fd92 2024: d14: ex2: add solution 2024-12-14 11:22:58 -05:00
Bruno BELANYI f6119c763e 2024: d14: ex2: add input 2024-12-14 11:22:54 -05:00
Bruno BELANYI dbff9dc49b 2024: d14: ex1: add solution 2024-12-14 11:22:46 -05:00
Bruno BELANYI bf7e3eb6dc 2024: d14: ex1: add input 2024-12-14 11:22:39 -05:00
Bruno BELANYI 8eb066cd31 2024: d13: ex2: add solution 2024-12-13 01:51:43 -05:00
Bruno BELANYI 086b0738f9 2024: d13: ex2: add input 2024-12-13 01:51:38 -05:00
Bruno BELANYI 8cbe50560c 2024: d13: ex1: add solution 2024-12-13 01:51:32 -05:00
Bruno BELANYI fc6314d77a 2024: d13: ex1: add input 2024-12-13 01:51:28 -05:00
Bruno BELANYI 1a77489993 2024: d12: ex2: add solution 2024-12-12 10:01:22 -05:00
Bruno BELANYI a90594264e 2024: d12: ex2: add input 2024-12-12 10:01:03 -05:00
Bruno BELANYI 176c75fe29 2024: d12: ex1: add solution 2024-12-12 10:00:57 -05:00
31 changed files with 13250 additions and 0 deletions

67
2024/d12/ex1/ex1.py Executable file
View file

@ -0,0 +1,67 @@
#!/usr/bin/env python
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[Point, str]:
return {
Point(x, y): c for x, line in enumerate(input) for y, c in enumerate(line)
}
def find_plots(garden: dict[Point, str]) -> list[set[Point]]:
res: list[set[Point]] = []
visited: set[Point] = set()
for p, plant in garden.items():
if p in visited:
continue
plot: set[Point] = set()
to_visit = {p}
while to_visit:
p = to_visit.pop()
visited.add(p)
plot.add(p)
assert garden[p] == plant # Sanity check
for n in p.neighbours():
if garden.get(n) != plant:
continue
if n in visited:
continue
to_visit.add(n)
res.append(plot)
return res
def fence_price(plot: set[Point]) -> int:
area = len(plot)
perimeter = sum(n not in plot for p in plot for n in p.neighbours())
return area * perimeter
garden = parse(input.splitlines())
plots = find_plots(garden)
return sum(map(fence_price, plots))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

90
2024/d12/ex2/ex2.py Executable file
View file

@ -0,0 +1,90 @@
#!/usr/bin/env python
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[Point, str]:
return {
Point(x, y): c for x, line in enumerate(input) for y, c in enumerate(line)
}
def find_plots(garden: dict[Point, str]) -> list[set[Point]]:
res: list[set[Point]] = []
visited: set[Point] = set()
for p, plant in garden.items():
if p in visited:
continue
plot: set[Point] = set()
to_visit = {p}
while to_visit:
p = to_visit.pop()
visited.add(p)
plot.add(p)
assert garden[p] == plant # Sanity check
for n in p.neighbours():
if garden.get(n) != plant:
continue
if n in visited:
continue
to_visit.add(n)
res.append(plot)
return res
def count_corners(plot: set[Point]) -> int:
def corners(p: Point) -> int:
res = 0
for dx, dy in (
(-1, -1),
(1, 1),
(-1, 1),
(1, -1),
):
diag = Point(p.x + dx, p.y + dy)
vert = Point(p.x + dx, p.y)
hori = Point(p.x, p.y + dy)
# Both sides are out: an outside corner
if vert not in plot and hori not in plot:
res += 1
# Both sides are in, diagonal is out: an inside corner
if vert in plot and hori in plot and diag not in plot:
res += 1
return res
return sum(corners(p) for p in plot)
def fence_price(plot: set[Point]) -> int:
area = len(plot)
# Number of sides is equal to number of corners
sides = count_corners(plot)
return area * sides
garden = parse(input.splitlines())
plots = find_plots(garden)
return sum(map(fence_price, plots))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

140
2024/d12/ex2/input Normal file
View file

@ -0,0 +1,140 @@
TTTTTTTTTTTTTTDDDDDDDD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TLLLLLLLLLLLLLLLLLLLLGSSSGTGSSYYYYYYYYYRRRRRRRRRRRRRPRRIIIIIIIIIIIAAAAAAAAAAEHEEQQQQQQQQQQQQQQFFFFIIIIIIIIYYGGGVVVVVVVYYYWYYYQQQQQQQQ

79
2024/d13/ex1/ex1.py Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env python
import dataclasses
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class ClawMachine:
a_delta: Point
b_delta: Point
prize: Point
def solve(input: str) -> int:
def parse_button(input: str) -> Point:
deltas = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("+")[1]), deltas.split(", "))
return Point(x, y)
def parse_prize(input: str) -> Point:
coords = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("=")[1]), coords.split(", "))
return Point(x, y)
def parse_claw_machine(input: list[str]) -> ClawMachine:
assert len(input) == 3 # Sanity check
return ClawMachine(
parse_button(input[0]),
parse_button(input[1]),
parse_prize(input[2]),
)
def parse(input: str) -> list[ClawMachine]:
return [parse_claw_machine(group.splitlines()) for group in input.split("\n\n")]
def play_machine(machine: ClawMachine) -> int | None:
def found_prize(row: list[tuple[int, Point]]) -> int | None:
for tokens, p in row:
if p == machine.prize:
return tokens
return None
row = [
(3 * i, Point(machine.a_delta.x * i, machine.a_delta.y * i))
for i in range(101)
]
res = found_prize(row)
for _ in range(100):
row = [
(tokens + 1, Point(p.x + machine.b_delta.x, p.y + machine.b_delta.y))
for tokens, p in row
]
tmp = found_prize(row)
if tmp is None:
continue
if res is None:
res = tmp
res = min(res, tmp)
return res
claw_machines = parse(input)
return sum(
tokens for tokens in map(play_machine, claw_machines) if tokens is not None
)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1279
2024/d13/ex1/input Normal file

File diff suppressed because it is too large Load diff

69
2024/d13/ex2/ex2.py Executable file
View file

@ -0,0 +1,69 @@
#!/usr/bin/env python
import dataclasses
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class ClawMachine:
a_delta: Point
b_delta: Point
prize: Point
def solve(input: str) -> int:
def parse_button(input: str) -> Point:
deltas = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("+")[1]), deltas.split(", "))
return Point(x, y)
def parse_prize(input: str) -> Point:
coords = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("=")[1]), coords.split(", "))
return Point(10000000000000 + x, 10000000000000 + y)
def parse_claw_machine(input: list[str]) -> ClawMachine:
assert len(input) == 3 # Sanity check
return ClawMachine(
parse_button(input[0]),
parse_button(input[1]),
parse_prize(input[2]),
)
def parse(input: str) -> list[ClawMachine]:
return [parse_claw_machine(group.splitlines()) for group in input.split("\n\n")]
def play_machine(machine: ClawMachine) -> int | None:
a_dx, a_dy = machine.a_delta
b_dx, b_dy = machine.b_delta
px, py = machine.prize
a = (px * b_dy - py * b_dx) // (b_dy * a_dx - b_dx * a_dy)
b = (px * a_dy - py * a_dx) // (a_dy * b_dx - a_dx * b_dy)
if a * a_dx + b * b_dx != px:
return None
if a * a_dy + b * b_dy != py:
return None
return 3 * a + b
claw_machines = parse(input)
return sum(
tokens for tokens in map(play_machine, claw_machines) if tokens is not None
)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1279
2024/d13/ex2/input Normal file

File diff suppressed because it is too large Load diff

61
2024/d14/ex1/ex1.py Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env python
import dataclasses
import functools
import operator
import sys
from collections import Counter
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class Robot:
pos: Point
vel: Point
def step(self, dims: Point, delta: int = 1) -> "Robot":
x, y = self.pos.x + self.vel.x * delta, self.pos.y + self.vel.y * delta
return Robot(
Point(x % dims.x, y % dims.y),
self.vel,
)
def solve(input: str) -> int:
def parse_robot(input: str) -> Robot:
pos, vel = map(lambda s: s.split("=")[1], input.split(" "))
return Robot(
Point(*map(int, pos.split(","))),
Point(*map(int, vel.split(","))),
)
def parse(input: list[str]) -> list[Robot]:
return [parse_robot(line) for line in input]
def compute_safety(robots: list[Robot], dims: Point) -> int:
mid_x, mid_y = dims.x // 2, dims.y // 2
counts: Counter[tuple[bool, bool]] = Counter()
for x, y in map(lambda robot: robot.pos, robots):
if x == mid_x or y == mid_y:
continue
counts[(x < mid_x, y < mid_y)] += 1
return functools.reduce(operator.mul, counts.values())
robots = parse(input.splitlines())
dims = Point(101, 103)
robots = [robot.step(dims, 100) for robot in robots]
return compute_safety(robots, dims)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

500
2024/d14/ex1/input Normal file
View file

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

80
2024/d14/ex2/ex2.py Executable file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env python
import dataclasses
import functools
import itertools
import sys
from typing import Literal, NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class Robot:
pos: Point
vel: Point
def step(self, dims: Point, delta: int = 1) -> "Robot":
x, y = self.pos.x + self.vel.x * delta, self.pos.y + self.vel.y * delta
return Robot(
Point(x % dims.x, y % dims.y),
self.vel,
)
def solve(input: str) -> int:
def parse_robot(input: str) -> Robot:
pos, vel = map(lambda s: s.split("=")[1], input.split(" "))
return Robot(
Point(*map(int, pos.split(","))),
Point(*map(int, vel.split(","))),
)
def parse(input: list[str]) -> list[Robot]:
return [parse_robot(line) for line in input]
def find_tree(robots: list[Robot], dims: Point) -> int:
def compute_positions(step: int) -> list[Point]:
return [robot.step(dims, step).pos for robot in robots]
def compute_variance(values: list[int]) -> float:
avg = sum(values) / len(values)
variance = sum((n - avg) ** 2 for n in values) / len(values)
return variance
def cluster_variance(step: int, dimension: Literal["x", "y"]) -> float:
return compute_variance(
[getattr(p, dimension) for p in compute_positions(step)]
)
# The tree should have robots clustered together in X and Y
cluster_x = min(
range(dims.x),
key=functools.partial(cluster_variance, dimension="x"),
)
cluster_y = min(
range(dims.y),
key=functools.partial(cluster_variance, dimension="y"),
)
# And those clusers should repeat modulo each dimension
for i in itertools.count(cluster_x, step=dims.x):
if i % dims.y == cluster_y:
return i
assert False # Sanity check
robots = parse(input.splitlines())
dims = Point(101, 103)
return find_tree(robots, dims)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

500
2024/d14/ex2/input Normal file
View file

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

103
2024/d15/ex1/ex1.py Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/env python
import copy
import enum
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class Direction(enum.StrEnum):
UP = "^"
RIGHT = ">"
DOWN = "v"
LEFT = "<"
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.UP:
dx, dy = -1, 0
case Direction.RIGHT:
dx, dy = 0, 1
case Direction.DOWN:
dx, dy = 1, 0
case Direction.LEFT:
dx, dy = 0, -1
return Point(p.x + dx, p.y + dy)
class Object(enum.StrEnum):
BOX = "O"
WALL = "#"
Maze = dict[Point, Object]
def solve(input: str) -> int:
def parse_maze(input: list[str]) -> tuple[Point, Maze]:
robot: Point | None = None
maze: Maze = {}
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
if c == "@":
robot = Point(x, y)
continue
maze[Point(x, y)] = Object(c)
assert robot is not None # Sanity check
return robot, maze
def parse_directions(input: str) -> list[Direction]:
return [Direction(c) for c in input if c in Direction]
def parse(input: str) -> tuple[Point, Maze, list[Direction]]:
maze_input, directions_input = input.split("\n\n")
robot, maze = parse_maze(maze_input.splitlines())
directions = parse_directions(directions_input)
return robot, maze, directions
def step(robot: Point, maze: Maze, d: Direction) -> tuple[Point, Maze]:
# Maze a tentative step
new_robot = d.step(robot)
new_maze = copy.copy(maze)
# Try to move boxes along
if (blocker := new_robot) in new_maze:
# Try to move boxes up
while blocker in new_maze:
# We hit a wall, abort the movement
if new_maze[blocker] == Object.WALL:
return robot, maze
# Otherwise look at the next space along
blocker = d.step(blocker)
# Out of the loop, we must have found an empty space, so do the push
new_maze[blocker] = new_maze.pop(new_robot)
# Robot moved without hitting a wall
return new_robot, new_maze
def compute_coordinates(maze: Maze) -> int:
return sum(100 * p.x + p.y for p, obj in maze.items() if obj == Object.BOX)
robot, maze, directions = parse(input)
for d in directions:
robot, maze = step(robot, maze, d)
return compute_coordinates(maze)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

71
2024/d15/ex1/input Normal file
View file

@ -0,0 +1,71 @@
##################################################
#......O.O..O......O......O..OO...O..O.O.O..O..O.#
#....O.O..#.O....O#.#.#......O.O#O.O#O#..O.O.....#
#.........O..#O......O...OO..O..O..O#....O.......#
#.O.O......O#.#..#.#.........O...OOO.O..O..O....O#
#..O......O.......O..O.#O......OO.O.O#..O.OO..O..#
#O.O.....O.O......O....O..OO...#.#...O##OO#O.....#
#O..O....OOOO...#.O.O.O#.....##.....O#.##..O.....#
#O..O.O....O.#..O.O.OO#O.#..#.O....O..O.#.....O..#
##..OOOO..O..#O.#.O....O...............OO.....O..#
#O.O#.........OO..O..#..O.....O..O...O#.....O....#
#..#O#O#...#....O...OOOO..O.....#O.......O.......#
#..........O...O.....#OOOO#O..#..O..#O.........O.#
##..O.OO.O......#...#OOO.OO..O.O.O.OO#.#OO..O.OO.#
#....O.O..OO.O.OOO..OO...O...O..O.O.O....O...O...#
#O..#OO.........O#......OOO....O.....O.OO.#.O.##.#
#.O.OOO.....O....O...#O.O.O.#.O.O..........O...OO#
#.OO.OO...O...O..#........O.O...O.O...#OO.O....O.#
#OO...O.OO.#O.....OOO.#O#.O.#......OO.....OO#..O.#
#..O......O.....#...#O.....O.....OOO.....O.#OO...#
#.....#O..O..#...OOO.#O.O..O.O#...#OO.O......O..##
#..OO.OOO#.O.....OO..#.OO......OO.O....O...O.....#
#.O.OO..............#..O.....O.O...OO.....#.O#...#
#......OO.....OOO.O..O#OO...OO..O#..O..O.OO......#
#.#O....O....O..#O..O..O@..#..#...#......O.......#
#.#..O.O.OO...O.O#....O..#..O...OOOOO...#.OOO#...#
##O..O.O....#O....OO#O.#O......O.....O..O...#O...#
#...O...........O.#O..O.#...#.O.O.O...........#.##
#O#O.......O..O.....OO.#O.O.#OOOO#.O.O.O.O.......#
##O.O..OO...#.O..#.O.O..OOO.O.O#.....O.O..#.O.O.O#
#..OO...O..#O.O.#.OOO.....OO........#..OO.#...O.##
#O.#.#..#.O.O...O..O.#O..O.O.OO......O.OO.O...O.##
#.O.OO...OO.........#....O.OO.OO..O#O.#O........##
#.......O.......OO#...#....#.OOO#.#........#.O...#
#...O.O.#.O.O.........OOO.O.O...O....O....#...O#.#
#....O.O.......#.......#..O##.O.O.....O...O.O...O#
#.O.O.O..O#.O.O...##O#O...O.....#OO#O.O....O..O..#
#O.O.O.#..O...O.O.......#.OO..#..........O...O.O.#
#...O...O.....O....##......#..OO....##.O..OO.....#
#..OO..O..O..OOO.....#O..OO.O.OOOO.#.O...O.#.....#
#...O...O.O.O...O.#O.#.O...O#.#......O..OO..O.##O#
#...O.O#......OO.#.O.....OO..O.......#...#.O...#.#
##OO..#O.....OO..............#...O#..O#......OOO.#
##OOOO..O.#..O.O....O....O..O#.O#....O....O.O....#
#.....#......O...OOO.O........O....#O.OO.....OO.O#
#O.#....OO#....OO.O....#O#........#.#.OO.#.O...OO#
#.O.....O.OO.....OO...#O..OOO.O...OO....O.O##O...#
##O..OO.OO..#..O.O.O.##O......O..#....OOO....OO..#
#O..O....O.........OO#.#......OO...##.O.......O..#
##################################################
>v><^>^v^v^^v><><>^><>>v<><<^<><>>v<^><^>><<<^v<>v>^<v>>><<<<^^<<^v>vv><>>v^<^>^^^^>v<<^<<>v<^^>v^v>>^v^v<<vv>^v^>v^v^^^>>vv<<><^^v<v^v<<<v^<v><<^>>^v<>vv^v<v<vv><<^^vvv<<^^v>^vv>v<v>>v>^v<^<^>^>><>><^>><>^>>v<vv<v^^<>^vv><v^<><>^vv^<<^>><<<>v^>^vv<v<^^^^^^<><v<<^vv^><>^<vv^<>v<>v<v<^<><<>^<v>v><<>^<<<^>vv<<^v^<<v>v<<v^v<v>v>v^<>^v<<v^><^>v^<>vv<v^^>>>>^v<v^><<vv^><v<>v^<^>^>v>>>>^^<<^<<<^^>>^><<v^>>^^^vv>^<<vvv<>v^<v^vv>vvv^<^>v>^<>>vv^^^><v>v<<vv<^<^vv>>>^v>>^>>^^^v<>^vv<<^<>vv>^<vv^>^<>v<^<<^>><>v><>vv<^v^>^v>>><<>^^<<<^><<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v^^<>><^<>v>^^><v<>^<>>vv^vv^^v^>vv^<v>v^>>vv>>v^><<<>>^<<^>vv>v>^<>>>^^<v^^>><v^v<v^><<v>^v<>>^vv<>v<vv>^^>>><^<^^>>>vvv><><vv<v>v^<^^<^><>>^<<><<>>v>v^^^><^>v<<>^^<<vv<>>>v>>v^v<<><<^v^^<<vvv^v^^<>v><<^v>>^v<>^^^^v>^>>^>>v^>^>>v>>><^><<^v><>><><v^<v<<>><^v<^>vv<v^<>v^<<^><<<^^>>v<^>>v>>v>>>^<v^v<v<<>v>^><<vv>vv><^>v>^v<v^v><^<^vv^<vv<^^v>^^v^v<v<>>>>>^v>>^>^>v<>^>^<v^<>>^^v>v<>^<><^^<v<v^><<^v>v><>v>^>^<>><>>^>v^<v>v<<<>^><^v<><v>^^^^v<><^^v^^<^v>^<<v^>^>><^v><><<^^^v>><^^<<^>^vv<<^<>>v<<>>><v>>>^<<v<<><v<^v<v^v<>>^>v<<v^<><<>v<^v^<vv>><vvv>v<^^<<^v<<^v><>^vv>v<><v^><v<^^<<<>v<<<^^v^><^^^^<^^v<<^<>v><>>v<vv<vv<v^v<<>><v^v>^v<><v<><v>v><>><^>^^^<v<<^^>>v<<<<v<<^v^vv>>v^>vv<><<<^^><v>^^>^^v<^>^^^v<^^>>>^<^<>v<vv<<^^><^^v^vv<v<v^<^v<<v><^^^<v<>v<^<<v><^><><>v^v>>>^vv^<<^v<<><<<><^^^>>^<^v^v<<>v<v<^<^v^<<^<^>^v^v>v><^^>^>>^<<><v^><<^<<<>v^><>><^<v^v>>^<^<^v^<<<^>^<>^^<>>^<^v^v>v^><v^<>v^>>vv>>>^<>vv<><>^>>^><>>v><^>>>^><^v<vv

149
2024/d15/ex2/ex2.py Executable file
View file

@ -0,0 +1,149 @@
#!/usr/bin/env python
import copy
import enum
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class Direction(enum.StrEnum):
UP = "^"
RIGHT = ">"
DOWN = "v"
LEFT = "<"
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.UP:
dx, dy = -1, 0
case Direction.RIGHT:
dx, dy = 0, 1
case Direction.DOWN:
dx, dy = 1, 0
case Direction.LEFT:
dx, dy = 0, -1
return Point(p.x + dx, p.y + dy)
class Object(enum.StrEnum):
BOX = "O"
WALL = "#"
# Maze always contains the left part of the object
Maze = dict[Point, Object]
# WideMaze maps left and right side of an object to its (left, right) tuple
WideMaze = dict[Point, tuple[Point, Point]]
def solve(input: str) -> int:
def parse_maze(input: list[str]) -> tuple[Point, Maze]:
robot: Point | None = None
maze: Maze = {}
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
if c == "@":
robot = Point(x, y * 2)
continue
maze[Point(x, y * 2)] = Object(c)
assert robot is not None # Sanity check
return robot, maze
def parse_directions(input: str) -> list[Direction]:
return [Direction(c) for c in input if c in Direction]
def parse(input: str) -> tuple[Point, Maze, list[Direction]]:
maze_input, directions_input = input.split("\n\n")
robot, maze = parse_maze(maze_input.splitlines())
directions = parse_directions(directions_input)
return robot, maze, directions
def step(robot: Point, maze: Maze, d: Direction) -> tuple[Point, Maze]:
def widen_maze() -> WideMaze:
res: WideMaze = {}
for p in maze.keys():
right_p = Point(p.x, p.y + 1)
res[p] = (p, right_p)
res[right_p] = (p, right_p)
return res
def boxes_along(wide_maze: WideMaze) -> set[Point] | None:
def helper(current: Point) -> set[Point] | None:
# Return empty set if we hit the air
if current not in wide_maze:
return set()
# Query both sides of the object
left, right = wide_maze[current]
# Return None if we hit a wall
if maze[left] == Object.WALL:
return None
assert right not in maze # Sanity check
# Try to move both sides of the box recursively
res_left: set[Point] = set()
res_right: set[Point] = set()
# Only check next_left if not moving right
if (next_left := d.step(left)) != right:
if (try_left := helper(next_left)) is None:
return None
res_left = try_left
# And only check next_right if not moving left
if (next_right := d.step(right)) != left:
if (try_right := helper(next_right)) is None:
return None
res_right = try_right
# Both sides succeeded, return the set of boxes to move
return {left} | res_left | res_right
return helper(d.step(robot))
def move_boxes(boxes: set[Point]) -> Maze:
new_maze = copy.copy(maze)
# Do the move in two steps to avoid overwriting any values during movement
for box in boxes:
new_maze.pop(box)
for box in boxes:
new_maze[d.step(box)] = maze[box]
return new_maze
new_robot = d.step(robot)
# If we hit a wall, abort the step
if maze.get(new_robot) == Object.WALL:
return robot, maze
# If a box hits a wall, abort the step
if (boxes := boxes_along(widen_maze())) is None:
return robot, maze
# Otherwise move everything along the direction
return new_robot, move_boxes(boxes)
def compute_coordinates(maze: Maze) -> int:
return sum(100 * p.x + p.y for p, obj in maze.items() if obj == Object.BOX)
robot, maze, directions = parse(input)
for d in directions:
robot, maze = step(robot, maze, d)
return compute_coordinates(maze)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

71
2024/d15/ex2/input Normal file
View file

@ -0,0 +1,71 @@
##################################################
#......O.O..O......O......O..OO...O..O.O.O..O..O.#
#....O.O..#.O....O#.#.#......O.O#O.O#O#..O.O.....#
#.........O..#O......O...OO..O..O..O#....O.......#
#.O.O......O#.#..#.#.........O...OOO.O..O..O....O#
#..O......O.......O..O.#O......OO.O.O#..O.OO..O..#
#O.O.....O.O......O....O..OO...#.#...O##OO#O.....#
#O..O....OOOO...#.O.O.O#.....##.....O#.##..O.....#
#O..O.O....O.#..O.O.OO#O.#..#.O....O..O.#.....O..#
##..OOOO..O..#O.#.O....O...............OO.....O..#
#O.O#.........OO..O..#..O.....O..O...O#.....O....#
#..#O#O#...#....O...OOOO..O.....#O.......O.......#
#..........O...O.....#OOOO#O..#..O..#O.........O.#
##..O.OO.O......#...#OOO.OO..O.O.O.OO#.#OO..O.OO.#
#....O.O..OO.O.OOO..OO...O...O..O.O.O....O...O...#
#O..#OO.........O#......OOO....O.....O.OO.#.O.##.#
#.O.OOO.....O....O...#O.O.O.#.O.O..........O...OO#
#.OO.OO...O...O..#........O.O...O.O...#OO.O....O.#
#OO...O.OO.#O.....OOO.#O#.O.#......OO.....OO#..O.#
#..O......O.....#...#O.....O.....OOO.....O.#OO...#
#.....#O..O..#...OOO.#O.O..O.O#...#OO.O......O..##
#..OO.OOO#.O.....OO..#.OO......OO.O....O...O.....#
#.O.OO..............#..O.....O.O...OO.....#.O#...#
#......OO.....OOO.O..O#OO...OO..O#..O..O.OO......#
#.#O....O....O..#O..O..O@..#..#...#......O.......#
#.#..O.O.OO...O.O#....O..#..O...OOOOO...#.OOO#...#
##O..O.O....#O....OO#O.#O......O.....O..O...#O...#
#...O...........O.#O..O.#...#.O.O.O...........#.##
#O#O.......O..O.....OO.#O.O.#OOOO#.O.O.O.O.......#
##O.O..OO...#.O..#.O.O..OOO.O.O#.....O.O..#.O.O.O#
#..OO...O..#O.O.#.OOO.....OO........#..OO.#...O.##
#O.#.#..#.O.O...O..O.#O..O.O.OO......O.OO.O...O.##
#.O.OO...OO.........#....O.OO.OO..O#O.#O........##
#.......O.......OO#...#....#.OOO#.#........#.O...#
#...O.O.#.O.O.........OOO.O.O...O....O....#...O#.#
#....O.O.......#.......#..O##.O.O.....O...O.O...O#
#.O.O.O..O#.O.O...##O#O...O.....#OO#O.O....O..O..#
#O.O.O.#..O...O.O.......#.OO..#..........O...O.O.#
#...O...O.....O....##......#..OO....##.O..OO.....#
#..OO..O..O..OOO.....#O..OO.O.OOOO.#.O...O.#.....#
#...O...O.O.O...O.#O.#.O...O#.#......O..OO..O.##O#
#...O.O#......OO.#.O.....OO..O.......#...#.O...#.#
##OO..#O.....OO..............#...O#..O#......OOO.#
##OOOO..O.#..O.O....O....O..O#.O#....O....O.O....#
#.....#......O...OOO.O........O....#O.OO.....OO.O#
#O.#....OO#....OO.O....#O#........#.#.OO.#.O...OO#
#.O.....O.OO.....OO...#O..OOO.O...OO....O.O##O...#
##O..OO.OO..#..O.O.O.##O......O..#....OOO....OO..#
#O..O....O.........OO#.#......OO...##.O.......O..#
##################################################
>v><^>^v^v^^v><><>^><>>v<><<^<><>>v<^><^>><<<^v<>v>^<v>>><<<<^^<<^v>vv><>>v^<^>^^^^>v<<^<<>v<^^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<^^>>v<<<<v<<^v^vv>>v^>vv<><<<^^><v>^^>^^v<^>^^^v<^^>>>^<^<>v<vv<<^^><^^v^vv<v<v^<^v<<v><^^^<v<>v<^<<v><^><><>v^v>>>^vv^<<^v<<><<<><^^^>>^<^v^v<<>v<v<^<^v^<<^<^>^v^v>v><^^>^>>^<<><v^><<^<<<>v^><>><^<v^v>>^<^<^v^<<<^>^<>^^<>>^<^v^v>v^><v^<>v^>>vv>>>^<>vv<><>^>>^><>>v><^>>>^><^v<vv

118
2024/d16/ex1/ex1.py Executable file
View file

@ -0,0 +1,118 @@
#!/usr/bin/env python
import enum
import heapq
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class ParsedMaze(NamedTuple):
start: Point
end: Point
blocks: set[Point]
class Direction(enum.IntEnum):
EAST = enum.auto()
WEST = enum.auto()
NORTH = enum.auto()
SOUTH = enum.auto()
def rotations(self) -> tuple["Direction", "Direction"]:
match self:
case Direction.EAST | Direction.WEST:
return (Direction.NORTH, Direction.SOUTH)
case Direction.NORTH | Direction.SOUTH:
return (Direction.EAST, Direction.WEST)
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.EAST:
dx, dy = 0, 1
case Direction.WEST:
dx, dy = 0, -1
case Direction.NORTH:
dx, dy = -1, 0
case Direction.SOUTH:
dx, dy = 1, 0
return Point(p.x + dx, p.y + dy)
Node = tuple[Point, Direction]
def solve(input: str) -> int:
def parse(input: list[str]) -> ParsedMaze:
start: Point | None = None
end: Point | None = None
blocks: set[Point] = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
p = Point(x, y)
if c == "S":
start = p
elif c == "E":
end = p
elif c == "#":
blocks.add(p)
else:
assert False # Sanity check
assert start is not None # Sanity check
assert end is not None # Sanity check
return ParsedMaze(start, end, blocks)
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int:
def next_moves(
pos: Point,
dir: Direction,
) -> Iterator[tuple[int, Point, Direction]]:
transitions = [(1, dir.step(pos), dir)]
for new_dir in dir.rotations():
transitions.append((1000, pos, new_dir))
for cost, pos, dir in transitions:
if pos in blocks:
continue
yield cost, pos, dir
# Priority queue of (distance, point, direction)
queue = [(0, start, Direction.EAST)]
seen: set[Node] = set()
while len(queue) > 0:
cost, p, dir = heapq.heappop(queue)
if p == end:
return cost
# We must have seen (p, dir) with a smaller distance before
if (p, dir) in seen:
continue
# First time encountering (p, dir), must be the smallest distance to it
seen.add((p, dir))
# Add all neighbours to be visited
for n_cost, n, n_dir in next_moves(p, dir):
heapq.heappush(queue, (cost + n_cost, n, n_dir))
assert False # Sanity check
start, end, blocks = parse(input.splitlines())
return djikstra(start, end, blocks)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

141
2024/d16/ex1/input Normal file
View file

@ -0,0 +1,141 @@
#############################################################################################################################################
#.......#...#.....#.......#.........#.#.............#...........#.......#...............#.........#...........#...#.......#.......#.......#E#
#.#####.#.###.#.#.#.#.#.#.#.#.#####.#.#.###.###.###.###.#####.#.###.#.#.#.#####.#######.#.#######.#####.#####.#.#.#.###.#.#.###.#.#.#.###.#.#
#.....#.#.....#.#.#.#.#...#.#.....#...#.#...#...#.#...#.#.....#...#.#.#.....#...#...#...#...#...#.#.....#...#.#.#...#.....#.#...#.#.#.#.....#
#.###.#.#.#####.###.#.#.###.#####.#.###.#.#.#.###.###.###.#######.#.#.#######.###.###.#####.#.#.#.#.#####.#.#.#.#####.#######.#.#.###.#####.#
#.#.................#.#.#...#...#.#.#...#.#.#.#.....#.....#...#...#...#.......#.......#.....#.#.#.#.......#.#.#...#...........#.......#...#.#
#.#.#.#.#####.#######.#.#.###.###.#.#.###.#.#.#.#.#.#######.###.#######.#########.#####.#####.#.#.#######.#.#.###.#.###########.#####.#.#.###
#...#.#...#.#.#...#...#.#.#...#...#.#...#.#.#.#.#...........#...#.......#...................#.#.#.......#.#.#.....#.#.........#.......#.#...#
###.#.###.#.#.#.###.#.#.#.###.#.#######.#.#.#.###.###.###.#.#.#####.#.###.#.###.#.#########.#.#######.#.###.###.#####.#######.#.#####.#.###.#
#...#...#.#...#.#...#...#.#...#...#...#.#.#.#...#...#.#...#...#.....#.....#.....#.......#...#.#.......................#.....#.......#...#.#.#
#.#.###.#.#.###.#.###.#.#.#.#####.#.#.#.#.#.###.#.#.###.#######.#####.#####.###.#######.#.###.#.#.###.#.#.#######.#######.#.#######.#.###.#.#
#.#.....#.#...#.#.........#.....#...#.#.#.........#...#.....#.#.......#...#...#...#.....#.#.#...#...#...#.......#...#.....#.#.............#.#
#.#######.###.#.#####.#.#.###.#.#####.#.#.#######.###.#####.#.#.#####.#.#.###.#.#.#.#####.#.#.#####.#.###.#####.###.#.#.###.#.#.#.###.#.#.#.#
#.....#...#.........#...#.....#.#...#...#.#.....#.#.#.....#.#.....#...#.#.....#.#.#.#.....#.#...#...#.#.......#...#.#.#.#.....#.#...#.#...#.#
#####.#.###.#########.#.#.###.###.#.#.###.###.#.#.#.#####.#.#####.#.#.#.#######.###.#.#.###.###.#.###.#########.###.#.#.#######.###.#.###.#.#
#.....#.#.......#.....#.....#.#...#.#...#...#.#...#.......#.........#.#.#...#.......#.#...#.....#...#.#.......#...#.#.#.#.......#.#.#.......#
#.#####.###.###.#.#########.###.###.#####.#.#.###.###.#.#####.#.#######.#.###.#.#####.###.#########.#.#.#####.#.#.#.#.#.#.#######.#.#.#####.#
#.#.....#...#...#.......#.#.#...#.....#.....#.#.......#.#...#.#...#...#.#...#.#.......#.#.#.....#...#...#...#.#.#...#.#.#.......#.#.#.....#.#
#.###.###.#.#.###.#####.#.#.#.#######.#.#####.#.#######.#.#.#.#.###.#.#.#.#.#.#####.###.#.#.###.#.#######.###.#.#######.#######.#.#.#.###.#.#
#...#...#...#.#...#.....#...#.#...#.#...#...#.#...#...#...#...#.#...#.#.#.#...#...#...#.#.....#.#.......#.#...#.........#.....#.#.#...#.....#
#.#.###.###.#.#####.#####.###.#.#.#.#######.#.###.#.#.#########.#.###.#.#.#####.#.###.#.#######.#.#.###.#.#.###########.###.#.#.#.###.#####.#
#.#...#.....#.......#.........#.#.#.........#...#...#...........#.#.....#...#...#.#...#.#.....#.#.#.#.#.#.#.......#...#...#.#.#.#.#.........#
#####.#.#.#.#########.#######.#.#.###.#########.#.#############.#.#########.#.###.#.###.#.###.#.###.#.#.#.#######.#.#.###.#.#.#.#.#.#.#.#.#.#
#.....#...#...............#...#.#...#.........#.#...#.....#...#.#.......#.#.#.#...#.#...#.#...#.#...#.......#.....#.#.#...#.#.#.#.....#.#.#.#
#.#####.###.#####.###.#.###.#.#.###.###.###.###.###.#.###.#.#.#.#######.#.#.#.#.###.#.###.#.###.#.###########.#####.###.#####.#.#####.#.#.#.#
#.....#...#.....#...#.#...#.#.#...#...#...#...#.....#.#.....#.......#...#.#.#.#...#...#...#.#...#.#.....#...#.....#...#.......#.#...#...#.#.#
#####.#.#.#.###.###.###.#.#.#.###.###.###.###.###.#.###.#.#.#.#####.#.###.#.#.###.###.#.###.#.###.#.###.#.#.#####.###.###.#####.#.#.#.#.#.###
#.....#.......#.#.#...#.#.#...#.....#.#...#.#.#...#.....#...#.#.....#.#...#.#.#.......#.#.#...#...#...#...#.....#...#.....#...#...#.#.#.#...#
#.#####.###.#.#.#.###.###.#.###.#####.#.###.#.#.###########.#.#.#.###.#.###.#.#####.###.#.#####.###.###########.###.#######.#.#.###.#.#.###.#
#...........#.#.....#...#...#...#.#.........#.#...........#...#.#.....#.....#.#...#...#.#.....#...#.#.............#...#.....#.#...#.#...#.#.#
#.#####.###.#######.###.#####.###.#.###.#####.###.#####.#.#.#.###.#####.###.#.#.#.###.#.#####.#.#.#.#.###.###########.#.#####.###.#.#.#.#.#.#
#.#...#...#...........#.....#.....#.#.#.#...#.....#...#...#.#.....#.#...#...#...#.#.#.#.....#.#.#.#.#.#...#.........#...#...#.#...#.....#.#.#
#.###.#.#.#.#############.#.###.###.#.#.#.#.#.#.#.#.#.#.###.#######.#.#####.#.###.#.#.#####.#.#.#.#.#.#.###.#######.#####.#.#.#.#####.#.#.#.#
#...............#.......#.#.....#...#.#.#.#.#.#.#...#.#...#.#...#...#.#.....#.#.#.#.#...#...#...#...#.#...#.................#.#...#.......#.#
#######.#######.#.#.###.#.#######.###.#.#.#.###.#########.#.#.###.#.#.#.#.###.#.#.#.###.#.#########.#.###########.#########.#.###.###.#.###.#
#...#...#.#...#.#.....#.#...#...#...#...#.#...#.....#...#...#.#...#.#.#.#...#...#.#.#...#.#...#...#.#.........#...#.....#...#...#.......#...#
#.#.#.###.#.#.#.#.#.#.#.###.###.###.###.#.###.###.#.#.#.#####.#.###.#.#.###.###.#.#.#.###.#.#.#.#.#######.###.#.###.###.#.#.###.#######.#.###
#.#...#...#.#.#.#.#...#.#.........#...#.#...#...#...#.#.#.....#.#.#...#...#.....#.#.....#...#...#.......#...#.#...#.#.#.#.#.#...#...#...#...#
#.#####.#.#.#.#.###.###.#############.#.###.###.#.#.#.#.#.###.#.#.###.###.#######.#####.#.#############.#.###.###.#.#.#.#.###.#####.#.#.###.#
#.#.....#...#...#...#.#.........#.....#.#.#.#.#...#...#.......#.#...#...........#...#...#...#.....#...#.#.......#...#...#.....#...#...#...#.#
#.#.#############.###.#########.#.#####.#.#.#.#.#.###.#####.###.#.#.#.#######.#.###.#.#####.#####.#.#.#.#.#.#########.#########.#.#.###.#.#.#
#.......#.....#.....#...#.....#.#...#.#...#.....#...#...#...#...#.#...#.......#.....#...#.......#.#.#...#.#.........#...#.......#...........#
#.###.#.#.#.#.#####.#.#.#.#.###.###.#.###.#####.###.###.#.###.#########.###############.#######.#.#.#####.#####.#######.#####.###.#####.#.#.#
#.#...#...#.#...#...#.#...#...#...#.#.#.......#...#...#.#.....#.....#...#.#.....#.....#...#.......#.#.....#...#.......#...#...#...........#.#
#.#.#######.###.#.###.#######.###.#.#.#.#########.###.#.#########.#.#.###.#.###.#.###.###.###.#####.#####.#.#.#####.#####.#.###.#######.###.#
#.#.........#...#.....#.....#.....#.#...#.......#...#.#...#.......#...#.#...#.#...#.#.......#.#...#.....#...#.#...#.....#...#.#...#.........#
#.###########.#####.#.#.###########.#####.###.#####.#.###.#.###########.#.###.#####.#######.###.#.#####.#####.#.#.#####.#####.###.#.###.###.#
#...............#...#.#...........#.....#...#.#.....#...#...#.........#...........#...#...#...#.#...#...#...#...#.#...#.........#...#.....#.#
#.###.#.#####.#.#.###.#####.#.###.###.#.###.#.#.#.#.###.###.#.#######.#####.#####.#.#.#.#.###.#.###.#.#.#.#######.###.#########.#.###.#.###.#
#...#...#.#...#...#.#.....#.#...#...#.#.....#.....#.....#...#.#.....#.....#.#...#.#.#...#.#.....#.#...#.#.......#.....#...............#.#...#
###.#.###.#.#.#####.#####.#####.###.#.#############.#.#######.#.###.#####.###.#.#.#.#.###.#######.#####.#.#.#########.#.#########.###.#.#.###
#...#.....#.#...#.......#.......#.#.....#.....#...#.#.#.....#...#.#.#...#...#.#.#...#...#...#...........#.#...........#...#...........#...#.#
#.#.###.###.#.#.#.#.###.#########.#.###.#.###.#.#.#.#.#.###.###.#.#.#.#.###.#.#.###.#.#####.#######.#.###.#########.#.###.#.#####.#####.###.#
#.........#.#.#.#.#.#.....#.......#.#.#...#...#.#...#.#.#.#...#.....#.#...#...#...#...#.....#.......#.#...#.......#.....#.#.#.........#.#...#
#.#.###.#.#.#.#.#.#.#######.#####.#.#.###.#.###.#.###.#.#.###.#.#####.###.#######.#.###.#####.#######.#.#####.###.#######.#.###.#.#####.#.#.#
#...#...#.#...#...#...#...#...#...#.#.......#...#.#...#...#...#.#...#.#...#.....#.#...#.....#.....#...#.....#...#.#.....#.#.....#.#.....#.#.#
#.###.#.#.###.###.#.#.#.#.###.#.###.#########.###.#.#####.#.###.#.#.#.#.#.#####.#.###.#####.#.###.#.#######.###.###.###.#.#######.#.###.#.#.#
#.....#.#.......#.......#.....#...............#...#...#.#.#.....#.#...#.#.......#...#.#.#...#.#...#...#.........#...#.#...#.#.....#.#.....#.#
#######.#####.#.###.#.#####.#.#################.#.###.#.#.#########.###.#######.#.###.#.#.#####.#######.#########.###.#####.#.###.#.#.#.###.#
#.......#.....#...#.#.#...#...#...............#.#...#.#.#...#.....#.....#.....#.........#.#.....#.......#.....#...#...#.....#...#.#.#.#.....#
#.#####.#.###.#.###.#.#.#########.#.#.###.#.###.#.###.#.###.#.#.#.###.#####.#.#.###.#####.###.###.#######.###.#.###.#.#.#.#####.#.#.#.#.#####
#...#.....#.#.......#.#...........#.#...#.#.........#...#.#.#.#.#...#.....#.#...#.....#...#...#...#.......#.#...#...#...#.#.................#
###.#.#.###.#.#.#####.#.#####.#####.###.#.#.#######.###.#.#.#.#.###.#####.###.###.###.#.###.###.###.#######.#####.#######.#.#######.#.###.#.#
#...#.#...............#.#.....#.....#...#.#.#.......#...#.#.#.#.#.......#...#.#...#.#...#.........#.#.........#...#.......#.#.#.....#.....#.#
#####.#.#####.#########.#.#####.#####.###.#.#.#####.#.###.#.#.#.#######.###.#.#.###.###########.###.#.#.#####.#.###.###.###.#.#.#####.#####.#
#.....#.#.........#.....#.#.#...#.........#.#...#...#.#...#.#.#...#.#...#...#.#.#.........#...#.#...#.#...#...#...#...........#...#.......#.#
#.#####.#.###.###.#######.#.#.#.#.#####.#.###.#.#.###.#.#.#.#####.#.#.###.#####.#.#.#.###.#.#.###.#######.###.###.#.#############.#########.#
#.#...#...#.....#.....#...#.#...#...#...#...#.#.#...#.#.#.#.#.....#.#.....#.....#...#...#.#.#.....#.....#.........#.......#.#...#...#.......#
#.#.#.#####.###.#####.#.###.#.#####.###.###.###.#####.#.###.#.#####.#####.#.###########.#.#.#######.#.#.###.#.###########.#.#.#.###.#.#####.#
#.#.#.........#...#...#.#...#.#...#.#.....#...#...........#.#.....#.......#.#...........#.#.#.......#.#.......#...#...#.....#...#...#.#.#...#
#.#.###########.#.#.###.###.#.#.#.#.#.###.###.#.###.#####.#.#####.#.#######.###.#########.#.#.#####.#.#######.#.#.#.#.#.#####.#.#.###.#.#.###
#.#...#.........#.#.#.....#...#.#...#...#.#...#.#.........#.......#...#...#.#...#...#...#...#.....#.#.........#.#...#...#.....#...#...#...#.#
#.###.#.#########.#.#####.#####.#####.#.#.#.###.#.###############.###.###.#.#.#.#.#.###.###########.###########.#########.#########.#.#.###.#
#...#.#.........#.#.....#.....#.....#.#.#.#.#.....#.....#...#.........#.#...#.....#...#...........#...........#.#.....#...#.........#.#.....#
#.###.#########.#.#####.#####.#####.#.#.#.#.#.#####.###.#.#.#.#.###.#.#.#############.#.#########.###########.#.#.###.#.#.#.#########.#####.#
#.....#.......#.#.................#.#.#.#.#.#.#...#.#.#...#...#...#.#.#...............#...#...#.#.........#...#...#.#...#.#.......#...#...#.#
#.#####.#######.###.###############.#.#.#.#.###.#.#.#.###########.#.#.###.#############.#.#.#.#.#########.#.#.###.#.###.#.#######.#.###.#.###
#.......#.....#...#.#...#...........#.#.#.#.#...#.#.#...#.........#.#.#...#.....#.....#.#...#.#.............#.#.#.....#.#...#...............#
#.#####.#.###.###.#.#.###.#############.#.#.#.###.#.#.#.#.#########.#.#.#.#.###.#.#####.#####.#.#####.#######.#.#.#.#.#.###.###.#.#######.#.#
#.......#...#.#...#...#...#.........#...#.#...#...#.#.#.#...#.#.......#.#.#...#.#.....#.....#.#.#...#...#...#...#.#.#.#.#.#...#.....#...#.#.#
#.#########.#.#.#####.#.#######.###.#.###.#####.###.#.###.#.#.#.#####.#.#####.#.###.#.#####.#.###.#.#####.#.#####.#.###.#.###.#######.#.#.#.#
#.#.....#...#...#...#.#.......#.#.#...#.#.#...#.....#...#.......#.....#.......#...#.#...#...#.#...#...#...#...#...#.....#...#.#.......#.#.#.#
#.#.###.#.#.###.#.#.#.#######.#.#.#####.#.#.#.#######.#.#.###.###.#####.#########.#####.#.###.#.#####.#.#####.#.###.#####.###.#.#######.###.#
#.#.#.....#.#.....#.#.#.........#.#.....#...#.#.....#.#.#...#.....#...#...#...#.#.....#.....#.#.#...#...#...#.#...#.......#...#...#...#.#...#
#.#.#.#######.#####.#.#.#.#######.#.###.#####.#.#####.#.###.###.###.#.###.#.#.#.#####.#####.#.#.###.#.#.###.#.###.###.###.#.#####.#.#.#.#.###
#.......#...#...#.#.#.#.#.........#...#.........#.....#...#...#.#...#...#...#.#.....#...#.#.#.#.....#.......#...#...#.#...#.#.....#.#...#...#
#.#.#####.#.###.#.#.###.###.#.#####.#.#########.#.#.###.#####.#.#.###.#.#####.#.###.###.#.#.#.#####.#####.###.###.#.###.#.#.#.#####.###.#.#.#
#.#.#.....#...#...#.#.......#.#.....#.#.#.......#.#...#.....#...#...#.#...#...#...#.#.#.#.#.#.....#.#.......#.#...#.#...#.#.#.#.......#...#.#
#.###.#######.###.#.#.#####.###.#.###.#.#.#.#.###.#.#.#####.#######.#.###.#.#.###.#.#.#.#.#.#####.#.#.#####.#.#.#.#.#.#.###.#.#.#####.#.###.#
#.....#.....#.....#.....#...#...#.#...#...#.#.#...#.#.....#...#.#...#...#.#.#.....#...#.#...#...#.#.#.#.....#...#.#...#.#...#.#.....#...#...#
#######.#.###############.#.#.###.#.#######.#.#.#####.###.#.#.#.#.#####.#.#.###.#######.#.###.#.#.#.###.#####.###.#####.#.###.#####.###.#.###
#.....#.#.............#...#.#...#.#...#.....#.#.....#.#.#.#.#...#.....#.#.#.....#.......#.#.#.#...#.....#...#.........#.#.#.....#.......#...#
#####.#.#.###.#######.#.#######.#.###.#.#####.#####.#.#.#.#.###.#####.#.#.#####.#.#######.#.#.#######.###.#.#####.#####.#.#.#.#.#######.###.#
#.....#...#...#...#...#.........#...#.#.......#...#...#...#...#.#.....#.#...#.#.#...#...#...#.............#.....#.........#.#.#...#...#.....#
#.###.###.#.###.#.#.#.#############.#.#.#####.#.#.#####.#####.###.#####.###.#.#.###.#.#.###.###########.#######.#########.#.#.###.#.#.#.#####
#...........#...#.#.#.....#...#...#...#.#...#...#...#...#...#...#...#...#.....#.#.#.#.....#.#.....#...#.#...#.#.......#...#.....#...#...#...#
#.#######.#.#.###.#.#####.#.#.#.#.#######.#.#.#####.#.###.#.###.#.###.#########.#.#.#.###.#.#.#####.#.#.#.#.#.#####.#.#.###.#########.#.#.#.#
#.....#...#.#...#.#.......#.#.#.#.........#.#...#...#.....#.#.#...#...#.....#...#.#...#.#.#...#.....#.#...#.#.......#.....#...#.....#.#...#.#
#####.#.#.#.#####.#######.#.#.#.###.#.#####.#####.#########.#.#.###.#.#.###.#.###.#####.#.#####.#####.#####.#######.#.###.#####.###.#.#.###.#
#...#...........#.#...#...#.#...#.#...#.........#.....#.....#.....#.#.#...#.#.#.........#.......#...#.....#.......#.#.....#.....#.#.#.....#.#
#.#.#####.#.#.#.#.#.#.#.###.#####.#.#####.#####.#####.#.#.#####.###.#####.#.#.#.#######.#.#########.#.###.#######.#.#######.#####.#.###.###.#
#.......#.#.#.#.#...#...#.#.#...#.#.....#.....#.......#.#.....#...#.....#.#...#.....#.#.#...........#.#...........#.......#.#...#.....#.....#
#.#####.#.###.#.#.#######.#.#.#.#.#####.#.###.#########.#.###.###.###.###.#########.#.#.#.#####.#####.#.###########.#.###.#.#.#.#####.#.###.#
#.#...#.#.#...#.#.......#.#...#...#...#.#.#.#...........#...#.....#.#.#...#.........#...#.#.#...#.....#...#.......#...#.#.#.#.....#.#.#.#...#
#.#.#.#.#.#.###.#.#####.#.#######.#.#.#.#.#.###############.#####.#.#.#.###.###.#####.#.#.#.#.###.###.###.###.#.#.#.###.#.#.#.###.#.#.#.###.#
#...#...#.#.#.#...#...#...#.......#.#.....#...............#.....#...#...#.#.#...#.....#.#.#.....#.#.#...#...#.#.#...#.....#.#.....#.#.......#
#.#####.#.#.#.#.###.#.###.#.#######.#.#####.#.###########.#.###.#####.###.#.#.###.#####.#.#.#####.#.###.###.###.#####.#####.###.#.#.#.###.#.#
#.#...#...#.#.#.....#...#.#.........#.......#.......#.......#.#.........#...#.#...#.....#.#...#...#.......#...#.#.....#.......#.#.#.#.#...#.#
#.#.#.###.#.#.#########.#.#####.###.#########.#.#####.#####.#.#######.###.###.#.###.#####.#.###.#.#######.###.#.#.#####.#######.#.#.#.#.#####
#.#...........#...#.#...#...#...#...#...#.....#.......#.............#.#...#...#...#.......#.#.....#.........#...#...#...........#.#...#.....#
#.#.#.#######.#.#.#.#.#.###.#.###.###.###.#############.#############.#.###.###.#.#.#########.###.#.#.#####.#######.#.###########.#.#.#.###.#
#...#.#.....#...#.#.#...#...#.#.....#.#...#...........#.#...........#.#.#.#.#.#.#...#.....#...#...#.#.....#...#...#.#.#...#...#...#...#...#.#
#.###.#.#.#######.#.###.#####.#.###.#.#.###.#####.###.###.#####.#.#.#.#.#.#.#.#.#####.###.#.#.#####.#####.#####.#.#.#.#.#.#.###.#####.#####.#
#...#.#.#.......#...#.#.#...#.#.#...#.#...#...#.......#...#.....#.#...#...#.#...#...#.#.....#.#.....#.....#...#.#...#...#...#...#...........#
#####.#.#######.#.#.#.#.#.#.#.#.#.###.###.###.###.#####.#####.###.#####.#.#.###.#.#.#.#########.#####.###.#.#.#.#######.###.#.###############
#.....#.#...#...#...#.#.#.#.....#.#.........#...#.#...#.....#.....#.....#.#...#...#.#.#.........#...#.#...#.#...#...#.....#.#.#.............#
#.###.#.#.#.#.###.###.#.#.#####.#.#########.###.#.#.#.###.#.#######.#.###.###.#####.#.#.###########.#.#####.#######.#.#.###.#.#.###########.#
#...#.#.#.#.#.....#...#.#...#...#.........#.#...#...#...#.#.......#.#.....#.#.#.....#...#.....#.....#.......#.....#...#.#...#.......#.......#
#.#.#.#.#.#########.#.#.###.#############.#.#.#########.#.#######.#.#######.#.###############.#.#.###.#######.###.###.#.#.#########.#.#.#.#.#
#.#.#.#.#...........#.#...#.#...#.......#.#.#.#.....#.#.#.......#.....#.........#...........#...#.#.........#...#...#.#...................#.#
#.#.###.#.#######.###.###.#.#.#.#.#####.#.#.#.#.###.#.#.###.#########.#.###.###.#.#.###.###.#####.#.#####.#.###.#.#.#.#########.#.#.#.#.###.#
#.#.....#.#.....#.#.....#.#.#.#...#...#.#.#.#...#...#.#.#...#.......#...#.#...#...#.....#.#.#...#.......#.#.#...#...#.#.........#.#...#.#...#
#.#######.#.###.#.###.#.#.#.#.#####.###.#.#.#.###.###.#.#.###.#####.#####.###.#####.###.#.#.#.#.#####.###.#.#.###.#####.#########.#######.#.#
#...#.....#.#...#...#...#.#...#...#.....#.#.#...#.#.....#...#.#...#.#...#.........#.#.#.....#.#...........#...#.#.......#.......#.....#...#.#
###.#.#####.#.#####.###.#.#######.#.#####.#.#####.#.#####.###.#.###.###.#.#####.###.#.#.###.#.#############.#.#.#########.#####.#####.#.###.#
#.#.#.....#.#.#...#...#.#...#.....#.#.....#.......#...#...#...#.......#.........#...#.#.#.......#.........#...#.....#.....#.#...#.....#...#.#
#.#.#####.#.#.#.#.###.#####.#.#.#.#.#.#.###########.#.#.###.#########.#######.#.#.###.#.#.#.###.#########.#######.#.#.#####.#.###.#######.#.#
#...#...#.#.#...#.#...#...#.#.#.#.#.#.#.#...#.........#.#...#.....#...#.....#...#...#...#.#...#.#...#.......#.....#...#.......#...#.......#.#
#.#.#.#.#.#######.#.###.#.#.#.#.###.#.#.#.#.#######.#.###.###.###.#.###.###.#######.#.###.#.#.#.#.#.#.#####.#.#########.#######.###.###.###.#
#.#...#.#...#...........#.........................#.....#...............#.#.........#.#...#.#.#...#.#...#.#.#...#.....#.#.......#.....#...#.#
#.#.###.###.#.###.###.###.###########.#.#.#######.#.###.###.###.#.#.#.###.###########.#####.#.###.#.#.#.#.#.###.#.#####.#.#######.#######.#.#
#...#...#...#.#.#.#...#.........#...#.#.#.....#.#.....#...#.#...#.#...#.............#.#.....#...#.#.#.#.#.......#.......#.........#.......#.#
###.#.###.###.#.#.#.#.#.#######.#.#.#.#.#####.#.#####.###.#.#.#.#.#######.#####.#.###.#.#.#.###.#.#.###.#######.#####.#####.###.#.#.#######.#
#...#.#.#.....#...#.#...#.....#.#.#...#.#.........#...#.#.#.....................#...#...#...#.#.#.#...#.....#.#.#...#.......#...#.#...#...#.#
#.#.#.#.#.#####.###.#.###.###.#.#.#######.#######.#.###.#.###.#.###.#.#.###.#.###.#.#######.#.#.#####.#.###.#.#.#.#.#######.#.#######.#.#.#.#
#.....#...#...#...#.#.....#...#.#.........#.....#.#.#.#...#.......#...#...#.#...#.#...........#.....#.#...#.#...#.#.......#.#...#...#...#.#.#
#.#.#######.#.#####.#.#.#####.#.#####.#####.###.###.#.#.###.#.###########.#.###.#.#####.###.#.#####.#.###.#.#####.#######.#.#.#.#.#.#####.#.#
#.#.....#...#.#.....#.#.#...#.#.....#.....#.#.#...#.#.#...#...#.......................#...#...#...#.#...................#.#...#.#.#.#.......#
#.###.#.#.###.#.#####.#.#.#.#######.#######.#.###.#.#.###.###.#.#######.#####.###.#.#.###.#.###.#.#.###.#.#.#.#####.###.#.#####.#.#.#.#####.#
#S....#...#.....#.....#...#.................#.......#...........#.............#.....#...#.......#.....................................#.....#
#############################################################################################################################################

149
2024/d16/ex2/ex2.py Executable file
View file

@ -0,0 +1,149 @@
#!/usr/bin/env python
import enum
import heapq
import sys
from collections import defaultdict
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class ParsedMaze(NamedTuple):
start: Point
end: Point
blocks: set[Point]
class Direction(enum.IntEnum):
EAST = enum.auto()
WEST = enum.auto()
NORTH = enum.auto()
SOUTH = enum.auto()
def rotations(self) -> tuple["Direction", "Direction"]:
match self:
case Direction.EAST | Direction.WEST:
return (Direction.NORTH, Direction.SOUTH)
case Direction.NORTH | Direction.SOUTH:
return (Direction.EAST, Direction.WEST)
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.EAST:
dx, dy = 0, 1
case Direction.WEST:
dx, dy = 0, -1
case Direction.NORTH:
dx, dy = -1, 0
case Direction.SOUTH:
dx, dy = 1, 0
return Point(p.x + dx, p.y + dy)
Node = tuple[Point, Direction]
def solve(input: str) -> int:
def parse(input: list[str]) -> ParsedMaze:
start: Point | None = None
end: Point | None = None
blocks: set[Point] = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
p = Point(x, y)
if c == "S":
start = p
elif c == "E":
end = p
elif c == "#":
blocks.add(p)
else:
assert False # Sanity check
assert start is not None # Sanity check
assert end is not None # Sanity check
return ParsedMaze(start, end, blocks)
def count_path_cells(start: Point, end: Point, blocks: set[Point]) -> int:
def next_moves(
pos: Point,
dir: Direction,
) -> Iterator[tuple[int, Point, Direction]]:
transitions = [(1, dir.step(pos), dir)]
for new_dir in dir.rotations():
transitions.append((1000, pos, new_dir))
for cost, pos, dir in transitions:
if pos in blocks:
continue
yield cost, pos, dir
def get_all_predecessors(
predecessors: dict[Node, set[Node]],
) -> set[Point]:
queue = {(end, dir) for dir in Direction}
visited: set[Node] = set()
while queue:
cur = queue.pop()
visited.add(cur)
for pred in predecessors[cur]:
if pred in visited:
continue
queue.add(pred)
return set(p for p, _ in visited)
# Priority queue of (distance, point)
queue = [(0, start, Direction.EAST)]
seen: set[Node] = set()
predecessors: dict[Node, set[Node]] = defaultdict(set)
predecessor_cost: dict[Node, int] = {}
# Use an invalid maximum cost to simplify the loop
max_cost: int = -1
while len(queue) > 0:
cost, p, dir = heapq.heappop(queue)
# Did we go past the optimal cost, if so stop the loop
if max_cost > 0 and cost > max_cost:
break
# Otherwise, record the minimum cost
if p == end:
max_cost = cost
# We must have seen (p, dir) with a smaller distance before
if (p, dir) in seen:
continue
# First time encountering (p, dir), must be the smallest distance to it
seen.add((p, dir))
# Add all neighbours to be visited
for n_cost, n, n_dir in next_moves(p, dir):
n_cost += cost
# Record predecessors
if predecessor_cost.setdefault((n, n_dir), n_cost) > n_cost:
predecessor_cost[(n, n_dir)] = n_cost
predecessors[(n, n_dir)] = {(p, dir)}
elif predecessor_cost[(n, n_dir)] == n_cost:
predecessors[(n, n_dir)].add((p, dir))
heapq.heappush(queue, (n_cost, n, n_dir))
# Run back up the tree of predecessors to count all cells
return len(get_all_predecessors(predecessors))
start, end, blocks = parse(input.splitlines())
return count_path_cells(start, end, blocks)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

141
2024/d16/ex2/input Normal file
View file

@ -0,0 +1,141 @@
#############################################################################################################################################
#.......#...#.....#.......#.........#.#.............#...........#.......#...............#.........#...........#...#.......#.......#.......#E#
#.#####.#.###.#.#.#.#.#.#.#.#.#####.#.#.###.###.###.###.#####.#.###.#.#.#.#####.#######.#.#######.#####.#####.#.#.#.###.#.#.###.#.#.#.###.#.#
#.....#.#.....#.#.#.#.#...#.#.....#...#.#...#...#.#...#.#.....#...#.#.#.....#...#...#...#...#...#.#.....#...#.#.#...#.....#.#...#.#.#.#.....#
#.###.#.#.#####.###.#.#.###.#####.#.###.#.#.#.###.###.###.#######.#.#.#######.###.###.#####.#.#.#.#.#####.#.#.#.#####.#######.#.#.###.#####.#
#.#.................#.#.#...#...#.#.#...#.#.#.#.....#.....#...#...#...#.......#.......#.....#.#.#.#.......#.#.#...#...........#.......#...#.#
#.#.#.#.#####.#######.#.#.###.###.#.#.###.#.#.#.#.#.#######.###.#######.#########.#####.#####.#.#.#######.#.#.###.#.###########.#####.#.#.###
#...#.#...#.#.#...#...#.#.#...#...#.#...#.#.#.#.#...........#...#.......#...................#.#.#.......#.#.#.....#.#.........#.......#.#...#
###.#.###.#.#.#.###.#.#.#.###.#.#######.#.#.#.###.###.###.#.#.#####.#.###.#.###.#.#########.#.#######.#.###.###.#####.#######.#.#####.#.###.#
#...#...#.#...#.#...#...#.#...#...#...#.#.#.#...#...#.#...#...#.....#.....#.....#.......#...#.#.......................#.....#.......#...#.#.#
#.#.###.#.#.###.#.###.#.#.#.#####.#.#.#.#.#.###.#.#.###.#######.#####.#####.###.#######.#.###.#.#.###.#.#.#######.#######.#.#######.#.###.#.#
#.#.....#.#...#.#.........#.....#...#.#.#.........#...#.....#.#.......#...#...#...#.....#.#.#...#...#...#.......#...#.....#.#.............#.#
#.#######.###.#.#####.#.#.###.#.#####.#.#.#######.###.#####.#.#.#####.#.#.###.#.#.#.#####.#.#.#####.#.###.#####.###.#.#.###.#.#.#.###.#.#.#.#
#.....#...#.........#...#.....#.#...#...#.#.....#.#.#.....#.#.....#...#.#.....#.#.#.#.....#.#...#...#.#.......#...#.#.#.#.....#.#...#.#...#.#
#####.#.###.#########.#.#.###.###.#.#.###.###.#.#.#.#####.#.#####.#.#.#.#######.###.#.#.###.###.#.###.#########.###.#.#.#######.###.#.###.#.#
#.....#.#.......#.....#.....#.#...#.#...#...#.#...#.......#.........#.#.#...#.......#.#...#.....#...#.#.......#...#.#.#.#.......#.#.#.......#
#.#####.###.###.#.#########.###.###.#####.#.#.###.###.#.#####.#.#######.#.###.#.#####.###.#########.#.#.#####.#.#.#.#.#.#.#######.#.#.#####.#
#.#.....#...#...#.......#.#.#...#.....#.....#.#.......#.#...#.#...#...#.#...#.#.......#.#.#.....#...#...#...#.#.#...#.#.#.......#.#.#.....#.#
#.###.###.#.#.###.#####.#.#.#.#######.#.#####.#.#######.#.#.#.#.###.#.#.#.#.#.#####.###.#.#.###.#.#######.###.#.#######.#######.#.#.#.###.#.#
#...#...#...#.#...#.....#...#.#...#.#...#...#.#...#...#...#...#.#...#.#.#.#...#...#...#.#.....#.#.......#.#...#.........#.....#.#.#...#.....#
#.#.###.###.#.#####.#####.###.#.#.#.#######.#.###.#.#.#########.#.###.#.#.#####.#.###.#.#######.#.#.###.#.#.###########.###.#.#.#.###.#####.#
#.#...#.....#.......#.........#.#.#.........#...#...#...........#.#.....#...#...#.#...#.#.....#.#.#.#.#.#.#.......#...#...#.#.#.#.#.........#
#####.#.#.#.#########.#######.#.#.###.#########.#.#############.#.#########.#.###.#.###.#.###.#.###.#.#.#.#######.#.#.###.#.#.#.#.#.#.#.#.#.#
#.....#...#...............#...#.#...#.........#.#...#.....#...#.#.......#.#.#.#...#.#...#.#...#.#...#.......#.....#.#.#...#.#.#.#.....#.#.#.#
#.#####.###.#####.###.#.###.#.#.###.###.###.###.###.#.###.#.#.#.#######.#.#.#.#.###.#.###.#.###.#.###########.#####.###.#####.#.#####.#.#.#.#
#.....#...#.....#...#.#...#.#.#...#...#...#...#.....#.#.....#.......#...#.#.#.#...#...#...#.#...#.#.....#...#.....#...#.......#.#...#...#.#.#
#####.#.#.#.###.###.###.#.#.#.###.###.###.###.###.#.###.#.#.#.#####.#.###.#.#.###.###.#.###.#.###.#.###.#.#.#####.###.###.#####.#.#.#.#.#.###
#.....#.......#.#.#...#.#.#...#.....#.#...#.#.#...#.....#...#.#.....#.#...#.#.#.......#.#.#...#...#...#...#.....#...#.....#...#...#.#.#.#...#
#.#####.###.#.#.#.###.###.#.###.#####.#.###.#.#.###########.#.#.#.###.#.###.#.#####.###.#.#####.###.###########.###.#######.#.#.###.#.#.###.#
#...........#.#.....#...#...#...#.#.........#.#...........#...#.#.....#.....#.#...#...#.#.....#...#.#.............#...#.....#.#...#.#...#.#.#
#.#####.###.#######.###.#####.###.#.###.#####.###.#####.#.#.#.###.#####.###.#.#.#.###.#.#####.#.#.#.#.###.###########.#.#####.###.#.#.#.#.#.#
#.#...#...#...........#.....#.....#.#.#.#...#.....#...#...#.#.....#.#...#...#...#.#.#.#.....#.#.#.#.#.#...#.........#...#...#.#...#.....#.#.#
#.###.#.#.#.#############.#.###.###.#.#.#.#.#.#.#.#.#.#.###.#######.#.#####.#.###.#.#.#####.#.#.#.#.#.#.###.#######.#####.#.#.#.#####.#.#.#.#
#...............#.......#.#.....#...#.#.#.#.#.#.#...#.#...#.#...#...#.#.....#.#.#.#.#...#...#...#...#.#...#.................#.#...#.......#.#
#######.#######.#.#.###.#.#######.###.#.#.#.###.#########.#.#.###.#.#.#.#.###.#.#.#.###.#.#########.#.###########.#########.#.###.###.#.###.#
#...#...#.#...#.#.....#.#...#...#...#...#.#...#.....#...#...#.#...#.#.#.#...#...#.#.#...#.#...#...#.#.........#...#.....#...#...#.......#...#
#.#.#.###.#.#.#.#.#.#.#.###.###.###.###.#.###.###.#.#.#.#####.#.###.#.#.###.###.#.#.#.###.#.#.#.#.#######.###.#.###.###.#.#.###.#######.#.###
#.#...#...#.#.#.#.#...#.#.........#...#.#...#...#...#.#.#.....#.#.#...#...#.....#.#.....#...#...#.......#...#.#...#.#.#.#.#.#...#...#...#...#
#.#####.#.#.#.#.###.###.#############.#.###.###.#.#.#.#.#.###.#.#.###.###.#######.#####.#.#############.#.###.###.#.#.#.#.###.#####.#.#.###.#
#.#.....#...#...#...#.#.........#.....#.#.#.#.#...#...#.......#.#...#...........#...#...#...#.....#...#.#.......#...#...#.....#...#...#...#.#
#.#.#############.###.#########.#.#####.#.#.#.#.#.###.#####.###.#.#.#.#######.#.###.#.#####.#####.#.#.#.#.#.#########.#########.#.#.###.#.#.#
#.......#.....#.....#...#.....#.#...#.#...#.....#...#...#...#...#.#...#.......#.....#...#.......#.#.#...#.#.........#...#.......#...........#
#.###.#.#.#.#.#####.#.#.#.#.###.###.#.###.#####.###.###.#.###.#########.###############.#######.#.#.#####.#####.#######.#####.###.#####.#.#.#
#.#...#...#.#...#...#.#...#...#...#.#.#.......#...#...#.#.....#.....#...#.#.....#.....#...#.......#.#.....#...#.......#...#...#...........#.#
#.#.#######.###.#.###.#######.###.#.#.#.#########.###.#.#########.#.#.###.#.###.#.###.###.###.#####.#####.#.#.#####.#####.#.###.#######.###.#
#.#.........#...#.....#.....#.....#.#...#.......#...#.#...#.......#...#.#...#.#...#.#.......#.#...#.....#...#.#...#.....#...#.#...#.........#
#.###########.#####.#.#.###########.#####.###.#####.#.###.#.###########.#.###.#####.#######.###.#.#####.#####.#.#.#####.#####.###.#.###.###.#
#...............#...#.#...........#.....#...#.#.....#...#...#.........#...........#...#...#...#.#...#...#...#...#.#...#.........#...#.....#.#
#.###.#.#####.#.#.###.#####.#.###.###.#.###.#.#.#.#.###.###.#.#######.#####.#####.#.#.#.#.###.#.###.#.#.#.#######.###.#########.#.###.#.###.#
#...#...#.#...#...#.#.....#.#...#...#.#.....#.....#.....#...#.#.....#.....#.#...#.#.#...#.#.....#.#...#.#.......#.....#...............#.#...#
###.#.###.#.#.#####.#####.#####.###.#.#############.#.#######.#.###.#####.###.#.#.#.#.###.#######.#####.#.#.#########.#.#########.###.#.#.###
#...#.....#.#...#.......#.......#.#.....#.....#...#.#.#.....#...#.#.#...#...#.#.#...#...#...#...........#.#...........#...#...........#...#.#
#.#.###.###.#.#.#.#.###.#########.#.###.#.###.#.#.#.#.#.###.###.#.#.#.#.###.#.#.###.#.#####.#######.#.###.#########.#.###.#.#####.#####.###.#
#.........#.#.#.#.#.#.....#.......#.#.#...#...#.#...#.#.#.#...#.....#.#...#...#...#...#.....#.......#.#...#.......#.....#.#.#.........#.#...#
#.#.###.#.#.#.#.#.#.#######.#####.#.#.###.#.###.#.###.#.#.###.#.#####.###.#######.#.###.#####.#######.#.#####.###.#######.#.###.#.#####.#.#.#
#...#...#.#...#...#...#...#...#...#.#.......#...#.#...#...#...#.#...#.#...#.....#.#...#.....#.....#...#.....#...#.#.....#.#.....#.#.....#.#.#
#.###.#.#.###.###.#.#.#.#.###.#.###.#########.###.#.#####.#.###.#.#.#.#.#.#####.#.###.#####.#.###.#.#######.###.###.###.#.#######.#.###.#.#.#
#.....#.#.......#.......#.....#...............#...#...#.#.#.....#.#...#.#.......#...#.#.#...#.#...#...#.........#...#.#...#.#.....#.#.....#.#
#######.#####.#.###.#.#####.#.#################.#.###.#.#.#########.###.#######.#.###.#.#.#####.#######.#########.###.#####.#.###.#.#.#.###.#
#.......#.....#...#.#.#...#...#...............#.#...#.#.#...#.....#.....#.....#.........#.#.....#.......#.....#...#...#.....#...#.#.#.#.....#
#.#####.#.###.#.###.#.#.#########.#.#.###.#.###.#.###.#.###.#.#.#.###.#####.#.#.###.#####.###.###.#######.###.#.###.#.#.#.#####.#.#.#.#.#####
#...#.....#.#.......#.#...........#.#...#.#.........#...#.#.#.#.#...#.....#.#...#.....#...#...#...#.......#.#...#...#...#.#.................#
###.#.#.###.#.#.#####.#.#####.#####.###.#.#.#######.###.#.#.#.#.###.#####.###.###.###.#.###.###.###.#######.#####.#######.#.#######.#.###.#.#
#...#.#...............#.#.....#.....#...#.#.#.......#...#.#.#.#.#.......#...#.#...#.#...#.........#.#.........#...#.......#.#.#.....#.....#.#
#####.#.#####.#########.#.#####.#####.###.#.#.#####.#.###.#.#.#.#######.###.#.#.###.###########.###.#.#.#####.#.###.###.###.#.#.#####.#####.#
#.....#.#.........#.....#.#.#...#.........#.#...#...#.#...#.#.#...#.#...#...#.#.#.........#...#.#...#.#...#...#...#...........#...#.......#.#
#.#####.#.###.###.#######.#.#.#.#.#####.#.###.#.#.###.#.#.#.#####.#.#.###.#####.#.#.#.###.#.#.###.#######.###.###.#.#############.#########.#
#.#...#...#.....#.....#...#.#...#...#...#...#.#.#...#.#.#.#.#.....#.#.....#.....#...#...#.#.#.....#.....#.........#.......#.#...#...#.......#
#.#.#.#####.###.#####.#.###.#.#####.###.###.###.#####.#.###.#.#####.#####.#.###########.#.#.#######.#.#.###.#.###########.#.#.#.###.#.#####.#
#.#.#.........#...#...#.#...#.#...#.#.....#...#...........#.#.....#.......#.#...........#.#.#.......#.#.......#...#...#.....#...#...#.#.#...#
#.#.###########.#.#.###.###.#.#.#.#.#.###.###.#.###.#####.#.#####.#.#######.###.#########.#.#.#####.#.#######.#.#.#.#.#.#####.#.#.###.#.#.###
#.#...#.........#.#.#.....#...#.#...#...#.#...#.#.........#.......#...#...#.#...#...#...#...#.....#.#.........#.#...#...#.....#...#...#...#.#
#.###.#.#########.#.#####.#####.#####.#.#.#.###.#.###############.###.###.#.#.#.#.#.###.###########.###########.#########.#########.#.#.###.#
#...#.#.........#.#.....#.....#.....#.#.#.#.#.....#.....#...#.........#.#...#.....#...#...........#...........#.#.....#...#.........#.#.....#
#.###.#########.#.#####.#####.#####.#.#.#.#.#.#####.###.#.#.#.#.###.#.#.#############.#.#########.###########.#.#.###.#.#.#.#########.#####.#
#.....#.......#.#.................#.#.#.#.#.#.#...#.#.#...#...#...#.#.#...............#...#...#.#.........#...#...#.#...#.#.......#...#...#.#
#.#####.#######.###.###############.#.#.#.#.###.#.#.#.###########.#.#.###.#############.#.#.#.#.#########.#.#.###.#.###.#.#######.#.###.#.###
#.......#.....#...#.#...#...........#.#.#.#.#...#.#.#...#.........#.#.#...#.....#.....#.#...#.#.............#.#.#.....#.#...#...............#
#.#####.#.###.###.#.#.###.#############.#.#.#.###.#.#.#.#.#########.#.#.#.#.###.#.#####.#####.#.#####.#######.#.#.#.#.#.###.###.#.#######.#.#
#.......#...#.#...#...#...#.........#...#.#...#...#.#.#.#...#.#.......#.#.#...#.#.....#.....#.#.#...#...#...#...#.#.#.#.#.#...#.....#...#.#.#
#.#########.#.#.#####.#.#######.###.#.###.#####.###.#.###.#.#.#.#####.#.#####.#.###.#.#####.#.###.#.#####.#.#####.#.###.#.###.#######.#.#.#.#
#.#.....#...#...#...#.#.......#.#.#...#.#.#...#.....#...#.......#.....#.......#...#.#...#...#.#...#...#...#...#...#.....#...#.#.......#.#.#.#
#.#.###.#.#.###.#.#.#.#######.#.#.#####.#.#.#.#######.#.#.###.###.#####.#########.#####.#.###.#.#####.#.#####.#.###.#####.###.#.#######.###.#
#.#.#.....#.#.....#.#.#.........#.#.....#...#.#.....#.#.#...#.....#...#...#...#.#.....#.....#.#.#...#...#...#.#...#.......#...#...#...#.#...#
#.#.#.#######.#####.#.#.#.#######.#.###.#####.#.#####.#.###.###.###.#.###.#.#.#.#####.#####.#.#.###.#.#.###.#.###.###.###.#.#####.#.#.#.#.###
#.......#...#...#.#.#.#.#.........#...#.........#.....#...#...#.#...#...#...#.#.....#...#.#.#.#.....#.......#...#...#.#...#.#.....#.#...#...#
#.#.#####.#.###.#.#.###.###.#.#####.#.#########.#.#.###.#####.#.#.###.#.#####.#.###.###.#.#.#.#####.#####.###.###.#.###.#.#.#.#####.###.#.#.#
#.#.#.....#...#...#.#.......#.#.....#.#.#.......#.#...#.....#...#...#.#...#...#...#.#.#.#.#.#.....#.#.......#.#...#.#...#.#.#.#.......#...#.#
#.###.#######.###.#.#.#####.###.#.###.#.#.#.#.###.#.#.#####.#######.#.###.#.#.###.#.#.#.#.#.#####.#.#.#####.#.#.#.#.#.#.###.#.#.#####.#.###.#
#.....#.....#.....#.....#...#...#.#...#...#.#.#...#.#.....#...#.#...#...#.#.#.....#...#.#...#...#.#.#.#.....#...#.#...#.#...#.#.....#...#...#
#######.#.###############.#.#.###.#.#######.#.#.#####.###.#.#.#.#.#####.#.#.###.#######.#.###.#.#.#.###.#####.###.#####.#.###.#####.###.#.###
#.....#.#.............#...#.#...#.#...#.....#.#.....#.#.#.#.#...#.....#.#.#.....#.......#.#.#.#...#.....#...#.........#.#.#.....#.......#...#
#####.#.#.###.#######.#.#######.#.###.#.#####.#####.#.#.#.#.###.#####.#.#.#####.#.#######.#.#.#######.###.#.#####.#####.#.#.#.#.#######.###.#
#.....#...#...#...#...#.........#...#.#.......#...#...#...#...#.#.....#.#...#.#.#...#...#...#.............#.....#.........#.#.#...#...#.....#
#.###.###.#.###.#.#.#.#############.#.#.#####.#.#.#####.#####.###.#####.###.#.#.###.#.#.###.###########.#######.#########.#.#.###.#.#.#.#####
#...........#...#.#.#.....#...#...#...#.#...#...#...#...#...#...#...#...#.....#.#.#.#.....#.#.....#...#.#...#.#.......#...#.....#...#...#...#
#.#######.#.#.###.#.#####.#.#.#.#.#######.#.#.#####.#.###.#.###.#.###.#########.#.#.#.###.#.#.#####.#.#.#.#.#.#####.#.#.###.#########.#.#.#.#
#.....#...#.#...#.#.......#.#.#.#.........#.#...#...#.....#.#.#...#...#.....#...#.#...#.#.#...#.....#.#...#.#.......#.....#...#.....#.#...#.#
#####.#.#.#.#####.#######.#.#.#.###.#.#####.#####.#########.#.#.###.#.#.###.#.###.#####.#.#####.#####.#####.#######.#.###.#####.###.#.#.###.#
#...#...........#.#...#...#.#...#.#...#.........#.....#.....#.....#.#.#...#.#.#.........#.......#...#.....#.......#.#.....#.....#.#.#.....#.#
#.#.#####.#.#.#.#.#.#.#.###.#####.#.#####.#####.#####.#.#.#####.###.#####.#.#.#.#######.#.#########.#.###.#######.#.#######.#####.#.###.###.#
#.......#.#.#.#.#...#...#.#.#...#.#.....#.....#.......#.#.....#...#.....#.#...#.....#.#.#...........#.#...........#.......#.#...#.....#.....#
#.#####.#.###.#.#.#######.#.#.#.#.#####.#.###.#########.#.###.###.###.###.#########.#.#.#.#####.#####.#.###########.#.###.#.#.#.#####.#.###.#
#.#...#.#.#...#.#.......#.#...#...#...#.#.#.#...........#...#.....#.#.#...#.........#...#.#.#...#.....#...#.......#...#.#.#.#.....#.#.#.#...#
#.#.#.#.#.#.###.#.#####.#.#######.#.#.#.#.#.###############.#####.#.#.#.###.###.#####.#.#.#.#.###.###.###.###.#.#.#.###.#.#.#.###.#.#.#.###.#
#...#...#.#.#.#...#...#...#.......#.#.....#...............#.....#...#...#.#.#...#.....#.#.#.....#.#.#...#...#.#.#...#.....#.#.....#.#.......#
#.#####.#.#.#.#.###.#.###.#.#######.#.#####.#.###########.#.###.#####.###.#.#.###.#####.#.#.#####.#.###.###.###.#####.#####.###.#.#.#.###.#.#
#.#...#...#.#.#.....#...#.#.........#.......#.......#.......#.#.........#...#.#...#.....#.#...#...#.......#...#.#.....#.......#.#.#.#.#...#.#
#.#.#.###.#.#.#########.#.#####.###.#########.#.#####.#####.#.#######.###.###.#.###.#####.#.###.#.#######.###.#.#.#####.#######.#.#.#.#.#####
#.#...........#...#.#...#...#...#...#...#.....#.......#.............#.#...#...#...#.......#.#.....#.........#...#...#...........#.#...#.....#
#.#.#.#######.#.#.#.#.#.###.#.###.###.###.#############.#############.#.###.###.#.#.#########.###.#.#.#####.#######.#.###########.#.#.#.###.#
#...#.#.....#...#.#.#...#...#.#.....#.#...#...........#.#...........#.#.#.#.#.#.#...#.....#...#...#.#.....#...#...#.#.#...#...#...#...#...#.#
#.###.#.#.#######.#.###.#####.#.###.#.#.###.#####.###.###.#####.#.#.#.#.#.#.#.#.#####.###.#.#.#####.#####.#####.#.#.#.#.#.#.###.#####.#####.#
#...#.#.#.......#...#.#.#...#.#.#...#.#...#...#.......#...#.....#.#...#...#.#...#...#.#.....#.#.....#.....#...#.#...#...#...#...#...........#
#####.#.#######.#.#.#.#.#.#.#.#.#.###.###.###.###.#####.#####.###.#####.#.#.###.#.#.#.#########.#####.###.#.#.#.#######.###.#.###############
#.....#.#...#...#...#.#.#.#.....#.#.........#...#.#...#.....#.....#.....#.#...#...#.#.#.........#...#.#...#.#...#...#.....#.#.#.............#
#.###.#.#.#.#.###.###.#.#.#####.#.#########.###.#.#.#.###.#.#######.#.###.###.#####.#.#.###########.#.#####.#######.#.#.###.#.#.###########.#
#...#.#.#.#.#.....#...#.#...#...#.........#.#...#...#...#.#.......#.#.....#.#.#.....#...#.....#.....#.......#.....#...#.#...#.......#.......#
#.#.#.#.#.#########.#.#.###.#############.#.#.#########.#.#######.#.#######.#.###############.#.#.###.#######.###.###.#.#.#########.#.#.#.#.#
#.#.#.#.#...........#.#...#.#...#.......#.#.#.#.....#.#.#.......#.....#.........#...........#...#.#.........#...#...#.#...................#.#
#.#.###.#.#######.###.###.#.#.#.#.#####.#.#.#.#.###.#.#.###.#########.#.###.###.#.#.###.###.#####.#.#####.#.###.#.#.#.#########.#.#.#.#.###.#
#.#.....#.#.....#.#.....#.#.#.#...#...#.#.#.#...#...#.#.#...#.......#...#.#...#...#.....#.#.#...#.......#.#.#...#...#.#.........#.#...#.#...#
#.#######.#.###.#.###.#.#.#.#.#####.###.#.#.#.###.###.#.#.###.#####.#####.###.#####.###.#.#.#.#.#####.###.#.#.###.#####.#########.#######.#.#
#...#.....#.#...#...#...#.#...#...#.....#.#.#...#.#.....#...#.#...#.#...#.........#.#.#.....#.#...........#...#.#.......#.......#.....#...#.#
###.#.#####.#.#####.###.#.#######.#.#####.#.#####.#.#####.###.#.###.###.#.#####.###.#.#.###.#.#############.#.#.#########.#####.#####.#.###.#
#.#.#.....#.#.#...#...#.#...#.....#.#.....#.......#...#...#...#.......#.........#...#.#.#.......#.........#...#.....#.....#.#...#.....#...#.#
#.#.#####.#.#.#.#.###.#####.#.#.#.#.#.#.###########.#.#.###.#########.#######.#.#.###.#.#.#.###.#########.#######.#.#.#####.#.###.#######.#.#
#...#...#.#.#...#.#...#...#.#.#.#.#.#.#.#...#.........#.#...#.....#...#.....#...#...#...#.#...#.#...#.......#.....#...#.......#...#.......#.#
#.#.#.#.#.#######.#.###.#.#.#.#.###.#.#.#.#.#######.#.###.###.###.#.###.###.#######.#.###.#.#.#.#.#.#.#####.#.#########.#######.###.###.###.#
#.#...#.#...#...........#.........................#.....#...............#.#.........#.#...#.#.#...#.#...#.#.#...#.....#.#.......#.....#...#.#
#.#.###.###.#.###.###.###.###########.#.#.#######.#.###.###.###.#.#.#.###.###########.#####.#.###.#.#.#.#.#.###.#.#####.#.#######.#######.#.#
#...#...#...#.#.#.#...#.........#...#.#.#.....#.#.....#...#.#...#.#...#.............#.#.....#...#.#.#.#.#.......#.......#.........#.......#.#
###.#.###.###.#.#.#.#.#.#######.#.#.#.#.#####.#.#####.###.#.#.#.#.#######.#####.#.###.#.#.#.###.#.#.###.#######.#####.#####.###.#.#.#######.#
#...#.#.#.....#...#.#...#.....#.#.#...#.#.........#...#.#.#.....................#...#...#...#.#.#.#...#.....#.#.#...#.......#...#.#...#...#.#
#.#.#.#.#.#####.###.#.###.###.#.#.#######.#######.#.###.#.###.#.###.#.#.###.#.###.#.#######.#.#.#####.#.###.#.#.#.#.#######.#.#######.#.#.#.#
#.....#...#...#...#.#.....#...#.#.........#.....#.#.#.#...#.......#...#...#.#...#.#...........#.....#.#...#.#...#.#.......#.#...#...#...#.#.#
#.#.#######.#.#####.#.#.#####.#.#####.#####.###.###.#.#.###.#.###########.#.###.#.#####.###.#.#####.#.###.#.#####.#######.#.#.#.#.#.#####.#.#
#.#.....#...#.#.....#.#.#...#.#.....#.....#.#.#...#.#.#...#...#.......................#...#...#...#.#...................#.#...#.#.#.#.......#
#.###.#.#.###.#.#####.#.#.#.#######.#######.#.###.#.#.###.###.#.#######.#####.###.#.#.###.#.###.#.#.###.#.#.#.#####.###.#.#####.#.#.#.#####.#
#S....#...#.....#.....#...#.................#.......#...........#.............#.....#...#.......#.....................................#.....#
#############################################################################################################################################

107
2024/d17/ex1/ex1.py Executable file
View file

@ -0,0 +1,107 @@
#!/usr/bin/env python
import dataclasses
import enum
import sys
@dataclasses.dataclass
class Registers:
reg_a: int
reg_b: int
reg_c: int
class Instruction(enum.IntEnum):
ADV = 0
BXL = 1
BST = 2
JNZ = 3
BXC = 4
OUT = 5
BDV = 6
CDV = 7
@dataclasses.dataclass
class Computer:
registers: Registers
program: list[int]
ip: int = 0
def _resolve_combo_operand(self, operand: int) -> int:
assert operand != 7 # Sanity check
if 0 <= operand <= 3:
return operand
if operand == 4:
return self.registers.reg_a
if operand == 5:
return self.registers.reg_b
if operand == 6:
return self.registers.reg_c
assert False # Sanity check
# Returns False if the computer is halted
# `output` is an out parameter
def step(self, output: list[int]) -> bool:
# NOTE: also accounting for operand in overflow check here
if (self.ip + 1) >= len(self.program):
return False
instr, literal_operand = (
Instruction(self.program[self.ip]),
self.program[self.ip + 1],
)
combo_operand = self._resolve_combo_operand(literal_operand)
ip_delta = 2
match instr:
case Instruction.ADV:
self.registers.reg_a //= 2**combo_operand
case Instruction.BXL:
self.registers.reg_b ^= literal_operand
case Instruction.BST:
self.registers.reg_b = combo_operand % 8
case Instruction.JNZ:
if self.registers.reg_a != 0:
self.ip = literal_operand
ip_delta = 0
case Instruction.BXC:
self.registers.reg_b ^= self.registers.reg_c
case Instruction.OUT:
output.append(combo_operand % 8)
case Instruction.BDV:
self.registers.reg_b = self.registers.reg_a // 2**combo_operand
case Instruction.CDV:
self.registers.reg_c = self.registers.reg_a // 2**combo_operand
self.ip += ip_delta
return True
def solve(input: str) -> str:
def parse_registers(input: list[str]) -> Registers:
def parse_register(input: str) -> int:
return int(input.split(": ")[1])
return Registers(*map(parse_register, input))
def parse(input: str) -> Computer:
registers, program_str = input.split("\n\n")
program = list(map(int, program_str.removeprefix("Program: ").split(",")))
return Computer(parse_registers(registers.splitlines()), program)
computer = parse(input)
output: list[int] = []
while computer.step(output):
pass
return ",".join(str(n) for n in output)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

5
2024/d17/ex1/input Normal file
View file

@ -0,0 +1,5 @@
Register A: 30886132
Register B: 0
Register C: 0
Program: 2,4,1,1,7,5,0,3,1,4,4,4,5,5,3,0

135
2024/d17/ex2/ex2.py Executable file
View file

@ -0,0 +1,135 @@
#!/usr/bin/env python
import copy
import dataclasses
import enum
import sys
@dataclasses.dataclass
class Registers:
reg_a: int
reg_b: int
reg_c: int
class Instruction(enum.IntEnum):
ADV = 0
BXL = 1
BST = 2
JNZ = 3
BXC = 4
OUT = 5
BDV = 6
CDV = 7
@dataclasses.dataclass
class Computer:
registers: Registers
program: list[int]
ip: int = 0
def _resolve_combo_operand(self, operand: int) -> int:
assert operand != 7 # Sanity check
if 0 <= operand <= 3:
return operand
if operand == 4:
return self.registers.reg_a
if operand == 5:
return self.registers.reg_b
if operand == 6:
return self.registers.reg_c
assert False # Sanity check
# Returns False if the computer is halted
# `output` is an out parameter
def step(self, output: list[int]) -> bool:
# NOTE: also accounting for operand in overflow check here
if (self.ip + 1) >= len(self.program):
return False
instr, literal_operand = (
Instruction(self.program[self.ip]),
self.program[self.ip + 1],
)
combo_operand = self._resolve_combo_operand(literal_operand)
ip_delta = 2
match instr:
case Instruction.ADV:
self.registers.reg_a //= 2**combo_operand
case Instruction.BXL:
self.registers.reg_b ^= literal_operand
case Instruction.BST:
self.registers.reg_b = combo_operand % 8
case Instruction.JNZ:
if self.registers.reg_a != 0:
self.ip = literal_operand
ip_delta = 0
case Instruction.BXC:
self.registers.reg_b ^= self.registers.reg_c
case Instruction.OUT:
output.append(combo_operand % 8)
case Instruction.BDV:
self.registers.reg_b = self.registers.reg_a // 2**combo_operand
case Instruction.CDV:
self.registers.reg_c = self.registers.reg_a // 2**combo_operand
self.ip += ip_delta
return True
def solve(input: str) -> int:
def parse_registers(input: list[str]) -> Registers:
def parse_register(input: str) -> int:
return int(input.split(": ")[1])
return Registers(*map(parse_register, input))
def parse(input: str) -> Computer:
registers, program_str = input.split("\n\n")
program = list(map(int, program_str.removeprefix("Program: ").split(",")))
return Computer(parse_registers(registers.splitlines()), program)
# Rely on the shape of the input, which reads 3 bits of reg_a at a time
def find_quine(computer: Computer) -> int:
def is_quine(a: int, n_outputs: int) -> bool:
if n_outputs == 0:
return True
tmp = copy.deepcopy(computer)
tmp.registers.reg_a = a
output: list[int] = []
while tmp.step(output):
pass
return output[-n_outputs:] == computer.program[-n_outputs:]
def helper(a: int, n_outputs: int) -> int | None:
# If not a quine of the correct length, abandon this candidate
if not is_quine(a, n_outputs):
return None
# If we've found all digits, return the candidate
if n_outputs == len(computer.program):
return a
# Try to find a longer quine, starting from this candidate
for next_a in range(a * 8, a * 8 + 8):
# We found a full quine, guaranteed to be the smallest value
if (res := helper(next_a, n_outputs + 1)) is not None:
return res
return None
res = helper(0, 0)
assert res is not None # Sanity check
return res
computer = parse(input)
return find_quine(computer)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

5
2024/d17/ex2/input Normal file
View file

@ -0,0 +1,5 @@
Register A: 30886132
Register B: 0
Register C: 0
Program: 2,4,1,1,7,5,0,3,1,4,4,4,5,5,3,0

65
2024/d18/ex1/ex1.py Executable file
View file

@ -0,0 +1,65 @@
#!/usr/bin/env python
import heapq
import sys
from typing import Iterator, NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
DIMS = Point(70, 70)
def solve(input: str) -> int:
def parse(input: list[str]) -> list[Point]:
return [Point(*map(int, line.split(","))) for line in input]
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
while len(queue) > 0:
cost, p = heapq.heappop(queue)
if p == end:
return cost
# We must have seen p with a smaller distance before
if p in seen:
continue
# First time encountering p, must be the smallest distance to it
seen.add(p)
# Add all neighbours to be visited
for n in p.neighbours():
if p in blocks:
continue
if not 0 <= p.x <= DIMS.x:
continue
if not 0 <= p.y <= DIMS.y:
continue
heapq.heappush(queue, (cost + 1, n))
assert False # Sanity check
coords = parse(input.splitlines())
return djikstra(Point(0, 0), DIMS, set(coords[:1024]))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

3450
2024/d18/ex1/input Normal file

File diff suppressed because it is too large Load diff

78
2024/d18/ex2/ex2.py Executable file
View file

@ -0,0 +1,78 @@
#!/usr/bin/env python
import heapq
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
DIMS = Point(70, 70)
def solve(input: str) -> str:
def parse(input: list[str]) -> list[Point]:
return [Point(*map(int, line.split(","))) for line in input]
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int | None:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
while len(queue) > 0:
cost, p = heapq.heappop(queue)
if p == end:
return cost
# We must have seen p with a smaller distance before
if p in seen:
continue
# First time encountering p, must be the smallest distance to it
seen.add(p)
# Add all neighbours to be visited
for n in p.neighbours():
if p in blocks:
continue
if not 0 <= p.x <= DIMS.x:
continue
if not 0 <= p.y <= DIMS.y:
continue
heapq.heappush(queue, (cost + 1, n))
return None
def bisect_cutoff(start: Point, end: Point, blocks: list[Point]) -> Point:
# Cutting off the path is monotonic: once cut-off, it's never uncut
low, high = 0, len(blocks)
while low < high:
mid = low + (high - low) // 2
if djikstra(start, end, set(blocks[: mid + 1])) is None:
high = mid
else:
low = mid + 1
return blocks[low]
coords = parse(input.splitlines())
byte = bisect_cutoff(Point(0, 0), DIMS, coords)
return f"{byte.x},{byte.y}"
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

3450
2024/d18/ex2/input Normal file

File diff suppressed because it is too large Load diff

32
2024/d19/ex1/ex1.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import functools
import sys
def solve(input: str) -> int:
def parse(input: str) -> tuple[frozenset[str], list[str]]:
towels, patterns = input.split("\n\n")
return frozenset(towels.split(", ")), patterns.splitlines()
@functools.cache
def is_possible(pattern: str, towels: frozenset[str]) -> bool:
if pattern == "":
return True
return any(
is_possible(pattern.removeprefix(towel), towels)
for towel in towels
if pattern.startswith(towel)
)
towels, patterns = parse(input)
return sum(is_possible(pattern, towels) for pattern in patterns)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

402
2024/d19/ex1/input Normal file
View file

@ -0,0 +1,402 @@
wwubu, guw, uguggg, bgr, rgbrg, bbrb, rwgru, bwgr, uwwbuw, rwrbrgb, ggbrbuur, bb, ugu, grurrr, gbwbwb, rgbrb, bgrwrbu, bgb, wrwu, rwwr, wubr, bug, wu, brwu, w, grbw, uwbgg, gggwrggb, rurgr, uuw, bbw, wbg, bgw, ugw, brb, uww, buww, uuwgr, buu, rrbugw, ggggbgug, wwwrbbr, rgbbr, ugrr, wgwrg, bwuubub, uugg, bbrgg, bbugw, wuuwb, uwr, bugww, rwrrbbr, ugwrrrb, ubbr, rrwbgg, wb, wgr, gbrb, gwgg, rbg, bub, brg, bubr, ugggw, uuugbbb, grbug, rbww, rg, wgwwwwg, wgb, brugbbb, wgrww, bbrgrurg, ruu, brr, grgwg, wurbb, bww, ubwgr, bburwurb, urrrrbb, rgg, wwww, gbgw, rbrb, buw, wur, ruugugb, uwugg, rgrrugub, ggg, ggr, wrurr, bgg, uuru, brbg, rrbb, bbr, gbbu, grug, rwrrug, ggubub, ggrgg, uu, grb, rrrwwbg, ubbg, wgwwrgbr, rbug, rwrgwbrb, wubwgu, rrw, ruw, rbwubwgr, wwugg, bbbu, wgwr, rwgb, ruwg, rrrb, ubw, rwgw, wbr, uwgrb, rbwrrrru, guwbwg, rgbwr, wbu, ubgu, uruug, urbuuruw, rug, wg, gugbw, brw, wgrb, rbwu, wrw, bgggr, rubu, ur, uggrur, ggwbbuwu, gggr, gwu, bbwb, rrru, rubgb, wub, rgb, rbur, wuwbb, rbb, bwb, wwr, wubrwb, bwwwg, wwbwww, ugrrurw, grg, gwuw, uwwww, ubgb, gwr, gwuurgg, grwuu, gbru, rbbrrg, r, rgbrrg, ugrrubr, bw, wwbwbg, brbwbwr, rrrbg, rggb, bgwu, rrgrwwb, wrgrrb, grw, ubu, wgrugw, bbrugug, wubuwrb, gbrr, rrbg, bbg, bgrwg, urwu, uug, gruruwb, bur, rbwrguw, gbbuw, wubbr, gwurrw, rurr, gwrubb, wwwrw, wrwrbbr, ubbru, gbr, rwg, rrgwgr, ugrwwg, wwbgbr, wwubuwu, uwbb, gggbb, bru, uwb, bgru, wgu, gbrgr, urrwb, ub, u, bgrug, rrwr, bguug, gwbb, uuu, brubwg, bwrwbu, ruggur, gggww, rgu, ug, gur, wgurgwb, uuwwb, wbwgr, gbrg, rru, uuwurrr, rbgbw, ubgwgw, wgwbgu, brbwgg, uwwgw, rgww, buuu, uwu, wrgug, gug, rr, gggwb, bgu, grwg, wrwr, uub, gbuwwrwr, bgug, bwg, ubg, urrb, bbgggw, uuurb, ggw, wgrbwrg, bguw, brrrb, gwrbr, brbw, ggrrbu, uru, wrrbg, ubr, ggrr, ww, wwbgwwr, bgrr, wugbrwg, rrrrg, rww, wrbg, ubur, gwb, rgw, bubgbw, gbb, buuuuur, wwu, uubwww, buwg, ugbg, wgrwbub, wurwuu, bbu, wuru, ggu, wguwgr, gbw, gub, grr, rubgw, urrurb, wbubrr, grgwwb, gbwwru, urb, ruuw, urr, gu, bwrbwg, wrr, wru, wug, wbuwwwwg, guugu, brwurrb, brruuw, wuuuu, rbu, gwg, bgwg, rgr, bbrw, bu, gbbg, bbub, bwr, buur, wrgg, wwuurbug, bgbu, ruburubr, bwurbr, rbr, wgw, gwwug, rruu, wubgg, bwwg, wgwbwu, gwrr, wbbrrb, rwbgbbbr, gr, rwuw, rggbur, gbu, uggb, gwgr, guggbuu, gugw, brgww, wuw, rbubgbu, wgwbrb, g, urbb, gb, gbwu, uuug, ggrbbw, wbrrww, wbw, ugb, gbg, ugr, ggwww, rwr, rbrbw, wrg, wwbr, uggu, rrg, gwguuuuu, bbwuur, rgru, bburww, bbbg, wbb, uuugww, bwgg, bgggw, rugbr, wugrbwr, urw, bwu, uur, gggwrw, buwr, rrr, wwb, wgbw, urg, uwgbw, gru, bgbgurw, rwrrgbub, rwrw, buuug, wggbrgw, guu, bruuubw, gw, wuu, rrb, uuuwg, uwbugu, ugbbrr, wr, uw, ruwbw, wwg, ubru, guub, wrrwg, www, bbuuuw, guruub, wwbrwu, rwgbuu, rguruww, bgggrwr, bg, uwuwr, ugwub, ubgbu, ubbur, rub, gww, rw, urrbbbbu, urrbb, wuwu, ubuggww, bbbwg, ubugg, grgb, rwu, rugbug, ugg, wgg, gg, ru, wruw, wrrwuw, rubg, rbw, rwgwr, uuruu, ubb, ggb
uwgwguuguruwggwbrbwurruwgwwwurgbgwggwwbbubgugguuurgugugwu
gwwggrgbwbbguwgbguubbwrbgurgbburrgbwruwgurgwgguwbwgbgrr
rgggbwgwgwuubwbwrrbrrrurwuwurgubuwrbwrbbbbr
rguruururrwbbrgrbgrbwggrubbggbrbrugrgugggurubrbuuw
rruggbrruruggubguwrubwbwuwgrwrguuurbrrbbbggbrwg
wbwurbbrggubugbrgrrbuuwubwurrwururgbgbwurubbuuwbuw
brbwrrruwrrrubrwuugrbuuwuuwrwrbrrgububwurugbwwrb
rbbbuurubwubbuguggrgwgwgurburugugwbgbuwbwwrrgugg
wrbbugrwgwubgugwrruggwwggurrwuugrwrwbrwgrww
gbwbugwgrubbbbburrbwugbwuugrbbwrrwbgrwubgwgbbb
urgrwbruurbbururwrwwbbubgwbwurbwguguwgrbrgugugwrburb
wubuubwggrgwgbgububrwgwbbubgwgbwwwuubrbbbuwbr
wrrrrurbwubwuuggwguuwwwububrwrruwurrbbbuubggwgrgwugwu
brurwwrbbuwgugbruurgrrgbuuwrbwrugurrwrurrrbbwrwbrrgrwuwg
urgwuwwbwwrbbwbwgwgrrbrwgubbrbgwububbwurggbrgrggbrggrrrwgg
uugwrbwguuwwgbwwwburburbwburwgwguwggwggwbbbuburrubgbbguugg
wbwbguuuuubwwbwgrwbwgguguwgbbggwwwurgrwgrgbgggurbuwugwrbu
uubwuwuuwggbbruwuwbwbgwbwrrguwurubbguwwgbug
bwwgwwubbrrrrwuubwbwrruurrwwwwggbgbrwububwwurbggwuwbgu
bruwgrwwbrwbgruubwbbbugwrbbgwguuwguurbrwrb
grbgwuwwrbgrwgrwurrwbbuwwwwwbrbburrbrwbuggrgwbwrb
wgggrubbbwwgwgggwruururugbrguburrwuwwurgggubrbwwgrwrb
wurbwrwwugrgrgruruuggbbggubwrurbrgrbwwrbrrw
uubuwwurrrrurubbbrrugugubgbruubbrwbuwugrwwgwrrbrwggwrb
ggbuwrwwwbbrgruugrrbrbuurwgurwgubrggguwbubrrbbwgwrb
ugwgurwrwwbrrbwrrrruwbgrwrurrrrrgugurwbuuubbubwwbgrrrbwrb
urwrbbrbwgurbuwrgrurgwggubbwubuggrgbuwgurbbwwbbwwubwrurgrw
bbugbwrwrrrwbgugbgguuwwbrwbbwgurubrgugrgwurrbb
uburggbrbuurrbbggububwbuuubgwrruugbrrbuuwb
rrwuwubggwrwruwrgrrwrwubwwrbbbuggbrggurubwubwbuggwu
rwwuuubguwgwuwgwwwggwbwrubbrguuubrurbwuggubwbruwrb
ruugbuurwwwwrwuwurrrbrubugubwrwwwgbwbrbgbwb
wrurbuuruwrbwgrbgbbwgwrwrrrwgwrurbrbuwrwwgbgwgrwgu
bbruguugubrrgrgurwwggwurwbgwbwbbuugwwrbwubwgrwrb
bbwgrrugwgrbgwbbugugwuubrbrbrbbrrrggurgbbwwuwrbbuwbgw
rbgbwburggggrbwubbrrrrggbuwbguggrrbuwbgugbbrgwrb
ubgwuwbbgbubrgbububwuwbbbburwurbwbbuburwrb
bbgubwgruwbuwbwrwrurbrbrubuwbgrugwbbggbwgrwrburguggwwg
uwuubwuwgbuurbugubbgguburbugugrrwbrrurgwrwgrgbb
wwuuugrwuwurbgwwbrbwguwugbgrbgwwbgrgbubrrgrbbgwrggwgrwgruu
bbbwurgwwbwurwubbugrwbwbgbwrbwrwububbgbgurwwruwrwrrggrugr
bubuwbbwrgrwuggbgrgwbbwruubggubuwguwgrbrrguwgwubbbbubugw
wbwbguwgbrgwgwrrurwwrrrgbrwubrgwbwguwbwwuwgugwgrbbubgru
bwbrbwbrbubbwwbgwwuwgwwgggrrgwbubbubwwwugrgwgr
wgwwwwurwubuugruwbrrguwgubwwbuuwruugbwrubr
rgbbbwrgburwuwwbwubwruubgguwbrbwbwrwurbggbwbrugwgrubrgbbur
gguwwggubgrgrgrwuubruuurubrbrruwgrrwrwuwgrwwburwuwrg
uwbgrrwbbggrwwgguwbbgbbrugruugbgrbuwgbugwrb
guurgurbwbbrugrbuugbgruwgburwrwwrbgbrrrgbwbuwrb
uuwuggwrwgbgbuguruwrgbrbrubgrgugwbrugwrgubbrwuwrb
rwgguuubwrbbrbubbgwwgrgbbrrrgggbururgwgbwgugwgbgbrbbb
grwwrwbbruwubgbwuuubwgubguruugubbwggrgurrbwurgubbggwb
bwuwbggbwbgwbruuggruurrwrwgubbwrrubrwwbgubguwrb
rbwbbrgrwgbgwgbwrrurgbrwgwurrwbrwwuwrgugrbgrugrgubbwrb
wbbgwgbwrubuwgurwbwbugwguwwwgbuwgruguwbgbgbuubwuwgwubgrbww
uwwbwrbubgbwwuwwubbgbgubwwwgwugrgugrwwwgwbubrguggbrgrbrgg
wbwuwgrwwguwgurwwurwubgwuwugrbbggbrruuwbgurrru
gbugwgrurugwrrggbrbubrugggwggbubwbwrubububgbwrgwuurugwrb
gugrgwugubwuwbbbuurrwwrubbwwwguguwwbbruuugbrwwwuwuw
rwbbgbugrgburrggrgwgubggwwruuggubururggrbwrb
rgggggrbbrgrrugwwwgwbwbbrrbrburbwbwwrrgrbuugrruwbbuwrb
ubbuurgrwwwuwbwwbgguurbbbgwbuugwgwuggrrbugguruwwrgbgggbbuwrb
bwuruwwubgubbggrruwgbbgggwrruubgurbrbuuubrgbwub
rbubbggrbwbgwwrrbbggubwwurwgrgwubgrgrrbwrb
gwwbgwubrububgwrurwgurbbuuubwugggbrrwuuwru
wguggrbbbwgrbrwwggrurwbggwgbrgggrwggugbrgwgg
uuguuwwrguwrrggugbwwgwuwrguwbguwuurbwbwrggwguwrubwrb
ruuubbgrgrrrgbbrbgbrbubgbubwguububuugubgrugbgrgwrgwrwruggw
ruurrbwrbgubbuwggguwbwububrbwgrubbwgugwrb
bbgbugbrubwggbrrwwuwrwwwwrwbgbbggrrwbguwrbwrb
brbugwrwrbwwwguwrgrrrggugwwruwburugurrgrurbguwguwwbrubu
wbwubgbubwwgrrggrbbgwruwrrugwwrwuuggbuuwburbrugbguwrwrb
uugbuuwwburgbgruuruguuuwrbwurwggbbwrrbgrurbwub
grrwguwurwwuwgguuugurwrgurrwgrgugrurururwrb
wwrbuwwwwrbbgwgwbgrurburbbwbgwuugbuwuuwwuuwbbuww
gggrbrwrugrrurwugwgbgugrruwrrruurbwuubbuuruuub
rwuguwurugbrububbrggrwrwururwuwuwbrwwgurwgrrrrbrururrwbgbwrb
rwbbgrbbwgbrbbgugggwwububugrbrgwgubbggwgrgrbrrbrgwwuwg
wururwgrruuwrgrrrwbruubuuwgbrrwbgrrbbbgugbgrrguugwg
uruwurbgrwrgwbrbbggwwbgwbgwrbrgrrugwbwrwwbggbrgrugwrb
wrubuwbugurguuurugburubbrgrurgwugwwbbwuwrb
bwrwgbwwbuuwbwgbwbbbrbwgwrugbubbgubuwrrwguurgrurwwwbwrb
rrwuuwbruwugwguurgubwrgwgwgburbrwwwgbubwrwrgggrwugurbrrbu
rrwgrgwwubwgwbrubwurbbrgbuguwbuggbrwrururrubbwburw
uubrgrrbgguggwrbwbwwwguwugugbbuubgugrrbugbruggrwubu
uwrrubgbrrgrbgrrrgbrwgwgrwbwgugguwwwgruwbuwwrb
wbgubgrbrrrwbgrbrwrggugruuguugubbwrrwugbbrubrrbuubbwrbwrgw
gubggguubrrguwrwurubwwubbugrwugwugguugguugbuwwwwubgwgbwwuu
gwguwggwgwbrugwbgbgruwbrwgbgrwbgubbbgwgwbggrw
wwwburgwwurgubugwrubrggbgbrrbgbwgggwrggbwbbbbubrbuuw
gggggubgburbgrguurbruuruguwubrrrbruruuguwwwgggu
bggruubuugbbubugwrrbuuwrguggrwrwurubgbwwwbuuuwgubguruw
gwgbrgburrbbgrwgrurguuwrrwgggrbgbbgwbbbwrgggwbrbrgwur
wbbbbrggurwuugbruubrbwgwgurbwuwbrbwrbwgruwrwwgrwurwuruwrb
bbggrguugwrguwbgruwrwbggurbguuuubgrurwbbgurrbgguggubw
uwrrwbwubbgwbuwwuwurgwurbrruruwuwguggrwbwwurwwurgbgu
ubuubuwrgrwugguuubwwgwrruwwbuwggbbwwrrwbrgbuugugwwr
rwwbbugwrwggwwwuwwbgwwrrrbggruruburubrrubggrgwrb
bbgbrwgwrgguwwrubgwbgubuuurbwwbbbbuggbrgbwrb
ubugbuwbrguwwbrgwrgguwwburgbuubwwgbgrbrubgbgr
rubwrrgurbuwbrggwgbgwbggwuwrbuwgbgubrrrgrrwgbbg
ubrbrrgurwbgbbbrrrugbrwwgwugbrgbugugugrbbggrwbgubbbuuub
wuwgububguurguugwuwbuwubgruwbwuwbubuwburbgg
wwrbgwrgwubwrgruuggwbwwbrbggurburgrggubgwrrgrgrgbbrbgwwuuwrb
gbgrrbugugwrrbuwrubwuwwgggwrbwwrugbgbgrgrrruw
bwwgwruwugwrgwwburrwrgwgubbrgurgubrwwrggrggbwwgrguuwww
rbbwurrgrwrbuwruwuwuuwrgugbwrgrgruubwburbrgbrubgrgrwguur
gwwuurbugbgwuggwwwwwbwgrrbbgrgwwbwgrggrwrbugwrwrb
ugwrbrgrggwbwwuubrwubuuwwurbbbbwgggwgurbggw
bbwggbubgwwuurbuguruwwbgggurgwbgrgrggwurrrrurgbrrugrgwgww
uugwuwubrurururbggrrgurwgwgrrgwwgrwurwrwurwgruu
uwgbwurruruwwuwgbbgwwrrwrwbwgrrbwbrwgwbbwubrgruwub
guugbrrubwbrbgwrwwrurrwwgbbgwgwrbuggurgruuwgrub
gbgurwuuwubrrugwrrugwbbbrwbrwuggrwrrugrwbgu
bwguugwwwuruguwrrwwbbuguugbggbwbubbwgwrgbbguguruwguwuru
bbwrbrguwrwbrgruguuggbgrbrruguubbuwwgrbbuwrwwgrbwb
buwbwbbrurrbubrwgrgwwwbgburbruruwbbbubwrbuuwgwwbwu
urgrrrurgwrggugwbrwubgguguuruurubbwrrrwrb
bburwruuwbugrbwruuuwguubrbuwuwbgbgrbubuwbgr
rbgrugguurbrrbbwruuuuwgwrggwwurbbrggwrruuuurgggbrbrbrb
rguwurugbwbwrbbggrgbgrgbwwuwrbbubugrwrgrrrbbbrburgubgurggwrb
gwuwuuwugwgguubruwwrubrurwrgwrbbgruuuubwwurrugwuuugwubg
bgubgwwbrbrwruugbbbbbwrbguwbgwgubgbbgbbgurgrurgggugbbwbr
gruwwbwwgbbwwbwgwgwwubwwbwubwrwrgurwuwgrbbrurgwg
guguwggbbbgbggbrbrgwbgbrwbgrgruurwurbwggbuwug
rbrbbuurgbgbgbgggbrrwuwuwgwbwbwwuwbgubbbbwr
bgbuwugbugrwwwwgrbbgguwbrbwuuwgrgggrrbgwbwgruggggwwubbwrb
ggwuurgbwurbwubbrgbbubgrwguwbrwbrruwgwgbrwgrrurggwub
gggruuubuwrrugggruuguubbrbbgbruubuwrurwbrwggbrgrrburwggw
rrugwrwbrgbbwrgwgbbbrwrgbburubggugrwggrbrbwubrgurgbwrb
grbrubguwruuwggbwugwwgwuwwggubuwuwwrggbrbuurwubwbbwrb
uwbwuwwbbrguburrwrugburgrwuruwugbburubwguugwwru
uuwwrubggwwwuugrgwbwgbbwrrbburuguurbrbwuwwrbggurbbwguuw
ubugbwrguwrrwurwuwbrbbubbbwbgugwgbrbwruwwwrububgur
ggrrburgrgburuwrrubububrrbgruuguuuwwwgwwrgbruub
ggbuugwurgbgrwggurugubwggbbbubrgurrwwburuggrrrgbbbbwg
ggbrgrwuuwwbwbuwwwwgguwbbuwuwuwuwrwgwwubwwuwrb
wrbrgugwrbwrwguggrrggbguwrguuwbwwrrubgbbbuwwrrbrg
gbwbwrgrbwurwuggwwrwwgwrbbwrwwrbrrrrbuwuurrburruu
bgugggbbburbbbrguurbgrugwwgggurugbuubuugubwrwr
wrgbrrrbwwurbgbgbwbuuwbwwbugbgbugrwgwuuubugwrggwwbbbwggwgwrb
wwbwbbrwrbruwrurwurwggwwbrbuugbugbrwgubggrr
brbubbburuwgrbuwwuwrurrwwubrwugwbgburgwrggbwuwrguwgwuu
rwurrbrggrrgbbgbuububrrwbguwrgbwruwgrrruburuurwwrwbuwgbbr
bwggbuggrwuubrrwubuwrgwrbuwwurugrbbguuwrrugbgburggububww
gruuwburbbgbrbwgugwgwuurgububuwugguwuwwrbw
grrbgwbwrbrwgwrwuugwbbgrrggggwuwgwugbbgugwbrugwbwu
rugruggwruburugwugrgwbugwwugwuwrrgrgrggubrgbwgwwwg
urubrbgbgrgwwgwbrgbbwbrruuruuruuururggubwr
burbwguggwrggrwggubuurrgwbgwggwrugwwuubgrbwbgrrbug
wwbwgrrwbwwbrugrbgwgwgrwwggwbrbwbgggguuubwbgbburguggub
urrbbbburgwbwbbwrgubbggrwbbubuwrgggubggwrb
ggugrbggurrbggrwruwgrbrwgwbuurrgrwwwgugurrrbwgbbrbbggwrb
bwgubwruwrgbrbwgbwbbgbwbgrbbruubbuugwburwrb
gwrbbrwugurrbugrbgruwruwrwwguwubwubwbrwgrruggrr
rwgubrrugrwwwubrwwwrbrwwrbgruwgrubbgwgrwrb
brrbwgwgwggugbgrrrrgggubbwwwuururbgbrwugwbrbrbwuuwru
urbrurgrbgguguguuruwurgugwwgrubggbgbwwwgrbugubwggr
rbgruguwrurwbgwgurrwrrrggugrwwbrbrbwgubuwubruubwrurrgwbgbwrb
ggbwuuuwggggrububwwrurgbrbrubbwgbbbgbbbgbwuwwgggbwrbuwrb
rbbbburwggwurrrrbggwgwwrurubwbgbrbruguwwrwrgggrugubw
rgwgwwrgbrgrwgrrbrburwbwuugbgrwwwggrwrbbwrb
ubgrwwwuubwwwwgbbrurbuuruuurrbuwggbbuurgrrwrgwb
wgwwuruurbgwruugrwgrbugrbbwbgwwgguubrwrrbr
bwrwubggwgrrubgrrwuwuuugruuuubuwbrbbwrrbgrwugwgwugrguwrb
rguwgwugururbwwgwwwgwgwbugubbrbrgwrwgguguwbwruwrrrbgbu
wuuuugurbwrgbuugbrrwgggwwwrwrrrrgwrwggwrbb
wwbwbugrwbbuwwwrwrrrubrbgwwwburwgbgbwwbuwrwugguurbg
ubgbuubgrrwruwugwbwbwbwwgbwbuurwwuwbubwrbug
uubgrgrrugubggggwgrbgbrwrwbrgrwbbwgrburrbr
gbwwugwbgggrbguurbrburbwwrugguwbugwwugbuwwbguu
wuwgrgrgwgrbuwgrbgburuuwrbwguuwuruwgbwwubwwbururbw
wwrwgugurwrbbbrwbwubggguuwrwbuurbwbwubggbbuurrwwbubuwrg
bburgruburubrbwrwwwbrgrbuwgwrwggurburubrgwgbbruw
ubrwbwubbbbwbwgruwuuwbrgbuwwuwuurrrwrrrwgb
wwwwrbrrguwugugbgrggrubbrgrurggbgbuwwbrgggwuguwugbrwg
rbrbbuwrubbbugbgwgurggrgbwrrurbburwrwggruwrubgbgwwuuu
wuuugbgwgggburrrrgwbubbbgrubbgburwrbugbbwbwggrgrg
rugwgubuwurrguwbwwurrggrgrurgwbbwbubwwgbgrubruuuwwbu
bgburwubrrwburrbwgwuwwwwurwuuwbgbgrwggubuwubwwggrwrb
uurbururruggwrwuwbguwwwbbwrbbwrggwrgbwwugwrwuwrw
bburugbugwwwwggggwruwwggrwwrbrrbwgbbbuwgwgbwwwubgrgbwrw
rgggubrrbgugguwwuuwurgubgwrbuwubwburwuubrgb
rwrgwbrbbwrbuwwuurgwuwwbrbrwuububrgubbrbwrguruuub
uuugrguwruwwuwuuwgbbrrwwgruuwbbgwguwwruuwrb
bubbubgwwuurgwrbuuurrwrwwrurwgbwugguwgbbggggww
uwruwuguubrrbbggbgrbwrwwwbwwwggggruuuguuugbwrwwrgw
gururwuubwbbugububgwugbugguwuwgwrugbrwrwrb
wrrbwuuwbwbubgwrruwgguwgrbggubrgbgugrrgrubwwwbwbr
rbgwbgwububrrrwbuwwwwgrurwrbwrgurwruggguggurrrubbbwrwgww
wggbrggbrrgbrrgrggwbbwurbbrgugugrbrgrwwbrgubwrwuuruubwugwrb
rrgbggurbrwuwrgrbbwwubguwgurugurwurwbgwrrbbwwuwwbg
wbbggrwrgruwgrbrgburwggrrbbbguurgubbuwbruwwrggrbr
wubugrwrrwuuugwuubgrubbbbgurguwgrwgruwwruguburwuwu
wbwuggubbrwugwbwrrwurgubuurrrubrgwbruugrgbrrbrugbwrruwuubwrb
rrbuwruwguburwgugrwgwuguwuubgurggrbuugbuwrb
wrrbuwggurrggwubgwwuggbwuuwwurrrwwrwurrburgwbwugrgbuwwrwrb
grrurwggwgruwrrbbwuugrwgrgggbrgubggbugugrwrb
wwwrwbuuwgbugbwurrgwuwbuuwrbuurugurwbuuuburrurwrb
ruruggbgwbggrwwrwrbrrgwuguwwrwurrguwugurbbruwbrwuu
uwuuggwurgbwrrrbruwrrwrurgrwrbrwugrwbbburwurbwbru
rrbwuwgrwuugwguugbrwgubrbubgguwrugrwbwrrbggbgrrrugrbbgr
rgggrbugbubburuwwbrrrbuubrrwubuuuwgbgguuuurrubrwwuwwugrbwrb
urrgwwwrgwrrgurrgwbbrggwrgubwgwwwugruuubuuwggbuur
gbuguuwwrbggrwrrubwwgrbwrurugrwrguuuugwgwrrrgubgbwb
gwugrrwrgubuwggwrrguubugwrbururwgbwgbbugwwwrb
bruuwuwbgrbrwbwwubrbbwrgwubgggwugbuwgbrwbbwruubgwbbrwwwubg
wwgurbbbbbwbwwrwguwbrururbwurgbgwurrurbgur
wwrgwuurruwuwugbbrwbwrbbbuwgwwububrwwgggbguwrgwrwrrub
gugwrrrwugugruuwrguwbwwubbggrwbgbwrugbuwrb
rgubwgbggwbbwggwgggrrrgggbuwwrgrwggggrrgwr
gbgrbggbgggggbgugwgubggwrwwwrwgrbrguwuwgwrbbrbuwwgrwuwrb
wwbgrrggrbgrbwbrrrbwrwrwbwrbrrwbwuugggwrb
wbbwbwbgrbwwwuguubbwgugrugbbrbbggrwwurururwggw
uguwrggruugrgwwuubbrbbbgbbgugurruwruwbugwrugubwwbgbwg
ruwbwbrubggruwbrwrurbrrrbgrrwrrgbubbrwrwurwuubwbrruburwuwrb
ugrrbgbbugruruwbgbbbgwbuwgbwugurbrwbgurggbubwwrbb
wbbwrwrwgurubwgbrgwgrgggrguruubburrubwugggrrwgbbrugw
uugwubrgwuuwbrrrbgruuwruwwbuuubgwuwwwuwbruguuuwgrbrwrb
gugubrrggwbuugubrbgwgbubwwgrrurubwwrbbwbrgrr
wrggwguuguuwbgburwwgwgwbruwrgrrwuwwrgbgugurwggbbg
wwuugbgggubwwwgrgrbguguwgwwwgbuwgbugwgwwguwrug
uwuurugbwgbrrbgbbuuwuggbrbrwubwbrggwbgrubbrrggbuubu
gwggubgwgubguwrbggbwwgbuurbbuubuwwugbubwbgbbruu
bbubugbuwwgbgubrbrguwggbbugggbuwuubbwgrwgwg
rrrrwugwuurrrbggrbwbrbrugbrbubugrbubbrguwwwwwrrgwgbuugbu
wrurguruugbwrwbgguggbwruwgbbwgguurwbgubwruuwru
rwbbwbrbwuwrubgbgwrbbuwbgubrgbwrrwwuwgbrwgurgubburuug
ggwubrwwuggrrwbuuubwwgbbgwurwgrgwwuwubbrgruurugwuguggurg
bbrugurbrurbgrbubwurrubbrbbgugwbbbwuuuwrb
wwgwwbruuuruwggbbwuuuubgwbubrbgwbwwuruuguw
gburwbwbgrbwbgrugbuwubgrrbrrggbuwwrwrwbguuuu
uwuwgrbggbrwgwggwwgbrrwburuuguwbbwwwrgurbgurrwgwurguwrbwu
rbwrbuwrwgbbwwggrbwbwwggrwguwggbwrgbrrubgubgugwbrruwwrb
bbuggbgbwgwrrrggbubrggrurugubuwbwuguwbugrrggwuwbwrggbwb
ugggrbwgwuubwwggggwuwwwruuugrrguwwbwubrrwugwrrurwgbg
bwgrgbubgbuurggguubwwrwgbubgrrgrgugwrguwruwbrbwrwbbwbbbb
wrrrbgrbggruggbbuwwuubrruwgbuuubgwbguurrubbubb
rbwrrrrubruuwgrgrbgwwwurwurgwbugrbbwwgggugbu
ugbggrgrguwwwggbruuruubwwgbwuggwbrwbwwbrbwubrubgbrrgwuwrwrb
rwrbrubwbburrurbuwgrrrgurwgrwbrgwgwwrbwgbrwr
wbwrbruubggrgwbbrbgrbuwwrrrbwwburwgwguubuwguwbrgubbwrbrbwrb
rgrrbwrgwbbuuuruuwbrubbbuburguuburrbgrwbgruwru
gwrgrrbubrwgurwgruwguurgruruubgubguggbbwwrb
wgbbuwurburbwwurgbgbwgggruggwurbwuwbubrwrrwbburbgrwgug
ubugbggwuwguwwwuwugwbwgwwuuuggrrrrubwwubwbwrwrrugwbwrgwuu
rubggguguuwgbuwggrruwrwrgruruguurrubwuwrgruwwgrrurbwuw
wurbburwrubbwbwrruwrbrbuuugurbwuwwgrbrbggwwbgugubrrg
gugruugwruwuwrugbgurguguuwwbbrwrurrgubwbwbrgbwrb
wugrbrbgwbbuuwrrgrbwgwrruuuubrbruwggurgbrg
rurwugugguurgubwbuuuurrrwbrrurbwruurwugrubrgubwrub
rubgwwrrwwwgguuggbwuruwwggbrubwbrwgubrrgrwwbuwggbbburwurbwrb
wbbbggwuwbwwgguruwguwbugwgruwwrwrgggurwwuwbbwubgu
bgbwbbwruuugugbrwburuwwrwbbbuggugbwubrrwgwugbwguguuuwru
rbrwwwwwgbruwguuuuubruuurgbuubrwbrbrwurgburbub
grruruwbrwwrbgrgbgrwuwrgwwuwbbwgrrrrrrrrrggbbbwbbbbu
urrwbbbrwuggrggbgububbrbubuwggwuugwurbbbwbbrwrb
rwwubggwrrbuurwwrrruuuruwggggwbbuwurrurugg
bgrbrruwrrgrwbwruwbwbguugbrrggrbgububwbuubrububggugg
rwruuwbuwruuwrrwgbwwrbwwwbwwrwwuuggbggwbbrbbbwwg
rrgwrgwubgwrwugbuurgruburburuwwwbwwwwrgwwrgwrgrgg
wgwrrgwwurrrubwgwrgbrbwgbbubrrrgugwwguubuwrbbb
gurggwuurwwurwrggugwugrbwubggwwwugrbubwrubbuw
uruuwurrggwbgrugrrbbubwbwwggbuuugwgrwbuuuugrrwbr
wbbguguuwuubwwrbrbbrugwrwuuwgrggbbwurrubrrgwwrb
rruuugbgbgrrwwrwgrbugburbubuuggurguugbwgggwrwwbubb
brbgwwbgrugurrgurbbwbrwubbrbrrwugwrwugrwwrb
buurubwuubrwbugwbbrrgwbgubrggubwurggwbrwwrrurubwrgrrg
wbrbrrrgrrbwubwgrwubgrgrwuubbgwwwugbwruwugwwgubww
uwrgbrubwbuubuurrrbwuguwbggurbubuwgwbwrggbggbwruwuggguwbw
gwbwgbwbgrwbgbbbrwwggbgrurgrwguwgrbruuwbugwrbuwwbwrb
guwbwbrwgbgrrrbbrbruwwbbuwwggbwrrbuubugwbrwrb
wrubrurubbbuguurrbguugwurwuuuwgubrwbbgguwwbbbwwwrbwgwuwgr
rurgbrrbwwbgwbubuggwugrubbgwwwrubuuwbgwgbgwugrrugrub
rwugwrwwbuggwbugbbwrbwwruggbgrwuugruurgrbwwbuwwurubgbr
bwbwuuubbgurgrgrbggrubuuwrugwgwuwggwrggbrbwubwgwguwwrb
urrgurwuwwggrubgrrwrugbbgbbbgwrguggrbuggrgrgwrb
wuwurrrrwbwgwwggurwuwbrrgrburggbwgrggbgrbrrggburrggwwrb
ubugrbugubbwgbbbwwgwgwgbguwwbrgbrgwubbwgwwruubgrgrrrb
gurwwrggbbbburwbgububbrwrggbuwgbwrbrrugburgrgbu
ubgbbrrbubrrubbggrbgwbwrbrwubwuurgwbburwwgr
gwbrrgwgubbbbrrubwgrguguggwwrbggrwrwuuururwrwguwgrbuwbuuwrb
ggbubbbbwruuggrwwuuwbbwubgbururrggrbbwgwrb
rgbbrgrwgrruwrwbuurgugbrububrugbgwruwbrurbrwwuwbbrgbbrugr
urruuurggrwgugbgrwgubrbbbbwuwrrwgrubrurgrbuwrgwu
bbwwwwrbbuwubgrrgurbbruwrbrwguwrbwrurwwwbbuwgruubwwwrb
rbrggubbuwguwbggbrrbbwrrurrrbuuuggugububbbbwrrwb
ugwgwwwrwruugwrwrbuggwuuwgbubwgrbrwwgrggrrgrbrbgbbwgwrb
ggugburbbrgrrwgwbwbwruuwugrbrrrurgwrbrrbrwubr
ububbrggggrbruugrubrwrbgbwggwrbrwubggubgggrrgbubrrgrwrb
rrgwwwrugrurwuggggwrbbwugwwwwububgbrbguwwwguwguwrb
uuwwwrbgrrbwgwuwrwwwgwwwrbbrbuggwwuguurwgwrb
gurrrubbgwubwuggrrwwbbubbrgbgubruwrgubggrwgrburrrrg
uwugubuuwurruwruubgbgbwwggbrwgwgrbbuwugwrb
wwwrbwrbwwgbrbrwbrggrgwrurrbrbwuruuburbubguwwugggrbwgwgb
wbgugurgwrrbbwugwbrwuwrwruruwrrugrruugwuggggw
rwbrwwgrgwwgrwgwbgwrwrwguubuwwbguwggubwggwwbww
rggrruwggwrrgggbrruwrgbuggbbgbwbwgurwrugwbgwwwr
gbbwrgwwrwgguurbggrbgbwggbbbuuwururrgrgwgbgg
wbgruwwwubrbugwbuwuubwgrubguwgwbrubrgwwwgwbgwwrrugbgbub
ugbwugubwgwbuggrurguwwubwrrurrbrgurrbrubwuwrwwwwwgwwgrwwbw
wrwubuguggbrrbugwbwwwrguuuguubwuruugwbgwbguurgwwbggrwwbuwrb
uuugbgrgwrugwguuuuurwgggrburwwgbwrurwbgrrwrb
wbgwguuwbbuwggubrrwbgrgbwuwrgbubruwggbrrubbwg
ubuwbrwbbbwbguuwgugrbuwwrgugwubgrburbgbbrrgrubbbbbu
ugbubrurbgwgwwgrurbwugbwwwbbgbugbbbuggrwgrbugbgwwbuwrbuwrb
wgrwwuugurbgrrgwwbwrubrgrrwwubgbuggwbbuwubu
gbuwrwbrrrwrwbwwrgbugrbugbrurrgggrgwgwgrrbgubrr
wugbuggubuggbrggubwgggbgbgbgurrgwwbrwwwwrb
grgugwubbugurgbguwbgbrugwbugbrrwubwrwuwrgbrugrgwrwrb
guruwwrurwurwugbbrbwwwwubuwrwuuwwugwruwbggbbb
bguruwbbggggbgugrbgrrrgubbbrubwrrwrwubrwgrurw
wbbrbbrgbbgguwbruuguwbbbrbrgrubgugwrgbrrgrwruguwrb
wgrbrgbrgwurggggurwwwggubbggrrrgrubugwuggb
bbwuwwrwrrubruuggwwbrurbgwururwggwwrrrurrww
ubwuugrgwuuuwururbrguurgrbwwwrrwbwruwrgwururbugrwrru
rgbbrwbbguggwbrwwbbgrburwbbwwgbrbwbbubwwrb
uuwuuubgurwwggwwbbbgbgbwbrrgbrrwrbbuwwwgubgggbbrwbrr
gbuurwggrrggbbrgbuuwrgrggrwgwwrwugugwbgwwbrr
bwbrgwbrgwwubrgubbbuwbrubwrbgbrrbbbbwrwbgwguuuuubrgrgrw
guwguururgwuwuuwgwbruguwbbubuwbrggwwugrwruruuugrwrb
grgwuuwrbbgrrgggbwrugbgwbbbrwuuwuwgbwugwruurrrbbuggrwwwru
buwggggwrrrruburwbrugrwrrgwuguwggwbwbgugrgugwwurbbburrggw
ugrwgbbwwwbbgruubgguuruuuururwwbuugbgwwrgubrrbuwwugggw
wbrbbugwgburbgrbgrurrbwwwrbwbwubbgrurrurwwrrbwgbugugw
ugugwbwwgrrgrgbuubwrwbrrurrgbubggwrgbugwrgbggubbruubgw
bwwubbgwwrrwruuruguugugrwgwubbguburuurwguwbwrwrb
brrbwugubgwrgurrrgrbbrwrurugrugwuggwrgrbrwggwbbuwurrwwruwrb
rwbbrbgwgbwguwgbgwurgrbuurugrrgwuwuurubrbgr
uwwbuuwgbwgggwrububuugrwurgggwgbwbubuurgbwrrwbbrwuruwrrrb
bbgwbwrrruurwwugbggbbguggguurrbbbbuubbwbwrwbrwurrbuwgrb
gwgwbwgguwwrwugugwuuwurwgwgbuwgbgbwwuurwwggrubb
rgburwwwuurrgbuwrgwrbugwwgguwwwgbubuuggrwbgubrwrgwugwbuwb
gurrbwgburruggbrbuguugbguruwurbuugbrgbguguuuubwggrwgrrwbwwrb
ruggwuwgbgguwwuburgruwrbgbubbwwugrbwuwwbrbrrwbg
wwbrrgguwbbguubbuuuuugwbbrwrrgrruwrgwwrbbbbwgrgw
bwbrwbwwrwwuugugugbrbrbrrbwrwrruguwuwwubbugwgurrr
wggrwwubuwruwgugrguggugwbbggugruuggrwbggrwbbw
gbgubgbwgurbwrrrgbuwwguwrrwwbwuwuwbgburrbgwbgwr
grrububuwruwrubrgwwbrrgrbwugrggwbrgbwwrb
uguuggrrwubrgrwggububbwgbbwgrwurwwwgwbubbbruggrwbrbgwrb
brgurrbwwugubrrgurrbbrbuubbwwwwguwwgrwwugubgruruu
wrwubrrwburuwbrgwwuggurwrrwbbruruuwuwuwubbubuuu
bwbugbrrbwugbwrubuwbuwwubbbguwbrgwwurbgugrgrwgwuwwbwubgwrwrb
bwguwgurgurrrbgbbbwbrrrwuwbrwubruuwrbwrb
rbubgwbubuwwbubbrgwwgubgwwrrgbubrwbbrwwrbwwuwgbbwrb
wrbbgwburwwwrgwggggrrbubbggrbgbggwurwruburwubrubrgr
rggurrwwgururrgrwwwgrugwwbguurbbwbuwrwurrrbrggbbbbrwwr
ugwwgwrgrgugrbbbbubrwrubrbguwbrwubgrwgrrgbgggwugw
uwgrgbugbwbbggrgrbbgrwrbggrrwbbwbugwrwbrrwwuuwrb
bguubugwggwguuggbguuwbgwbwruggwrbgbrrbwbrrbgwrbggwrbrrbu
rgwwbubbbbuugubwbrwuwwrrruuwggrbbrbwguwruuubgbwwgwurbgbubg
uuwbwbrwwubbrwuuuwuwwgggwwubburgwgwbrurrwbrbgbbburwgb
wwrrbbwwbruwbgbggbrbbgrugubggwgggugrbuurgrbbgbuwu
ugrbwbwwgggwrgbbguugrgggwrggbuuwuwubrgbruwbwrb
ubggwbwguugbbubbgbbguubwuubrbwubrubrwguwwwrb
rugburrbwruuwrwwgwrwggrubgwbuuubugbwuurgbg
ggrwrruwggbubrurubgwrbwrgbwgwuwrbbbwbuugwubrubwuwbrbgbgubg
grgwugwuwbgwuuwuugrgwwguwbburuubbbgubbuwgwg
ruwrwrwwrwgwwrgbubgbrbrwwbgurrwrrgbruuwgrgrrrgurugugu
brbwrgurrwgwrruwubrwwwrggbuururgrguwggwbbgrgubrw
bbuwggrbugbbgbguugwuuwuubgwgbbrgugbgbwbrubbbgugwrgrgrgruuwrb
wgbgbubuwrurbuuwgrugwrgrbrwrgwuwbbgwrrrrwrb
wgwrgbbbuurubgwwrgwguururrubgbgwrbgwwwwwggggbrurgrr
uwggrggrbrruwuruwbuwurrrwwwwbuggbguwuubwuwbubrrwrb
ugubbwurwurgwwrburwuugrurguuwruwwrwbgruggwbwwwgwbb
ubwgwbbgbrugguwrggubbrgrbgruuwugbgruuwggrbgwugugwugrrwwg
wggrgugugubgrrrbugbbbwrrrwbwguuruugrwwrb
bwgwwbrwbbubgwubrwwwgurbwbrwbubgbwbubwgbbggrrwbbgbwrbbrr
gurwrbbbrbrurbrrbugrrrguurwwbbwugwbubuwrwbrgbgrwrbuuwrbuuw
gwwwwuuubuguwwurubwwrggguwgbrbbbgbububgwrbwbubbruwbb
uwwwbbggwrgbrgrubrurwrgugrbubuwwruugbwbgubugbuguuuuurbrgr
rrbubwbuwrgrrugubbbuuuwwbwgurrwwgwburubwrwrb
rurrbbgurbuuruwuuwrurrwbbggrrrgguwgwrurgrurubwrwwrb
ugbugurrgggrgrbuuwgbuugrrgbuuwugbrwrrgbubbbbburuuuwww
wuwgugruburwguwrwgwbwrbubbrbgwbrgbwruruwbbuwwwugurwgurwrbbb
wugwbruwuggrruggrbgrgubuubgurbrrrruwrguububruubwugwwbbwbu
grubuwwurrbbggwbwwwruuuuubwgwubwuubuuwrrrwgrururbggbbggw
gwgrwbuwuwgwrubbgbugrgwbgrbwbuwgrggbwrrubbuggwbgrwgbggg
uruwrwuwbrbrwwruwgurrugrbwguuubwrwwurubgrbgrgwwur
rguubrwwgubuwwruruwbuggbrburgrgurugwwwwrb
uuubuubggrugbgbgwgbbgburuwggrrggwrwruwgbuwwbrgu
gwgrgugwgbwbuwbgwgbrguuguguugrrgrbuugugbrgu
urgrwwwrgurwwrwwwggbgubbrgwwwruwubgbrgurguurwugrgwrb
rubgwbrwbgrruuwbruwrgwbwbguwururubrgwrurbuubww
brurbguurgbggwbbgwwwugbrbgwrwbrwrrbrwbugwuguwrbwru
rwrbbguggugwwgrbrrwrbgruwrwwuugbrgurbwuguwwubgbgg
wgrgbgbwbbggrwgrbbbrrwubgrbrbgwwururguwugbgrgrrug
gwuurwubwwguggwwbbwwugrwgggwwurrrgrrrburguwwrrb
guggrruwrbrugwrwgrbgurbgbrgwugwwwwbbbwwrwuwug
uwgrrgrbbgwrggrwwwgbgbrbbrbuuburbbrbrugwurugwbburgbb
wwwbbbwbbbrbgubrwbbrubugbrgrrrruuwgurrwwwruwgwrguw
uuubuwgwrwugrbggggbruugbrruwuurubwwgwbwgurbgbuubbgwbuww
wbrrwgbuwggubuggrugbwwbbbbwgwrrbgggrrrwrbgrbgg
gbbbrwwggbugrbrrwrgbuwgbrrrwgwgubrruruurwguwb
rrbbuwrbruwruwurbggburwwbwuuwrurbbwrbuurubggwrb
rrubbuurrrgbrwwuwrbwgruuwbbwugrgubgbwwruwbburgbwb
wrwugbbgrbgurubrwwwwwbbbruubwgrgburbwbrgbwbgwb
wwrwugwbbrubugbrrgrwwbwbuwwwuugbbwguruggwgwrwgwrggwrgrgwgwrb
bguwgugwbgwgubwwbwwrwubrrwubbwgrbwgggwuuwgrbgwgwgrwwggrb

32
2024/d19/ex2/ex2.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import functools
import sys
def solve(input: str) -> int:
def parse(input: str) -> tuple[frozenset[str], list[str]]:
towels, patterns = input.split("\n\n")
return frozenset(towels.split(", ")), patterns.splitlines()
@functools.cache
def count_ways(pattern: str, towels: frozenset[str]) -> int:
if pattern == "":
return 1
return sum(
count_ways(pattern.removeprefix(towel), towels)
for towel in towels
if pattern.startswith(towel)
)
towels, patterns = parse(input)
return sum(count_ways(pattern, towels) for pattern in patterns)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

402
2024/d19/ex2/input Normal file
View file

@ -0,0 +1,402 @@
wwubu, guw, uguggg, bgr, rgbrg, bbrb, rwgru, bwgr, uwwbuw, rwrbrgb, ggbrbuur, bb, ugu, grurrr, gbwbwb, rgbrb, bgrwrbu, bgb, wrwu, rwwr, wubr, bug, wu, brwu, w, grbw, uwbgg, gggwrggb, rurgr, uuw, bbw, wbg, bgw, ugw, brb, uww, buww, uuwgr, buu, rrbugw, ggggbgug, wwwrbbr, rgbbr, ugrr, wgwrg, bwuubub, uugg, bbrgg, bbugw, wuuwb, uwr, bugww, rwrrbbr, ugwrrrb, ubbr, rrwbgg, wb, wgr, gbrb, gwgg, rbg, bub, brg, bubr, ugggw, uuugbbb, grbug, rbww, rg, wgwwwwg, wgb, brugbbb, wgrww, bbrgrurg, ruu, brr, grgwg, wurbb, bww, ubwgr, bburwurb, urrrrbb, rgg, wwww, gbgw, rbrb, buw, wur, ruugugb, uwugg, rgrrugub, ggg, ggr, wrurr, bgg, uuru, brbg, rrbb, bbr, gbbu, grug, rwrrug, ggubub, ggrgg, uu, grb, rrrwwbg, ubbg, wgwwrgbr, rbug, rwrgwbrb, wubwgu, rrw, ruw, rbwubwgr, wwugg, bbbu, wgwr, rwgb, ruwg, rrrb, ubw, rwgw, wbr, uwgrb, rbwrrrru, guwbwg, rgbwr, wbu, ubgu, uruug, urbuuruw, rug, wg, gugbw, brw, wgrb, rbwu, wrw, bgggr, rubu, ur, uggrur, ggwbbuwu, gggr, gwu, bbwb, rrru, rubgb, wub, rgb, rbur, wuwbb, rbb, bwb, wwr, wubrwb, bwwwg, wwbwww, ugrrurw, grg, gwuw, uwwww, ubgb, gwr, gwuurgg, grwuu, gbru, rbbrrg, r, rgbrrg, ugrrubr, bw, wwbwbg, brbwbwr, rrrbg, rggb, bgwu, rrgrwwb, wrgrrb, grw, ubu, wgrugw, bbrugug, wubuwrb, gbrr, rrbg, bbg, bgrwg, urwu, uug, gruruwb, bur, rbwrguw, gbbuw, wubbr, gwurrw, rurr, gwrubb, wwwrw, wrwrbbr, ubbru, gbr, rwg, rrgwgr, ugrwwg, wwbgbr, wwubuwu, uwbb, gggbb, bru, uwb, bgru, wgu, gbrgr, urrwb, ub, u, bgrug, rrwr, bguug, gwbb, uuu, brubwg, bwrwbu, ruggur, gggww, rgu, ug, gur, wgurgwb, uuwwb, wbwgr, gbrg, rru, uuwurrr, rbgbw, ubgwgw, wgwbgu, brbwgg, uwwgw, rgww, buuu, uwu, wrgug, gug, rr, gggwb, bgu, grwg, wrwr, uub, gbuwwrwr, bgug, bwg, ubg, urrb, bbgggw, uuurb, ggw, wgrbwrg, bguw, brrrb, gwrbr, brbw, ggrrbu, uru, wrrbg, ubr, ggrr, ww, wwbgwwr, bgrr, wugbrwg, rrrrg, rww, wrbg, ubur, gwb, rgw, bubgbw, gbb, buuuuur, wwu, uubwww, buwg, ugbg, wgrwbub, wurwuu, bbu, wuru, ggu, wguwgr, gbw, gub, grr, rubgw, urrurb, wbubrr, grgwwb, gbwwru, urb, ruuw, urr, gu, bwrbwg, wrr, wru, wug, wbuwwwwg, guugu, brwurrb, brruuw, wuuuu, rbu, gwg, bgwg, rgr, bbrw, bu, gbbg, bbub, bwr, buur, wrgg, wwuurbug, bgbu, ruburubr, bwurbr, rbr, wgw, gwwug, rruu, wubgg, bwwg, wgwbwu, gwrr, wbbrrb, rwbgbbbr, gr, rwuw, rggbur, gbu, uggb, gwgr, guggbuu, gugw, brgww, wuw, rbubgbu, wgwbrb, g, urbb, gb, gbwu, uuug, ggrbbw, wbrrww, wbw, ugb, gbg, ugr, ggwww, rwr, rbrbw, wrg, wwbr, uggu, rrg, gwguuuuu, bbwuur, rgru, bburww, bbbg, wbb, uuugww, bwgg, bgggw, rugbr, wugrbwr, urw, bwu, uur, gggwrw, buwr, rrr, wwb, wgbw, urg, uwgbw, gru, bgbgurw, rwrrgbub, rwrw, buuug, wggbrgw, guu, bruuubw, gw, wuu, rrb, uuuwg, uwbugu, ugbbrr, wr, uw, ruwbw, wwg, ubru, guub, wrrwg, www, bbuuuw, guruub, wwbrwu, rwgbuu, rguruww, bgggrwr, bg, uwuwr, ugwub, ubgbu, ubbur, rub, gww, rw, urrbbbbu, urrbb, wuwu, ubuggww, bbbwg, ubugg, grgb, rwu, rugbug, ugg, wgg, gg, ru, wruw, wrrwuw, rubg, rbw, rwgwr, uuruu, ubb, ggb
uwgwguuguruwggwbrbwurruwgwwwurgbgwggwwbbubgugguuurgugugwu
gwwggrgbwbbguwgbguubbwrbgurgbburrgbwruwgurgwgguwbwgbgrr
rgggbwgwgwuubwbwrrbrrrurwuwurgubuwrbwrbbbbr
rguruururrwbbrgrbgrbwggrubbggbrbrugrgugggurubrbuuw
rruggbrruruggubguwrubwbwuwgrwrguuurbrrbbbggbrwg
wbwurbbrggubugbrgrrbuuwubwurrwururgbgbwurubbuuwbuw
brbwrrruwrrrubrwuugrbuuwuuwrwrbrrgububwurugbwwrb
rbbbuurubwubbuguggrgwgwgurburugugwbgbuwbwwrrgugg
wrbbugrwgwubgugwrruggwwggurrwuugrwrwbrwgrww
gbwbugwgrubbbbburrbwugbwuugrbbwrrwbgrwubgwgbbb
urgrwbruurbbururwrwwbbubgwbwurbwguguwgrbrgugugwrburb
wubuubwggrgwgbgububrwgwbbubgwgbwwwuubrbbbuwbr
wrrrrurbwubwuuggwguuwwwububrwrruwurrbbbuubggwgrgwugwu
brurwwrbbuwgugbruurgrrgbuuwrbwrugurrwrurrrbbwrwbrrgrwuwg
urgwuwwbwwrbbwbwgwgrrbrwgubbrbgwububbwurggbrgrggbrggrrrwgg
uugwrbwguuwwgbwwwburburbwburwgwguwggwggwbbbuburrubgbbguugg
wbwbguuuuubwwbwgrwbwgguguwgbbggwwwurgrwgrgbgggurbuwugwrbu
uubwuwuuwggbbruwuwbwbgwbwrrguwurubbguwwgbug
bwwgwwubbrrrrwuubwbwrruurrwwwwggbgbrwububwwurbggwuwbgu
bruwgrwwbrwbgruubwbbbugwrbbgwguuwguurbrwrb
grbgwuwwrbgrwgrwurrwbbuwwwwwbrbburrbrwbuggrgwbwrb
wgggrubbbwwgwgggwruururugbrguburrwuwwurgggubrbwwgrwrb
wurbwrwwugrgrgruruuggbbggubwrurbrgrbwwrbrrw
uubuwwurrrrurubbbrrugugubgbruubbrwbuwugrwwgwrrbrwggwrb
ggbuwrwwwbbrgruugrrbrbuurwgurwgubrggguwbubrrbbwgwrb
ugwgurwrwwbrrbwrrrruwbgrwrurrrrrgugurwbuuubbubwwbgrrrbwrb
urwrbbrbwgurbuwrgrurgwggubbwubuggrgbuwgurbbwwbbwwubwrurgrw
bbugbwrwrrrwbgugbgguuwwbrwbbwgurubrgugrgwurrbb
uburggbrbuurrbbggububwbuuubgwrruugbrrbuuwb
rrwuwubggwrwruwrgrrwrwubwwrbbbuggbrggurubwubwbuggwu
rwwuuubguwgwuwgwwwggwbwrubbrguuubrurbwuggubwbruwrb
ruugbuurwwwwrwuwurrrbrubugubwrwwwgbwbrbgbwb
wrurbuuruwrbwgrbgbbwgwrwrrrwgwrurbrbuwrwwgbgwgrwgu
bbruguugubrrgrgurwwggwurwbgwbwbbuugwwrbwubwgrwrb
bbwgrrugwgrbgwbbugugwuubrbrbrbbrrrggurgbbwwuwrbbuwbgw
rbgbwburggggrbwubbrrrrggbuwbguggrrbuwbgugbbrgwrb
ubgwuwbbgbubrgbububwuwbbbburwurbwbbuburwrb
bbgubwgruwbuwbwrwrurbrbrubuwbgrugwbbggbwgrwrburguggwwg
uwuubwuwgbuurbugubbgguburbugugrrwbrrurgwrwgrgbb
wwuuugrwuwurbgwwbrbwguwugbgrbgwwbgrgbubrrgrbbgwrggwgrwgruu
bbbwurgwwbwurwubbugrwbwbgbwrbwrwububbgbgurwwruwrwrrggrugr
bubuwbbwrgrwuggbgrgwbbwruubggubuwguwgrbrrguwgwubbbbubugw
wbwbguwgbrgwgwrrurwwrrrgbrwubrgwbwguwbwwuwgugwgrbbubgru
bwbrbwbrbubbwwbgwwuwgwwgggrrgwbubbubwwwugrgwgr
wgwwwwurwubuugruwbrrguwgubwwbuuwruugbwrubr
rgbbbwrgburwuwwbwubwruubgguwbrbwbwrwurbggbwbrugwgrubrgbbur
gguwwggubgrgrgrwuubruuurubrbrruwgrrwrwuwgrwwburwuwrg
uwbgrrwbbggrwwgguwbbgbbrugruugbgrbuwgbugwrb
guurgurbwbbrugrbuugbgruwgburwrwwrbgbrrrgbwbuwrb
uuwuggwrwgbgbuguruwrgbrbrubgrgugwbrugwrgubbrwuwrb
rwgguuubwrbbrbubbgwwgrgbbrrrgggbururgwgbwgugwgbgbrbbb
grwwrwbbruwubgbwuuubwgubguruugubbwggrgurrbwurgubbggwb
bwuwbggbwbgwbruuggruurrwrwgubbwrrubrwwbgubguwrb
rbwbbrgrwgbgwgbwrrurgbrwgwurrwbrwwuwrgugrbgrugrgubbwrb
wbbgwgbwrubuwgurwbwbugwguwwwgbuwgruguwbgbgbuubwuwgwubgrbww
uwwbwrbubgbwwuwwubbgbgubwwwgwugrgugrwwwgwbubrguggbrgrbrgg
wbwuwgrwwguwgurwwurwubgwuwugrbbggbrruuwbgurrru
gbugwgrurugwrrggbrbubrugggwggbubwbwrubububgbwrgwuurugwrb
gugrgwugubwuwbbbuurrwwrubbwwwguguwwbbruuugbrwwwuwuw
rwbbgbugrgburrggrgwgubggwwruuggubururggrbwrb
rgggggrbbrgrrugwwwgwbwbbrrbrburbwbwwrrgrbuugrruwbbuwrb
ubbuurgrwwwuwbwwbgguurbbbgwbuugwgwuggrrbugguruwwrgbgggbbuwrb
bwuruwwubgubbggrruwgbbgggwrruubgurbrbuuubrgbwub
rbubbggrbwbgwwrrbbggubwwurwgrgwubgrgrrbwrb
gwwbgwubrububgwrurwgurbbuuubwugggbrrwuuwru
wguggrbbbwgrbrwwggrurwbggwgbrgggrwggugbrgwgg
uuguuwwrguwrrggugbwwgwuwrguwbguwuurbwbwrggwguwrubwrb
ruuubbgrgrrrgbbrbgbrbubgbubwguububuugubgrugbgrgwrgwrwruggw
ruurrbwrbgubbuwggguwbwububrbwgrubbwgugwrb
bbgbugbrubwggbrrwwuwrwwwwrwbgbbggrrwbguwrbwrb
brbugwrwrbwwwguwrgrrrggugwwruwburugurrgrurbguwguwwbrubu
wbwubgbubwwgrrggrbbgwruwrrugwwrwuuggbuuwburbrugbguwrwrb
uugbuuwwburgbgruuruguuuwrbwurwggbbwrrbgrurbwub
grrwguwurwwuwgguuugurwrgurrwgrgugrurururwrb
wwrbuwwwwrbbgwgwbgrurburbbwbgwuugbuwuuwwuuwbbuww
gggrbrwrugrrurwugwgbgugrruwrrruurbwuubbuuruuub
rwuguwurugbrububbrggrwrwururwuwuwbrwwgurwgrrrrbrururrwbgbwrb
rwbbgrbbwgbrbbgugggwwububugrbrgwgubbggwgrgrbrrbrgwwuwg
wururwgrruuwrgrrrwbruubuuwgbrrwbgrrbbbgugbgrrguugwg
uruwurbgrwrgwbrbbggwwbgwbgwrbrgrrugwbwrwwbggbrgrugwrb
wrubuwbugurguuurugburubbrgrurgwugwwbbwuwrb
bwrwgbwwbuuwbwgbwbbbrbwgwrugbubbgubuwrrwguurgrurwwwbwrb
rrwuuwbruwugwguurgubwrgwgwgburbrwwwgbubwrwrgggrwugurbrrbu
rrwgrgwwubwgwbrubwurbbrgbuguwbuggbrwrururrubbwburw
uubrgrrbgguggwrbwbwwwguwugugbbuubgugrrbugbruggrwubu
uwrrubgbrrgrbgrrrgbrwgwgrwbwgugguwwwgruwbuwwrb
wbgubgrbrrrwbgrbrwrggugruuguugubbwrrwugbbrubrrbuubbwrbwrgw
gubggguubrrguwrwurubwwubbugrwugwugguugguugbuwwwwubgwgbwwuu
gwguwggwgwbrugwbgbgruwbrwgbgrwbgubbbgwgwbggrw
wwwburgwwurgubugwrubrggbgbrrbgbwgggwrggbwbbbbubrbuuw
gggggubgburbgrguurbruuruguwubrrrbruruuguwwwgggu
bggruubuugbbubugwrrbuuwrguggrwrwurubgbwwwbuuuwgubguruw
gwgbrgburrbbgrwgrurguuwrrwgggrbgbbgwbbbwrgggwbrbrgwur
wbbbbrggurwuugbruubrbwgwgurbwuwbrbwrbwgruwrwwgrwurwuruwrb
bbggrguugwrguwbgruwrwbggurbguuuubgrurwbbgurrbgguggubw
uwrrwbwubbgwbuwwuwurgwurbrruruwuwguggrwbwwurwwurgbgu
ubuubuwrgrwugguuubwwgwrruwwbuwggbbwwrrwbrgbuugugwwr
rwwbbugwrwggwwwuwwbgwwrrrbggruruburubrrubggrgwrb
bbgbrwgwrgguwwrubgwbgubuuurbwwbbbbuggbrgbwrb
ubugbuwbrguwwbrgwrgguwwburgbuubwwgbgrbrubgbgr
rubwrrgurbuwbrggwgbgwbggwuwrbuwgbgubrrrgrrwgbbg
ubrbrrgurwbgbbbrrrugbrwwgwugbrgbugugugrbbggrwbgubbbuuub
wuwgububguurguugwuwbuwubgruwbwuwbubuwburbgg
wwrbgwrgwubwrgruuggwbwwbrbggurburgrggubgwrrgrgrgbbrbgwwuuwrb
gbgrrbugugwrrbuwrubwuwwgggwrbwwrugbgbgrgrrruw
bwwgwruwugwrgwwburrwrgwgubbrgurgubrwwrggrggbwwgrguuwww
rbbwurrgrwrbuwruwuwuuwrgugbwrgrgruubwburbrgbrubgrgrwguur
gwwuurbugbgwuggwwwwwbwgrrbbgrgwwbwgrggrwrbugwrwrb
ugwrbrgrggwbwwuubrwubuuwwurbbbbwgggwgurbggw
bbwggbubgwwuurbuguruwwbgggurgwbgrgrggwurrrrurgbrrugrgwgww
uugwuwubrurururbggrrgurwgwgrrgwwgrwurwrwurwgruu
uwgbwurruruwwuwgbbgwwrrwrwbwgrrbwbrwgwbbwubrgruwub
guugbrrubwbrbgwrwwrurrwwgbbgwgwrbuggurgruuwgrub
gbgurwuuwubrrugwrrugwbbbrwbrwuggrwrrugrwbgu
bwguugwwwuruguwrrwwbbuguugbggbwbubbwgwrgbbguguruwguwuru
bbwrbrguwrwbrgruguuggbgrbrruguubbuwwgrbbuwrwwgrbwb
buwbwbbrurrbubrwgrgwwwbgburbruruwbbbubwrbuuwgwwbwu
urgrrrurgwrggugwbrwubgguguuruurubbwrrrwrb
bburwruuwbugrbwruuuwguubrbuwuwbgbgrbubuwbgr
rbgrugguurbrrbbwruuuuwgwrggwwurbbrggwrruuuurgggbrbrbrb
rguwurugbwbwrbbggrgbgrgbwwuwrbbubugrwrgrrrbbbrburgubgurggwrb
gwuwuuwugwgguubruwwrubrurwrgwrbbgruuuubwwurrugwuuugwubg
bgubgwwbrbrwruugbbbbbwrbguwbgwgubgbbgbbgurgrurgggugbbwbr
gruwwbwwgbbwwbwgwgwwubwwbwubwrwrgurwuwgrbbrurgwg
guguwggbbbgbggbrbrgwbgbrwbgrgruurwurbwggbuwug
rbrbbuurgbgbgbgggbrrwuwuwgwbwbwwuwbgubbbbwr
bgbuwugbugrwwwwgrbbgguwbrbwuuwgrgggrrbgwbwgruggggwwubbwrb
ggwuurgbwurbwubbrgbbubgrwguwbrwbrruwgwgbrwgrrurggwub
gggruuubuwrrugggruuguubbrbbgbruubuwrurwbrwggbrgrrburwggw
rrugwrwbrgbbwrgwgbbbrwrgbburubggugrwggrbrbwubrgurgbwrb
grbrubguwruuwggbwugwwgwuwwggubuwuwwrggbrbuurwubwbbwrb
uwbwuwwbbrguburrwrugburgrwuruwugbburubwguugwwru
uuwwrubggwwwuugrgwbwgbbwrrbburuguurbrbwuwwrbggurbbwguuw
ubugbwrguwrrwurwuwbrbbubbbwbgugwgbrbwruwwwrububgur
ggrrburgrgburuwrrubububrrbgruuguuuwwwgwwrgbruub
ggbuugwurgbgrwggurugubwggbbbubrgurrwwburuggrrrgbbbbwg
ggbrgrwuuwwbwbuwwwwgguwbbuwuwuwuwrwgwwubwwuwrb
wrbrgugwrbwrwguggrrggbguwrguuwbwwrrubgbbbuwwrrbrg
gbwbwrgrbwurwuggwwrwwgwrbbwrwwrbrrrrbuwuurrburruu
bgugggbbburbbbrguurbgrugwwgggurugbuubuugubwrwr
wrgbrrrbwwurbgbgbwbuuwbwwbugbgbugrwgwuuubugwrggwwbbbwggwgwrb
wwbwbbrwrbruwrurwurwggwwbrbuugbugbrwgubggrr
brbubbburuwgrbuwwuwrurrwwubrwugwbgburgwrggbwuwrguwgwuu
rwurrbrggrrgbbgbuububrrwbguwrgbwruwgrrruburuurwwrwbuwgbbr
bwggbuggrwuubrrwubuwrgwrbuwwurugrbbguuwrrugbgburggububww
gruuwburbbgbrbwgugwgwuurgububuwugguwuwwrbw
grrbgwbwrbrwgwrwuugwbbgrrggggwuwgwugbbgugwbrugwbwu
rugruggwruburugwugrgwbugwwugwuwrrgrgrggubrgbwgwwwg
urubrbgbgrgwwgwbrgbbwbrruuruuruuururggubwr
burbwguggwrggrwggubuurrgwbgwggwrugwwuubgrbwbgrrbug
wwbwgrrwbwwbrugrbgwgwgrwwggwbrbwbgggguuubwbgbburguggub
urrbbbburgwbwbbwrgubbggrwbbubuwrgggubggwrb
ggugrbggurrbggrwruwgrbrwgwbuurrgrwwwgugurrrbwgbbrbbggwrb
bwgubwruwrgbrbwgbwbbgbwbgrbbruubbuugwburwrb
gwrbbrwugurrbugrbgruwruwrwwguwubwubwbrwgrruggrr
rwgubrrugrwwwubrwwwrbrwwrbgruwgrubbgwgrwrb
brrbwgwgwggugbgrrrrgggubbwwwuururbgbrwugwbrbrbwuuwru
urbrurgrbgguguguuruwurgugwwgrubggbgbwwwgrbugubwggr
rbgruguwrurwbgwgurrwrrrggugrwwbrbrbwgubuwubruubwrurrgwbgbwrb
ggbwuuuwggggrububwwrurgbrbrubbwgbbbgbbbgbwuwwgggbwrbuwrb
rbbbburwggwurrrrbggwgwwrurubwbgbrbruguwwrwrgggrugubw
rgwgwwrgbrgrwgrrbrburwbwuugbgrwwwggrwrbbwrb
ubgrwwwuubwwwwgbbrurbuuruuurrbuwggbbuurgrrwrgwb
wgwwuruurbgwruugrwgrbugrbbwbgwwgguubrwrrbr
bwrwubggwgrrubgrrwuwuuugruuuubuwbrbbwrrbgrwugwgwugrguwrb
rguwgwugururbwwgwwwgwgwbugubbrbrgwrwgguguwbwruwrrrbgbu
wuuuugurbwrgbuugbrrwgggwwwrwrrrrgwrwggwrbb
wwbwbugrwbbuwwwrwrrrubrbgwwwburwgbgbwwbuwrwugguurbg
ubgbuubgrrwruwugwbwbwbwwgbwbuurwwuwbubwrbug
uubgrgrrugubggggwgrbgbrwrwbrgrwbbwgrburrbr
gbwwugwbgggrbguurbrburbwwrugguwbugwwugbuwwbguu
wuwgrgrgwgrbuwgrbgburuuwrbwguuwuruwgbwwubwwbururbw
wwrwgugurwrbbbrwbwubggguuwrwbuurbwbwubggbbuurrwwbubuwrg
bburgruburubrbwrwwwbrgrbuwgwrwggurburubrgwgbbruw
ubrwbwubbbbwbwgruwuuwbrgbuwwuwuurrrwrrrwgb
wwwwrbrrguwugugbgrggrubbrgrurggbgbuwwbrgggwuguwugbrwg
rbrbbuwrubbbugbgwgurggrgbwrrurbburwrwggruwrubgbgwwuuu
wuuugbgwgggburrrrgwbubbbgrubbgburwrbugbbwbwggrgrg
rugwgubuwurrguwbwwurrggrgrurgwbbwbubwwgbgrubruuuwwbu
bgburwubrrwburrbwgwuwwwwurwuuwbgbgrwggubuwubwwggrwrb
uurbururruggwrwuwbguwwwbbwrbbwrggwrgbwwugwrwuwrw
bburugbugwwwwggggwruwwggrwwrbrrbwgbbbuwgwgbwwwubgrgbwrw
rgggubrrbgugguwwuuwurgubgwrbuwubwburwuubrgb
rwrgwbrbbwrbuwwuurgwuwwbrbrwuububrgubbrbwrguruuub
uuugrguwruwwuwuuwgbbrrwwgruuwbbgwguwwruuwrb
bubbubgwwuurgwrbuuurrwrwwrurwgbwugguwgbbggggww
uwruwuguubrrbbggbgrbwrwwwbwwwggggruuuguuugbwrwwrgw
gururwuubwbbugububgwugbugguwuwgwrugbrwrwrb
wrrbwuuwbwbubgwrruwgguwgrbggubrgbgugrrgrubwwwbwbr
rbgwbgwububrrrwbuwwwwgrurwrbwrgurwruggguggurrrubbbwrwgww
wggbrggbrrgbrrgrggwbbwurbbrgugugrbrgrwwbrgubwrwuuruubwugwrb
rrgbggurbrwuwrgrbbwwubguwgurugurwurwbgwrrbbwwuwwbg
wbbggrwrgruwgrbrgburwggrrbbbguurgubbuwbruwwrggrbr
wubugrwrrwuuugwuubgrubbbbgurguwgrwgruwwruguburwuwu
wbwuggubbrwugwbwrrwurgubuurrrubrgwbruugrgbrrbrugbwrruwuubwrb
rrbuwruwguburwgugrwgwuguwuubgurggrbuugbuwrb
wrrbuwggurrggwubgwwuggbwuuwwurrrwwrwurrburgwbwugrgbuwwrwrb
grrurwggwgruwrrbbwuugrwgrgggbrgubggbugugrwrb
wwwrwbuuwgbugbwurrgwuwbuuwrbuurugurwbuuuburrurwrb
ruruggbgwbggrwwrwrbrrgwuguwwrwurrguwugurbbruwbrwuu
uwuuggwurgbwrrrbruwrrwrurgrwrbrwugrwbbburwurbwbru
rrbwuwgrwuugwguugbrwgubrbubgguwrugrwbwrrbggbgrrrugrbbgr
rgggrbugbubburuwwbrrrbuubrrwubuuuwgbgguuuurrubrwwuwwugrbwrb
urrgwwwrgwrrgurrgwbbrggwrgubwgwwwugruuubuuwggbuur
gbuguuwwrbggrwrrubwwgrbwrurugrwrguuuugwgwrrrgubgbwb
gwugrrwrgubuwggwrrguubugwrbururwgbwgbbugwwwrb
bruuwuwbgrbrwbwwubrbbwrgwubgggwugbuwgbrwbbwruubgwbbrwwwubg
wwgurbbbbbwbwwrwguwbrururbwurgbgwurrurbgur
wwrgwuurruwuwugbbrwbwrbbbuwgwwububrwwgggbguwrgwrwrrub
gugwrrrwugugruuwrguwbwwubbggrwbgbwrugbuwrb
rgubwgbggwbbwggwgggrrrgggbuwwrgrwggggrrgwr
gbgrbggbgggggbgugwgubggwrwwwrwgrbrguwuwgwrbbrbuwwgrwuwrb
wwbgrrggrbgrbwbrrrbwrwrwbwrbrrwbwuugggwrb
wbbwbwbgrbwwwuguubbwgugrugbbrbbggrwwurururwggw
uguwrggruugrgwwuubbrbbbgbbgugurruwruwbugwrugubwwbgbwg
ruwbwbrubggruwbrwrurbrrrbgrrwrrgbubbrwrwurwuubwbrruburwuwrb
ugrrbgbbugruruwbgbbbgwbuwgbwugurbrwbgurggbubwwrbb
wbbwrwrwgurubwgbrgwgrgggrguruubburrubwugggrrwgbbrugw
uugwubrgwuuwbrrrbgruuwruwwbuuubgwuwwwuwbruguuuwgrbrwrb
gugubrrggwbuugubrbgwgbubwwgrrurubwwrbbwbrgrr
wrggwguuguuwbgburwwgwgwbruwrgrrwuwwrgbgugurwggbbg
wwuugbgggubwwwgrgrbguguwgwwwgbuwgbugwgwwguwrug
uwuurugbwgbrrbgbbuuwuggbrbrwubwbrggwbgrubbrrggbuubu
gwggubgwgubguwrbggbwwgbuurbbuubuwwugbubwbgbbruu
bbubugbuwwgbgubrbrguwggbbugggbuwuubbwgrwgwg
rrrrwugwuurrrbggrbwbrbrugbrbubugrbubbrguwwwwwrrgwgbuugbu
wrurguruugbwrwbgguggbwruwgbbwgguurwbgubwruuwru
rwbbwbrbwuwrubgbgwrbbuwbgubrgbwrrwwuwgbrwgurgubburuug
ggwubrwwuggrrwbuuubwwgbbgwurwgrgwwuwubbrgruurugwuguggurg
bbrugurbrurbgrbubwurrubbrbbgugwbbbwuuuwrb
wwgwwbruuuruwggbbwuuuubgwbubrbgwbwwuruuguw
gburwbwbgrbwbgrugbuwubgrrbrrggbuwwrwrwbguuuu
uwuwgrbggbrwgwggwwgbrrwburuuguwbbwwwrgurbgurrwgwurguwrbwu
rbwrbuwrwgbbwwggrbwbwwggrwguwggbwrgbrrubgubgugwbrruwwrb
bbuggbgbwgwrrrggbubrggrurugubuwbwuguwbugrrggwuwbwrggbwb
ugggrbwgwuubwwggggwuwwwruuugrrguwwbwubrrwugwrrurwgbg
bwgrgbubgbuurggguubwwrwgbubgrrgrgugwrguwruwbrbwrwbbwbbbb
wrrrbgrbggruggbbuwwuubrruwgbuuubgwbguurrubbubb
rbwrrrrubruuwgrgrbgwwwurwurgwbugrbbwwgggugbu
ugbggrgrguwwwggbruuruubwwgbwuggwbrwbwwbrbwubrubgbrrgwuwrwrb
rwrbrubwbburrurbuwgrrrgurwgrwbrgwgwwrbwgbrwr
wbwrbruubggrgwbbrbgrbuwwrrrbwwburwgwguubuwguwbrgubbwrbrbwrb
rgrrbwrgwbbuuuruuwbrubbbuburguuburrbgrwbgruwru
gwrgrrbubrwgurwgruwguurgruruubgubguggbbwwrb
wgbbuwurburbwwurgbgbwgggruggwurbwuwbubrwrrwbburbgrwgug
ubugbggwuwguwwwuwugwbwgwwuuuggrrrrubwwubwbwrwrrugwbwrgwuu
rubggguguuwgbuwggrruwrwrgruruguurrubwuwrgruwwgrrurbwuw
wurbburwrubbwbwrruwrbrbuuugurbwuwwgrbrbggwwbgugubrrg
gugruugwruwuwrugbgurguguuwwbbrwrurrgubwbwbrgbwrb
wugrbrbgwbbuuwrrgrbwgwrruuuubrbruwggurgbrg
rurwugugguurgubwbuuuurrrwbrrurbwruurwugrubrgubwrub
rubgwwrrwwwgguuggbwuruwwggbrubwbrwgubrrgrwwbuwggbbburwurbwrb
wbbbggwuwbwwgguruwguwbugwgruwwrwrgggurwwuwbbwubgu
bgbwbbwruuugugbrwburuwwrwbbbuggugbwubrrwgwugbwguguuuwru
rbrwwwwwgbruwguuuuubruuurgbuubrwbrbrwurgburbub
grruruwbrwwrbgrgbgrwuwrgwwuwbbwgrrrrrrrrrggbbbwbbbbu
urrwbbbrwuggrggbgububbrbubuwggwuugwurbbbwbbrwrb
rwwubggwrrbuurwwrrruuuruwggggwbbuwurrurugg
bgrbrruwrrgrwbwruwbwbguugbrrggrbgububwbuubrububggugg
rwruuwbuwruuwrrwgbwwrbwwwbwwrwwuuggbggwbbrbbbwwg
rrgwrgwubgwrwugbuurgruburburuwwwbwwwwrgwwrgwrgrgg
wgwrrgwwurrrubwgwrgbrbwgbbubrrrgugwwguubuwrbbb
gurggwuurwwurwrggugwugrbwubggwwwugrbubwrubbuw
uruuwurrggwbgrugrrbbubwbwwggbuuugwgrwbuuuugrrwbr
wbbguguuwuubwwrbrbbrugwrwuuwgrggbbwurrubrrgwwrb
rruuugbgbgrrwwrwgrbugburbubuuggurguugbwgggwrwwbubb
brbgwwbgrugurrgurbbwbrwubbrbrrwugwrwugrwwrb
buurubwuubrwbugwbbrrgwbgubrggubwurggwbrwwrrurubwrgrrg
wbrbrrrgrrbwubwgrwubgrgrwuubbgwwwugbwruwugwwgubww
uwrgbrubwbuubuurrrbwuguwbggurbubuwgwbwrggbggbwruwuggguwbw
gwbwgbwbgrwbgbbbrwwggbgrurgrwguwgrbruuwbugwrbuwwbwrb
guwbwbrwgbgrrrbbrbruwwbbuwwggbwrrbuubugwbrwrb
wrubrurubbbuguurrbguugwurwuuuwgubrwbbgguwwbbbwwwrbwgwuwgr
rurgbrrbwwbgwbubuggwugrubbgwwwrubuuwbgwgbgwugrrugrub
rwugwrwwbuggwbugbbwrbwwruggbgrwuugruurgrbwwbuwwurubgbr
bwbwuuubbgurgrgrbggrubuuwrugwgwuwggwrggbrbwubwgwguwwrb
urrgurwuwwggrubgrrwrugbbgbbbgwrguggrbuggrgrgwrb
wuwurrrrwbwgwwggurwuwbrrgrburggbwgrggbgrbrrggburrggwwrb
ubugrbugubbwgbbbwwgwgwgbguwwbrgbrgwubbwgwwruubgrgrrrb
gurwwrggbbbburwbgububbrwrggbuwgbwrbrrugburgrgbu
ubgbbrrbubrrubbggrbgwbwrbrwubwuurgwbburwwgr
gwbrrgwgubbbbrrubwgrguguggwwrbggrwrwuuururwrwguwgrbuwbuuwrb
ggbubbbbwruuggrwwuuwbbwubgbururrggrbbwgwrb
rgbbrgrwgrruwrwbuurgugbrububrugbgwruwbrurbrwwuwbbrgbbrugr
urruuurggrwgugbgrwgubrbbbbwuwrrwgrubrurgrbuwrgwu
bbwwwwrbbuwubgrrgurbbruwrbrwguwrbwrurwwwbbuwgruubwwwrb
rbrggubbuwguwbggbrrbbwrrurrrbuuuggugububbbbwrrwb
ugwgwwwrwruugwrwrbuggwuuwgbubwgrbrwwgrggrrgrbrbgbbwgwrb
ggugburbbrgrrwgwbwbwruuwugrbrrrurgwrbrrbrwubr
ububbrggggrbruugrubrwrbgbwggwrbrwubggubgggrrgbubrrgrwrb
rrgwwwrugrurwuggggwrbbwugwwwwububgbrbguwwwguwguwrb
uuwwwrbgrrbwgwuwrwwwgwwwrbbrbuggwwuguurwgwrb
gurrrubbgwubwuggrrwwbbubbrgbgubruwrgubggrwgrburrrrg
uwugubuuwurruwruubgbgbwwggbrwgwgrbbuwugwrb
wwwrbwrbwwgbrbrwbrggrgwrurrbrbwuruuburbubguwwugggrbwgwgb
wbgugurgwrrbbwugwbrwuwrwruruwrrugrruugwuggggw
rwbrwwgrgwwgrwgwbgwrwrwguubuwwbguwggubwggwwbww
rggrruwggwrrgggbrruwrgbuggbbgbwbwgurwrugwbgwwwr
gbbwrgwwrwgguurbggrbgbwggbbbuuwururrgrgwgbgg
wbgruwwwubrbugwbuwuubwgrubguwgwbrubrgwwwgwbgwwrrugbgbub
ugbwugubwgwbuggrurguwwubwrrurrbrgurrbrubwuwrwwwwwgwwgrwwbw
wrwubuguggbrrbugwbwwwrguuuguubwuruugwbgwbguurgwwbggrwwbuwrb
uuugbgrgwrugwguuuuurwgggrburwwgbwrurwbgrrwrb
wbgwguuwbbuwggubrrwbgrgbwuwrgbubruwggbrrubbwg
ubuwbrwbbbwbguuwgugrbuwwrgugwubgrburbgbbrrgrubbbbbu
ugbubrurbgwgwwgrurbwugbwwwbbgbugbbbuggrwgrbugbgwwbuwrbuwrb
wgrwwuugurbgrrgwwbwrubrgrrwwubgbuggwbbuwubu
gbuwrwbrrrwrwbwwrgbugrbugbrurrgggrgwgwgrrbgubrr
wugbuggubuggbrggubwgggbgbgbgurrgwwbrwwwwrb
grgugwubbugurgbguwbgbrugwbugbrrwubwrwuwrgbrugrgwrwrb
guruwwrurwurwugbbrbwwwwubuwrwuuwwugwruwbggbbb
bguruwbbggggbgugrbgrrrgubbbrubwrrwrwubrwgrurw
wbbrbbrgbbgguwbruuguwbbbrbrgrubgugwrgbrrgrwruguwrb
wgrbrgbrgwurggggurwwwggubbggrrrgrubugwuggb
bbwuwwrwrrubruuggwwbrurbgwururwggwwrrrurrww
ubwuugrgwuuuwururbrguurgrbwwwrrwbwruwrgwururbugrwrru
rgbbrwbbguggwbrwwbbgrburwbbwwgbrbwbbubwwrb
uuwuuubgurwwggwwbbbgbgbwbrrgbrrwrbbuwwwgubgggbbrwbrr
gbuurwggrrggbbrgbuuwrgrggrwgwwrwugugwbgwwbrr
bwbrgwbrgwwubrgubbbuwbrubwrbgbrrbbbbwrwbgwguuuuubrgrgrw
guwguururgwuwuuwgwbruguwbbubuwbrggwwugrwruruuugrwrb
grgwuuwrbbgrrgggbwrugbgwbbbrwuuwuwgbwugwruurrrbbuggrwwwru
buwggggwrrrruburwbrugrwrrgwuguwggwbwbgugrgugwwurbbburrggw
ugrwgbbwwwbbgruubgguuruuuururwwbuugbgwwrgubrrbuwwugggw
wbrbbugwgburbgrbgrurrbwwwrbwbwubbgrurrurwwrrbwgbugugw
ugugwbwwgrrgrgbuubwrwbrrurrgbubggwrgbugwrgbggubbruubgw
bwwubbgwwrrwruuruguugugrwgwubbguburuurwguwbwrwrb
brrbwugubgwrgurrrgrbbrwrurugrugwuggwrgrbrwggwbbuwurrwwruwrb
rwbbrbgwgbwguwgbgwurgrbuurugrrgwuwuurubrbgr
uwwbuuwgbwgggwrububuugrwurgggwgbwbubuurgbwrrwbbrwuruwrrrb
bbgwbwrrruurwwugbggbbguggguurrbbbbuubbwbwrwbrwurrbuwgrb
gwgwbwgguwwrwugugwuuwurwgwgbuwgbgbwwuurwwggrubb
rgburwwwuurrgbuwrgwrbugwwgguwwwgbubuuggrwbgubrwrgwugwbuwb
gurrbwgburruggbrbuguugbguruwurbuugbrgbguguuuubwggrwgrrwbwwrb
ruggwuwgbgguwwuburgruwrbgbubbwwugrbwuwwbrbrrwbg
wwbrrgguwbbguubbuuuuugwbbrwrrgrruwrgwwrbbbbwgrgw
bwbrwbwwrwwuugugugbrbrbrrbwrwrruguwuwwubbugwgurrr
wggrwwubuwruwgugrguggugwbbggugruuggrwbggrwbbw
gbgubgbwgurbwrrrgbuwwguwrrwwbwuwuwbgburrbgwbgwr
grrububuwruwrubrgwwbrrgrbwugrggwbrgbwwrb
uguuggrrwubrgrwggububbwgbbwgrwurwwwgwbubbbruggrwbrbgwrb
brgurrbwwugubrrgurrbbrbuubbwwwwguwwgrwwugubgruruu
wrwubrrwburuwbrgwwuggurwrrwbbruruuwuwuwubbubuuu
bwbugbrrbwugbwrubuwbuwwubbbguwbrgwwurbgugrgrwgwuwwbwubgwrwrb
bwguwgurgurrrbgbbbwbrrrwuwbrwubruuwrbwrb
rbubgwbubuwwbubbrgwwgubgwwrrgbubrwbbrwwrbwwuwgbbwrb
wrbbgwburwwwrgwggggrrbubbggrbgbggwurwruburwubrubrgr
rggurrwwgururrgrwwwgrugwwbguurbbwbuwrwurrrbrggbbbbrwwr
ugwwgwrgrgugrbbbbubrwrubrbguwbrwubgrwgrrgbgggwugw
uwgrgbugbwbbggrgrbbgrwrbggrrwbbwbugwrwbrrwwuuwrb
bguubugwggwguuggbguuwbgwbwruggwrbgbrrbwbrrbgwrbggwrbrrbu
rgwwbubbbbuugubwbrwuwwrrruuwggrbbrbwguwruuubgbwwgwurbgbubg
uuwbwbrwwubbrwuuuwuwwgggwwubburgwgwbrurrwbrbgbbburwgb
wwrrbbwwbruwbgbggbrbbgrugubggwgggugrbuurgrbbgbuwu
ugrbwbwwgggwrgbbguugrgggwrggbuuwuwubrgbruwbwrb
ubggwbwguugbbubbgbbguubwuubrbwubrubrwguwwwrb
rugburrbwruuwrwwgwrwggrubgwbuuubugbwuurgbg
ggrwrruwggbubrurubgwrbwrgbwgwuwrbbbwbuugwubrubwuwbrbgbgubg
grgwugwuwbgwuuwuugrgwwguwbburuubbbgubbuwgwg
ruwrwrwwrwgwwrgbubgbrbrwwbgurrwrrgbruuwgrgrrrgurugugu
brbwrgurrwgwrruwubrwwwrggbuururgrguwggwbbgrgubrw
bbuwggrbugbbgbguugwuuwuubgwgbbrgugbgbwbrubbbgugwrgrgrgruuwrb
wgbgbubuwrurbuuwgrugwrgrbrwrgwuwbbgwrrrrwrb
wgwrgbbbuurubgwwrgwguururrubgbgwrbgwwwwwggggbrurgrr
uwggrggrbrruwuruwbuwurrrwwwwbuggbguwuubwuwbubrrwrb
ugubbwurwurgwwrburwuugrurguuwruwwrwbgruggwbwwwgwbb
ubwgwbbgbrugguwrggubbrgrbgruuwugbgruuwggrbgwugugwugrrwwg
wggrgugugubgrrrbugbbbwrrrwbwguuruugrwwrb
bwgwwbrwbbubgwubrwwwgurbwbrwbubgbwbubwgbbggrrwbbgbwrbbrr
gurwrbbbrbrurbrrbugrrrguurwwbbwugwbubuwrwbrgbgrwrbuuwrbuuw
gwwwwuuubuguwwurubwwrggguwgbrbbbgbububgwrbwbubbruwbb
uwwwbbggwrgbrgrubrurwrgugrbubuwwruugbwbgubugbuguuuuurbrgr
rrbubwbuwrgrrugubbbuuuwwbwgurrwwgwburubwrwrb
rurrbbgurbuuruwuuwrurrwbbggrrrgguwgwrurgrurubwrwwrb
ugbugurrgggrgrbuuwgbuugrrgbuuwugbrwrrgbubbbbburuuuwww
wuwgugruburwguwrwgwbwrbubbrbgwbrgbwruruwbbuwwwugurwgurwrbbb
wugwbruwuggrruggrbgrgubuubgurbrrrruwrguububruubwugwwbbwbu
grubuwwurrbbggwbwwwruuuuubwgwubwuubuuwrrrwgrururbggbbggw
gwgrwbuwuwgwrubbgbugrgwbgrbwbuwgrggbwrrubbuggwbgrwgbggg
uruwrwuwbrbrwwruwgurrugrbwguuubwrwwurubgrbgrgwwur
rguubrwwgubuwwruruwbuggbrburgrgurugwwwwrb
uuubuubggrugbgbgwgbbgburuwggrrggwrwruwgbuwwbrgu
gwgrgugwgbwbuwbgwgbrguuguguugrrgrbuugugbrgu
urgrwwwrgurwwrwwwggbgubbrgwwwruwubgbrgurguurwugrgwrb
rubgwbrwbgrruuwbruwrgwbwbguwururubrgwrurbuubww
brurbguurgbggwbbgwwwugbrbgwrwbrwrrbrwbugwuguwrbwru
rwrbbguggugwwgrbrrwrbgruwrwwuugbrgurbwuguwwubgbgg
wgrgbgbwbbggrwgrbbbrrwubgrbrbgwwururguwugbgrgrrug
gwuurwubwwguggwwbbwwugrwgggwwurrrgrrrburguwwrrb
guggrruwrbrugwrwgrbgurbgbrgwugwwwwbbbwwrwuwug
uwgrrgrbbgwrggrwwwgbgbrbbrbuuburbbrbrugwurugwbburgbb
wwwbbbwbbbrbgubrwbbrubugbrgrrrruuwgurrwwwruwgwrguw
uuubuwgwrwugrbggggbruugbrruwuurubwwgwbwgurbgbuubbgwbuww
wbrrwgbuwggubuggrugbwwbbbbwgwrrbgggrrrwrbgrbgg
gbbbrwwggbugrbrrwrgbuwgbrrrwgwgubrruruurwguwb
rrbbuwrbruwruwurbggburwwbwuuwrurbbwrbuurubggwrb
rrubbuurrrgbrwwuwrbwgruuwbbwugrgubgbwwruwbburgbwb
wrwugbbgrbgurubrwwwwwbbbruubwgrgburbwbrgbwbgwb
wwrwugwbbrubugbrrgrwwbwbuwwwuugbbwguruggwgwrwgwrggwrgrgwgwrb
bguwgugwbgwgubwwbwwrwubrrwubbwgrbwgggwuuwgrbgwgwgrwwggrb