-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_23_a.py
72 lines (61 loc) · 1.26 KB
/
puzzle_23_a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
#inpt = '389125467'
inpt = '792845136'
cups = list(inpt)
mx = 9
def pick3(crt):
three = []
if crt == len(cups) -1:
three.extend(cups[0:3])
del cups[0:3]
elif crt == len(cups) -2:
three.extend(cups[-1:])
three.extend(cups[0:2])
del cups[-1]
del cups[0:2]
elif crt == len(cups) -3:
three.extend(cups[-2:])
three.extend(cups[0:1])
del cups[-2:]
del cups[0]
else:
three.extend( cups[crt+1:crt+4])
del cups[crt+1: crt+4]
print("in pick", cups,three)
return three
def get_destn(crt,three):
print(three,crt)
label = int(cups[crt])
dest = label -1
if dest == 0:
dest = mx
while str(dest) in three:
dest -=1
if dest == 0:
dest = mx
destind = cups.index(str(dest))
print(cups,destind,dest)
return (destind,str(dest))
current = 0
moves = 100
mcount = 0
while mcount < moves:
print("\n===",current,cups)
clabel = cups[current]
three = []
three.extend(pick3(current))
current = cups.index(clabel)
(destind,destn) = get_destn(current,three)
del cups[destind]
cups.insert(destind,destn)
cups[destind+1:destind+1] = three
if destind < current:
current +=3
current +=1
if current >= len(cups):
current = 0
mcount +=1
print("****",cups)
start = cups.index('1')
lst = cups[start+1:]+cups[0:start]
print(''.join(lst))