summary refs log tree commit diff
path: root/22.24/main.py
diff options
context:
space:
mode:
Diffstat (limited to '22.24/main.py')
-rw-r--r--22.24/main.py44
1 files changed, 15 insertions, 29 deletions
diff --git a/22.24/main.py b/22.24/main.py
index 9e5783e..68f4c64 100644
--- a/22.24/main.py
+++ b/22.24/main.py
@@ -48,42 +48,28 @@ def coll(x, y, t):
             return True
     return False
 
-def search():
-    partOne = None
-    cur = [(0, (start, 0, 0))]
+def search(start, end, t):
+    cur = [(0, (start, t))]
     visited = set(cur[0][1])
-    asdf = 0
-    gid_bonus = tdist(start, end)
     def dist(node):
-        bv, t, gid = node
-        goal = end if gid != 1 else start
-        score = 0
-        score += tdist(bv, goal)
-        score += t
-        score -= gid * gid_bonus
+        bv, t = node
+        return tdist(bv, end) + t
     while True:
         _, node = heappop(cur)
-        bv, t, gid = node
+        bv, t, = node
         vs = [bv]
         for d in range(4):
             vs.append(tadd(bv, tdir(d)))
         for v in vs:
             if not coll(*v, t+1):
-                node = None
-                if v == end and gid == 0:
-                    if not partOne: partOne = t+1
-                    node = (v, t+1, 1)
-                elif v == start and gid == 1:
-                    node = (v, t+1, 2)
-                elif v == end and gid == 2:
-                    return partOne, t+1
-                else:
-                    node = (v, t+1, gid)
-                chk = (node[0], node[1], node[2])
-                if not chk in visited:
-                    visited.add(chk)
-                    heappush(cur, (asdf, node))
-                    asdf += 1
-    return None
+                if v == end:
+                    return t+1
+                node = (v, t+1)
+                if not node in visited:
+                    visited.add(node)
+                    heappush(cur, (dist(node), node))
 
-print(search())
+partOne = search(start, end, 0)
+print(partOne)
+partTwo = search(start, end, search(end, start, partOne))
+print(partTwo)