-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler44.py
More file actions
29 lines (24 loc) · 767 Bytes
/
euler44.py
File metadata and controls
29 lines (24 loc) · 767 Bytes
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
import itertools,math,time
start = time.time()
def ispent(number):
pos = (1./6.)*(1+(24*number+1)**0.5)
neg = (1./6.)*(1-(24*number+1)**0.5)
if pos == int(pos) and pos > 0:
return True
elif neg == int(neg) and neg > 0:
return True
else:
return False
pentagonals = []
for number in xrange(1,10000000):
if ispent(number):
pentagonals.append(number)
print len(pentagonals),'pents calculated in',time.time()-start,'seconds'
def pentcompare(pentagonals):
staticlist = pentagonals
choplist = pentagonals
for index in xrange(1,len(pentagonals)):
for pair in itertools.izip(staticlist,choplist[index::]):
if ispent(sum(pair)) and ispent(abs(pair[0]-pair[1])):
print abs(pair[0]-pair[1])
pentcompare(pentagonals)