Moved problems till e045.py to Python 2.
This commit is contained in:
20
python/e044.py
Normal file
20
python/e044.py
Normal file
@@ -0,0 +1,20 @@
|
||||
def pentagonal(n):
|
||||
return n * (3 * n - 1) // 2
|
||||
|
||||
|
||||
def euler_044():
|
||||
n = 10000
|
||||
p = [pentagonal(n) for n in range(1, n)]
|
||||
p_set = set(p)
|
||||
for i in range(1, n):
|
||||
for j in range(i + 1, n):
|
||||
if p[i - 1] + p[j - 1] in p_set and p[j - 1] - p[i - 1] in p_set:
|
||||
d = pentagonal(j) - pentagonal(i)
|
||||
s = d
|
||||
# print("i = {}, j = {}, d = {}.".format(i, j, d))
|
||||
return s
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("e044.py: " + str(euler_044()))
|
||||
assert(euler_044() == 5482660)
|
||||
Reference in New Issue
Block a user