Skip to content

Commit 30efc30

Browse files
author
Sagar Shiroya
authored
Update garage.py
1 parent 29debf3 commit 30efc30

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

array/garage.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
# Each step swap with 0 only.
1818

1919

20-
def count_moves(beg,end):
20+
def garage(beg, end):
2121
i = 0
22-
count = 0
22+
moves = 0
2323
while beg != end:
2424
if beg[i] != 0 and beg[i] != end[i]:
25-
current_car = beg[i]
26-
empty_slot = beg.index(0)
25+
car = beg[i]
26+
empty = beg.index(0)
2727
final_pos = end.index(beg[i])
28-
if empty_slot != final_pos:
29-
beg[final_pos], beg[empty_slot] = beg[empty_slot], beg[final_pos]
28+
if empty != final_pos:
29+
beg[final_pos], beg[empty] = beg[empty], beg[final_pos]
3030
print beg
31-
empty_slot = beg.index(0)
32-
beg[beg.index(current_car)], beg[empty_slot] = beg[empty_slot], beg[beg.index(current_car)]
31+
empty = beg.index(0)
32+
beg[beg.index(car)], beg[empty] = beg[empty], beg[beg.index(car)]
3333
print beg
34-
count += 2
34+
moves += 2
3535
else:
36-
beg[beg.index(current_car)], beg[empty_slot] = beg[empty_slot], beg[beg.index(current_car)]
36+
beg[beg.index(car)], beg[empty] = beg[empty], beg[beg.index(car)]
3737
print beg
38-
count += 1
38+
moves += 1
3939
i += 1
4040
if i == len(beg):
4141
i = 0
42-
return count
42+
return moves
4343

4444

4545
initial = [1,2,3,0,4]

0 commit comments

Comments
 (0)