Compare commits

...

4 commits

4 changed files with 479 additions and 0 deletions

93
2023/d23/ex1/ex1.py Executable file
View file

@ -0,0 +1,93 @@
#!/usr/bin/env python
import enum
import sys
from collections.abc import Iterator
from typing import NamedTuple, Optional
class Point(NamedTuple):
x: int
y: int
class Cell(enum.StrEnum):
PATH = "."
NORTH_SLOPE = "^"
SOUTH_SLOPE = "v"
WEST_SLOPE = "<"
EAST_SLOPE = ">"
def neighbours(self) -> Iterator[Point]:
match self:
case self.PATH:
yield from (
Point(-1, 0),
Point(1, 0),
Point(0, -1),
Point(0, 1),
)
case self.NORTH_SLOPE:
yield Point(-1, 0)
case self.SOUTH_SLOPE:
yield Point(1, 0)
case self.WEST_SLOPE:
yield Point(0, -1)
case self.EAST_SLOPE:
yield Point(0, 1)
def apply(self, pos: Point) -> Iterator[Point]:
for dx, dy in self.neighbours():
yield Point(pos.x + dx, pos.y + dy)
Trails = dict[Point, Cell]
def solve(input: list[str]) -> int:
def parse(input: list[str]) -> Trails:
res: Trails = {}
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == "#":
continue
res[Point(x, y)] = Cell(c)
return res
def explore(trails: Trails, start: Point, dest: Point) -> int:
def recurse(start: Point, seen: set[Point]) -> Optional[int]:
if start == dest:
return 0
if start not in trails:
return None
next_step = (
recurse(n, seen | {n})
for n in trails[start].apply(start)
if n not in seen
)
distances = [dist for dist in next_step if dist is not None]
if not distances:
return None
return max(distances) + 1
res = recurse(start, {start})
assert res is not None # Sanity check
return res
trails = parse(input)
start, dest = Point(0, 1), Point(len(input) - 1, len(input[0]) - 2)
assert start in trails # Sanity check
assert dest in trails # Sanity check
sys.setrecursionlimit(10_000)
return explore(trails, start, dest)
def main() -> None:
input = sys.stdin.read().splitlines()
print(solve(input))
if __name__ == "__main__":
main()

141
2023/d23/ex1/input Normal file
View file

@ -0,0 +1,141 @@
#.###########################################################################################################################################
#.#...#...#...#...#...#.........#.......#...#.......#...###...###...#...#...#...###...#...#...#...#.....###...#...###...#.....#...#...#...###
#.#.#.#.#.#.#.#.#.#.#.#.#######.#.#####.#.#.#.#####.#.#.###.#.###.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#.#.###.###.#.#.#.###.#.#.###.#.#.#.#.#.#.###
#.#.#.#.#.#.#.#.#.#.#...#.......#.....#.#.#.#.....#...#...#.#.#...#.#.#...#.#.#...#.#.#.#.#.#.#.#.#.#...#...#.#.#...#.#.#...#.#.#...#...#...#
#.#.#.#.#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#.#.#.#.#.#.###.#.#####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#####.#.#.#.#.#.###.#.###v###.#.#.###########.#.#.#.#.#.#.#.#.#.#.#######v#.#.###############.#.#.###
#.......#.....#####.#.###...#.#.#...#.>.>...#.#.#.#.#.#.#...#...>.>.#.#...###...###...#...#...#.#.#...#...#...#...#.#...#.............#...###
#######.###########.#.#######.#.#.#.###v###.#.#.#.#.#.#.#.#######v#.#.#######.#.###.###########.#.#########.#.#.###.###.#.###################
#.....#.........#...#.#...#...#.#.#.#...###.#.#.#.#...#...###.....#...#.......#.....#.........#...#.........#...###.#...#.#.....#...#.......#
#.###.#########.#.###.#.#.#.###.#.#.#.#####.#.#.#.###########.#########.#############.#######.#####.###############.#.###.#.###.#.#.#.#####.#
#...#...........#.....#.#.#...#.#.#.#.....#.#.#.#.###...#...#.........#.#...#.........#.......#...#.#.......#...###...###...###...#...#.....#
###.###################.#.###.#.#.#.#####.#.#.#.#.###.#.#.#.#########.#.#.#.#.#########.#######.#.#.#.#####.#.#.#######################.#####
###.........#...#...###.#.....#.#.#.......#...#.#.#...#...#.###...#...#.#.#.#.#.......#.#...#...#.#...#.....#.#.#...#...###...#.........#####
###########.#.#.#.#.###.#######.#.#############.#.#.#######.###.#.#.###.#.#.#.#.#####.#.#.#.#.###.#####.#####.#.#.#.#.#.###.#.#.#############
#.....#.....#.#...#...#...#...#.#...........###...#.......#...#.#.#...#...#.#.#.....#...#.#.#.#...#...#.......#.#.#...#.#...#.#.............#
#.###.#.#####.#######.###.#.#.#.###########.#############.###.#.#.###.#####.#.#####.#####.#.#.#.###.#.#########.#.#####.#.###.#############.#
#...#...#...#...#.....#...#.#.#...#.......#...#...........###.#.#.....#...#.#.#.....#...#.#.#.#.###.#.#...#.....#.#.....#...#...........#...#
###.#####.#.###.#.#####.###.#.###.#.#####.###.#.#############.#.#######.#.#.#.#.#####.#.#.#.#.#.###.#.#.#.#v#####.#.#######.###########.#.###
#...#...#.#...#.#.#...#.....#...#.#.#...#.....#.......#.....#...###...#.#.#...#.....#.#...#.#.#...#.#.#.#.>.>.#...#.#.....#...........#...###
#.###.#.#.###.#.#.#.#.#########.#.#.#.#.#############.#.###.#######.#.#.#.#########.#.#####.#.###.#.#.#.#####.#.###.#.###.###########.#######
#...#.#...#...#.#.#.#.#.........#...#.#...#...#.....#...#...#.....#.#...#...#...#...#.###...#...#.#.#...###...#.#...#.#...###.........#...###
###.#.#####.###.#.#.#.#.#############.###.#.#.#.###.#####.###.###.#.#######.#.#.#.###.###.#####.#.#.#######.###.#.###.#.#####.#########.#.###
###.#...###.....#...#.#.#.....###...#.#...#.#.#...#.#.....###...#.#...#.....#.#.#...#...#...#...#.#.......#...#.#...#.#.#...#.........#.#.###
###.###.#############.#.#.###.###.#.#.#.###.#.###.#.#.#########.#.###.#.#####.#.###v###.###.#.###.#######.###.#.###.#.#.#.#.#########.#.#.###
###...#...#...........#...###.....#...#.#...#.###.#.#.......###.#.#...#.#...#.#.#.>.>.#.#...#...#.#.....#...#...###.#.#.#.#.###.......#.#.###
#####.###.#.###########################.#.###.###.#.#######.###.#.#.###.#.#.#.#.#.###.#.#.#####.#.#.###.###.#######.#.#.#.#.###.#######.#.###
#####.....#...........#...###...........#...#.#...#.#.......#...#.#.###.#.#...#.#...#.#.#.....#.#...###...#.#.......#.#...#...#...#...#.#...#
#####################.#.#.###v#############.#.#.###.#.#######.###.#.###.#.#####.###.#.#.#####.#.#########.#.#.#######.#######.###.#.#.#.###.#
#.....................#.#.#.>.>.###...#...#.#.#.#...#.....#...#...#...#.#.#.....#...#.#.#.....#...#.....#...#.......#.###.....#...#.#.#.#...#
#.#####################.#.#.###.###.#.#.#.#.#.#.#.#######v#.###.#####.#.#.#.#####.###.#.#.#######.#.###.###########.#.###.#####v###.#.#.#.###
#...#.....#...........#.#.#.#...#...#.#.#.#.#.#.#.#.....>.>.#...#...#.#.#.#.....#.###.#.#.......#...#...#...........#...#.....>.#...#.#.#.###
###.#.###.#.#########.#.#.#.#.###.###.#.#.#.#.#.#.#.#########.###.#.#.#.#.#####.#.###.#.#######.#####.###.#############.#######v#.###.#.#.###
#...#.#...#.#.........#.#.#.#.#...###.#.#.#.#.#.#.#.........#...#.#.#.#.#.#.....#...#.#.#.......#.....###...#.....#...#.#.......#...#.#.#.###
#.###.#.###.#.#########.#.#.#.#.#####.#.#.#.#.#.#.#########.###.#.#.#.#.#.#.#######.#.#.#.#######.#########.#.###.#.#.#.#.#########.#.#.#.###
#.....#.....#...........#...#...#####...#...#...#...........###...#...#...#.........#...#.........#########...###...#...#...........#...#...#
###########################################################################################################################################.#

104
2023/d23/ex2/ex2.py Executable file
View file

@ -0,0 +1,104 @@
#!/usr/bin/env python
import copy
import sys
from collections.abc import Iterator
from typing import NamedTuple, Optional
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)
Trails = set[Point]
Graph = dict[Point, dict[Point, int]]
def solve(input: list[str]) -> int:
def parse(input: list[str]) -> Trails:
res: Trails = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == "#":
continue
res.add(Point(x, y))
return res
def to_graph(trails: Trails) -> Graph:
graph: Graph = {p: {} for p in trails}
for p in trails:
for n in p.neighbours():
if n not in trails:
continue
graph[p][n] = 1
return graph
# Remove every node which has exactly two neighbours (i.e: straight lines)
def condense_graph(graph: Graph) -> Graph:
graph = copy.deepcopy(graph)
nodes = list(graph.keys())
for n in nodes:
if len(graph[n]) != 2:
continue
(n1, d1), (n2, d2) = graph[n].items()
del graph[n1][n]
del graph[n2][n]
del graph[n]
graph[n1][n2] = d1 + d2
graph[n2][n1] = d1 + d2
return graph
def explore(graph: Graph, start: Point, end: Point) -> int:
def recurse(start: Point, seen: set[Point]) -> Optional[int]:
if start == end:
return 0
if start not in graph:
return None
next_step = (
(dist, recurse(n, seen | {n}))
for n, dist in graph[start].items()
if n not in seen
)
distances = [
(dist + steps) for dist, steps in next_step if steps is not None
]
if not distances:
return None
return max(distances)
res = recurse(start, {start})
assert res is not None # Sanity check
return res
trails = parse(input)
graph = to_graph(trails)
graph = condense_graph(graph)
start, dest = Point(0, 1), Point(len(input) - 1, len(input[0]) - 2)
assert start in graph # Sanity check
assert dest in graph # Sanity check
return explore(graph, start, dest)
def main() -> None:
input = sys.stdin.read().splitlines()
print(solve(input))
if __name__ == "__main__":
main()

141
2023/d23/ex2/input Normal file
View file

@ -0,0 +1,141 @@
#.###########################################################################################################################################
#.#...#...#...#...#...#.........#.......#...#.......#...###...###...#...#...#...###...#...#...#...#.....###...#...###...#.....#...#...#...###
#.#.#.#.#.#.#.#.#.#.#.#.#######.#.#####.#.#.#.#####.#.#.###.#.###.#.#.#.#.#.#.#.###.#.#.#.#.#.#.#.#.###.###.#.#.#.###.#.#.###.#.#.#.#.#.#.###
#.#.#.#.#.#.#.#.#.#.#...#.......#.....#.#.#.#.....#...#...#.#.#...#.#.#...#.#.#...#.#.#.#.#.#.#.#.#.#...#...#.#.#...#.#.#...#.#.#...#...#...#
#.#.#.#.#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#.#.#.#.#.#.###.#.#####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#####.#.#.#.#.#.###.#.###v###.#.#.###########.#.#.#.#.#.#.#.#.#.#.#######v#.#.###############.#.#.###
#.......#.....#####.#.###...#.#.#...#.>.>...#.#.#.#.#.#.#...#...>.>.#.#...###...###...#...#...#.#.#...#...#...#...#.#...#.............#...###
#######.###########.#.#######.#.#.#.###v###.#.#.#.#.#.#.#.#######v#.#.#######.#.###.###########.#.#########.#.#.###.###.#.###################
#.....#.........#...#.#...#...#.#.#.#...###.#.#.#.#...#...###.....#...#.......#.....#.........#...#.........#...###.#...#.#.....#...#.......#
#.###.#########.#.###.#.#.#.###.#.#.#.#####.#.#.#.###########.#########.#############.#######.#####.###############.#.###.#.###.#.#.#.#####.#
#...#...........#.....#.#.#...#.#.#.#.....#.#.#.#.###...#...#.........#.#...#.........#.......#...#.#.......#...###...###...###...#...#.....#
###.###################.#.###.#.#.#.#####.#.#.#.#.###.#.#.#.#########.#.#.#.#.#########.#######.#.#.#.#####.#.#.#######################.#####
###.........#...#...###.#.....#.#.#.......#...#.#.#...#...#.###...#...#.#.#.#.#.......#.#...#...#.#...#.....#.#.#...#...###...#.........#####
###########.#.#.#.#.###.#######.#.#############.#.#.#######.###.#.#.###.#.#.#.#.#####.#.#.#.#.###.#####.#####.#.#.#.#.#.###.#.#.#############
#.....#.....#.#...#...#...#...#.#...........###...#.......#...#.#.#...#...#.#.#.....#...#.#.#.#...#...#.......#.#.#...#.#...#.#.............#
#.###.#.#####.#######.###.#.#.#.###########.#############.###.#.#.###.#####.#.#####.#####.#.#.#.###.#.#########.#.#####.#.###.#############.#
#...#...#...#...#.....#...#.#.#...#.......#...#...........###.#.#.....#...#.#.#.....#...#.#.#.#.###.#.#...#.....#.#.....#...#...........#...#
###.#####.#.###.#.#####.###.#.###.#.#####.###.#.#############.#.#######.#.#.#.#.#####.#.#.#.#.#.###.#.#.#.#v#####.#.#######.###########.#.###
#...#...#.#...#.#.#...#.....#...#.#.#...#.....#.......#.....#...###...#.#.#...#.....#.#...#.#.#...#.#.#.#.>.>.#...#.#.....#...........#...###
#.###.#.#.###.#.#.#.#.#########.#.#.#.#.#############.#.###.#######.#.#.#.#########.#.#####.#.###.#.#.#.#####.#.###.#.###.###########.#######
#...#.#...#...#.#.#.#.#.........#...#.#...#...#.....#...#...#.....#.#...#...#...#...#.###...#...#.#.#...###...#.#...#.#...###.........#...###
###.#.#####.###.#.#.#.#.#############.###.#.#.#.###.#####.###.###.#.#######.#.#.#.###.###.#####.#.#.#######.###.#.###.#.#####.#########.#.###
###.#...###.....#...#.#.#.....###...#.#...#.#.#...#.#.....###...#.#...#.....#.#.#...#...#...#...#.#.......#...#.#...#.#.#...#.........#.#.###
###.###.#############.#.#.###.###.#.#.#.###.#.###.#.#.#########.#.###.#.#####.#.###v###.###.#.###.#######.###.#.###.#.#.#.#.#########.#.#.###
###...#...#...........#...###.....#...#.#...#.###.#.#.......###.#.#...#.#...#.#.#.>.>.#.#...#...#.#.....#...#...###.#.#.#.#.###.......#.#.###
#####.###.#.###########################.#.###.###.#.#######.###.#.#.###.#.#.#.#.#.###.#.#.#####.#.#.###.###.#######.#.#.#.#.###.#######.#.###
#####.....#...........#...###...........#...#.#...#.#.......#...#.#.###.#.#...#.#...#.#.#.....#.#...###...#.#.......#.#...#...#...#...#.#...#
#####################.#.#.###v#############.#.#.###.#.#######.###.#.###.#.#####.###.#.#.#####.#.#########.#.#.#######.#######.###.#.#.#.###.#
#.....................#.#.#.>.>.###...#...#.#.#.#...#.....#...#...#...#.#.#.....#...#.#.#.....#...#.....#...#.......#.###.....#...#.#.#.#...#
#.#####################.#.#.###.###.#.#.#.#.#.#.#.#######v#.###.#####.#.#.#.#####.###.#.#.#######.#.###.###########.#.###.#####v###.#.#.#.###
#...#.....#...........#.#.#.#...#...#.#.#.#.#.#.#.#.....>.>.#...#...#.#.#.#.....#.###.#.#.......#...#...#...........#...#.....>.#...#.#.#.###
###.#.###.#.#########.#.#.#.#.###.###.#.#.#.#.#.#.#.#########.###.#.#.#.#.#####.#.###.#.#######.#####.###.#############.#######v#.###.#.#.###
#...#.#...#.#.........#.#.#.#.#...###.#.#.#.#.#.#.#.........#...#.#.#.#.#.#.....#...#.#.#.......#.....###...#.....#...#.#.......#...#.#.#.###
#.###.#.###.#.#########.#.#.#.#.#####.#.#.#.#.#.#.#########.###.#.#.#.#.#.#.#######.#.#.#.#######.#########.#.###.#.#.#.#.#########.#.#.#.###
#.....#.....#...........#...#...#####...#...#...#...........###...#...#...#.........#...#.........#########...###...#...#...........#...#...#
###########################################################################################################################################.#