Skip to content

Commit 0423211

Browse files
authored
Update minimum-moves-to-move-a-box-to-their-target-location.py
1 parent e0eebcd commit 0423211

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Python/minimum-moves-to-move-a-box-to-their-target-location.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def can_reach(grid, b, p, t):
1919
if not closer:
2020
closer, detour = detour, closer
2121
p = closer.pop()
22+
if p == t:
23+
return True
2224
if p in lookup:
2325
continue
2426
lookup.add(p)
25-
if p == t:
26-
return True
2727
for dx, dy in directions:
2828
np = (p[0]+dx, p[1]+dy)
2929
if not (0 <= np[0] < len(grid) and 0 <= np[1] < len(grid[0]) and
@@ -44,11 +44,11 @@ def a_star(grid, b, p, t):
4444
f += dh
4545
closer, detour = detour, closer
4646
b, p = closer.pop()
47+
if b == t:
48+
return f
4749
if (b, p) in lookup:
4850
continue
4951
lookup.add((b, p))
50-
if b == t:
51-
return f
5252
for dx, dy in directions:
5353
nb, np = (b[0]+dx, b[1]+dy), (b[0]-dx, b[1]-dy)
5454
if not (0 <= nb[0] < len(grid) and 0 <= nb[1] < len(grid[0]) and

0 commit comments

Comments
 (0)