summaryrefslogtreecommitdiffstats
path: root/15.py
blob: f3dd57c3ff4e7f60522317be699b3a6a29427744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from utils import open_day, Point2D, adjacent_bounded, a_star

with open_day(15) as f:
    inp = [[int(c) for c in l.rstrip()] for l in f]

def h(p): return 0

def d(a, b):
    add = b.x // len(inp[0]) + b.y // len(inp)
    x, y = b.x % len(inp[0]), b.y % len(inp)
    return (inp[y][x] + add - 1) % 9 + 1

start = Point2D(0, 0)
goal1 = Point2D(len(inp[0]) - 1, len(inp) - 1)
neighbours1 = lambda p: adjacent_bounded(p, Point2D(len(inp[0]), len(inp)), False)
print(a_star(start, goal1, neighbours1, h, d))
goal2 = Point2D(len(inp[0]) * 5 - 1, len(inp) * 5 - 1)
neighbours2 = lambda p: adjacent_bounded(p, Point2D(len(inp[0]) * 5, len(inp) * 5), False)
print(a_star(start, goal2, neighbours2, h, d))