diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2010-10-09 20:45:41 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2014-08-31 20:33:42 +0200 |
| commit | 2b5ace15757e3563334effbb69da837121a59f8f (patch) | |
| tree | d0c9a8e8f73361f4422d967f2db19c0a566196a8 | |
| parent | 82333e467eaf8282894b4cf6f2bb1ac4d29aab6e (diff) | |
projecteuler solution 061
| -rw-r--r-- | src/projecteuler/061.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/projecteuler/061.py b/src/projecteuler/061.py new file mode 100644 index 0000000..d9688e1 --- /dev/null +++ b/src/projecteuler/061.py @@ -0,0 +1,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) + |
