summaryrefslogtreecommitdiff
path: root/061.py
blob: d9688e1fa38f6ed2e3a59a19965a50e70a745562 (plain)
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

import sys

triangle = set([ n*(n+1)/2 for n in range(45,141) ])
square = set([ n*n for n in range(32,99) ])
pentagonal = set([ n*(3*n-1)/2 for n in range(26,82) ])
hexagonal = set([ n*(2*n-1) for n in range(23,71) ])
heptagonal = set([ n*(5*n-3)/2 for n in range(21,64) ])
octagonal = set([ n*(3*n-2) for n in range(19,59) ])

whole = set(triangle | square | pentagonal | hexagonal | heptagonal | octagonal)


def check_cond(testset):
	check = 0
	for e in testset:
		if e in octagonal:
			check |= 1
		elif e in heptagonal:
			check |= 2
		elif e in hexagonal:
			check |= 4
		elif e in pentagonal:
			check |= 8
		elif e in square:
			check |= 16
		elif e in triangle:
			check |= 32
	return check == 63

for i0 in whole:
	t0 = i0 % 100
	tail0 = [ n for n in whole if t0*100 < n < (t0+1)*100 ]
	for i1 in tail0:
		t1 = i1 % 100
		tail1 = [ n for n in whole if t1*100 < n < (t1+1)*100 ]
		for i2 in tail1:
			t2 = i2 % 100
			tail2 = [ n for n in whole if t2*100 < n < (t2+1)*100 ]
			for i3 in tail2:
				t3 = i3 % 100
				tail3 = [ n for n in whole if t3*100 < n < (t3+1)*100 ]
				for i4 in tail3:
					t4 = i4 % 100
					tail4 = [ n for n in whole if t4*100 < n < (t4+1)*100 ]
					for i5 in tail4:
						if i5 % 100 != i0 / 100:
							continue
						s = set([i0, i1, i2, i3, i4, i5])
						if len(s) == 6 and check_cond(s):
							print sum(s)
							sys.exit(0)