#!/usr/bin/env python import numpy as np import math from heapq import * from collections import defaultdict with open('day15.txt') as data: costs = [] for line in data: costs.append(list(line.strip())) costs = np.array(costs).astype(int) def a_star(costs) -> int: def h(point): m, n = point # approximate with straight line distance between points return math.sqrt((costs.shape[0]-m)**2 + (costs.shape[1]-n)**2) def neighbors(point): m, n = point neighboring = {(0, 1), (1, 0), (0, -1), (-1, 0)} return {(m+dx, n+dy) for dx, dy in neighboring if 0<=m+dx 9] = 1 xDim, yDim = costs.shape for i in range(5): for j in range(5): copied = np.copy(costs) for _ in range(i+j): increment(copied) new_costs[xDim*i:xDim*(i+1), yDim*j:yDim*(j+1)] = copied print(a_star(new_costs))