This commit is contained in:
@@ -61,13 +61,13 @@ def part_2(input):
|
|||||||
if not (x, y) in done:
|
if not (x, y) in done:
|
||||||
next.add((x, y))
|
next.add((x, y))
|
||||||
for (x, y) in next:
|
for (x, y) in next:
|
||||||
next_cost = nodes[(x % x_size, y % y_size)] + \
|
next_node_cost = nodes[(x % x_size, y % y_size)] + \
|
||||||
(x // x_size) + (y // y_size)
|
(x // x_size) + (y // y_size)
|
||||||
if next_cost > 9:
|
if next_node_cost > 9:
|
||||||
next_cost -= 9
|
next_node_cost -= 9
|
||||||
if not (x, y) in cost or (cur_cost + next_cost) < cost[(x, y)]:
|
if not (x, y) in cost or (cur_cost + next_node_cost) < cost[(x, y)]:
|
||||||
cost[(x, y)] = cur_cost + next_cost
|
cost[(x, y)] = cur_cost + next_node_cost
|
||||||
heappush(queue, (cur_cost + next_cost, (x, y)))
|
heappush(queue, (cur_cost + next_node_cost, (x, y)))
|
||||||
done.add(current)
|
done.add(current)
|
||||||
result = cost[end]
|
result = cost[end]
|
||||||
print("Part 2 result:", result)
|
print("Part 2 result:", result)
|
||||||
|
|||||||
Reference in New Issue
Block a user