-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_23_b.py
81 lines (71 loc) · 1.46 KB
/
puzzle_23_b.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
73
74
75
76
77
78
79
80
81
import sys
#inpt = '389125467'
inpt = '792845136'
cups = list(inpt)
mx = 1000000
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))
for i in range(10,mx+1):
cups.append(str(i))
current = 0
moves = 10000000
mcount = 0
while mcount < moves:
if mcount%1000 == 0:
print(mcount)
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')
if start == len(cups) -1:
print(cups[0])
print(cups[1])
ans = int(cups[0]) * int(cups[1])
else:
print(cups[start+1])
print(cups[start+2])
ans = int(cups[start+1])*int(cups[start+2])
print(ans)