File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 17
17
# Each step swap with 0 only.
18
18
19
19
20
- def count_moves (beg ,end ):
20
+ def garage (beg , end ):
21
21
i = 0
22
- count = 0
22
+ moves = 0
23
23
while beg != end :
24
24
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 )
27
27
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 ]
30
30
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 )]
33
33
print beg
34
- count += 2
34
+ moves += 2
35
35
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 )]
37
37
print beg
38
- count += 1
38
+ moves += 1
39
39
i += 1
40
40
if i == len (beg ):
41
41
i = 0
42
- return count
42
+ return moves
43
43
44
44
45
45
initial = [1 ,2 ,3 ,0 ,4 ]
You can’t perform that action at this time.
0 commit comments