-
Notifications
You must be signed in to change notification settings - Fork 0
/
p61.py
134 lines (106 loc) · 2.59 KB
/
p61.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import math
array3 = []
array4 = []
array5 = []
array6 = []
array7 = []
array8 = []
for n in range(1, 20000):
if (n*(n+1))/2 < 10000 and (n*(n+1))/2 >= 1000:
array3.append((n*(n+1))/2)
if n*n < 10000 and n*n >= 1000:
array4.append(n*n)
if (n*(3*n-1))/2 < 10000 and (n*(3*n-1))/2 >= 1000:
array5.append((n*(3*n-1))/2)
if n*(2*n-1) < 10000 and n*(2*n-1) >= 1000:
array6.append(n*(2*n-1))
if (n*(5*n-3))/2 < 10000 and (n*(5*n-3))/2 >= 1000:
array7.append((n*(5*n-3))/2)
if n*(3*n-2) < 10000 and n*(3*n-2) >= 1000:
array8.append(n*(3*n-2))
nodes = []
for i in array3:
nodes.append([i,1])
for i in array4:
nodes.append([i,2])
for i in array5:
nodes.append([i,3])
for i in array6:
nodes.append([i,4])
for i in array7:
nodes.append([i,5])
for i in array8:
nodes.append([i,6])
#print nodes
edges = []
for i in nodes:
for j in nodes:
if str(i[0])[2:4] == str(j[0])[0:2] and i[1] != j[1]:
edges.append([i, j])
#print edges
triples = []
for i in edges:
for j in edges:
if i[1] == j[0] and j[1][1] != i[0][1]:
cur = []
cur.append(i[0])
cur.append(i[1])
cur.append(j[1])
if cur not in triples:
triples.append(cur)
print triples
print len(triples)
quadruples = []
for i in triples:
for j in edges:
if i[2] == j[0] and j[1][1] != i[0][1] and j[1][1] != i[1][1] and j[1][1] != i[2][1]:
cur = []
cur.append(i[0])
cur.append(i[1])
cur.append(i[2])
cur.append(j[1])
if cur not in quadruples:
quadruples.append(cur)
print quadruples
print len(quadruples)
quintuples = []
for i in quadruples:
for j in edges:
if i[3] == j[0] and j[1][1] != i[0][1] and j[1][1] != i[1][1] and j[1][1] != i[2][1] and j[1][1] != i[3][1]:
cur = []
cur.append(i[0])
cur.append(i[1])
cur.append(i[2])
cur.append(i[3])
cur.append(j[1])
if cur not in quintuples:
quintuples.append(cur)
print quintuples
print len(quintuples)
sextuples = []
for i in quintuples:
for j in edges:
if i[4] == j[0] and j[1][1] != i[0][1] and j[1][1] != i[1][1] and j[1][1] != i[2][1] and j[1][1] != i[3][1] and j[1][1] != i[4][1]:
if str(j[1][0])[2:4] == str(i[0][0])[0:2]:
cur = []
cur.append(i[0])
cur.append(i[1])
cur.append(i[2])
cur.append(i[3])
cur.append(i[4])
cur.append(j[1])
if cur not in sextuples:
sextuples.append(cur)
print sextuples
print len(sextuples)
for i in sextuples:
print i[0][0] + i[1][0] + i[2][0] + i[3][0] + i[4][0] + i[5][0]
# triples = []
# for i in pairs:
# for j in pairs:
# if i[1] == j[0] and j[1][1] != i[0][1]:
# cur = i
# cur.append(j[1])
# print "cur", cur
# print triples
# print len(pairs)