Solve 2018 day 22 and 2019 day 20

This commit is contained in:
2024-09-21 22:49:45 -04:00
parent db383c7cfa
commit 6c3aec3d6e
4 changed files with 251 additions and 4 deletions

4
lib.py
View File

@@ -229,6 +229,7 @@ class A_Star(object):
"""
open_set = []
g_score = {}
self.cost = None
for start in starts:
heapq.heappush(open_set, (h(start), start))
@@ -237,7 +238,8 @@ class A_Star(object):
while open_set:
current_f_score, current = heapq.heappop(open_set)
if is_goal(current):
self.cost = current_f_score
assert current_f_score == g_score[current]
self.cost = g_score[current]
break
for neighbor in neighbors(current):