Adopted new convention from template
This commit is contained in:
parent
b0b380bdd8
commit
20893290f4
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python
|
||||||
"""
|
"""
|
||||||
Created on 05 Jan 2019
|
Created on 05 Jan 2019
|
||||||
|
|
||||||
@ -9,6 +9,8 @@ Solution for problem 23 of Project Euler
|
|||||||
https://projecteuler.net/problem=23
|
https://projecteuler.net/problem=23
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from itertools import product
|
||||||
|
|
||||||
from utils import timeit
|
from utils import timeit
|
||||||
|
|
||||||
|
|
||||||
@ -34,25 +36,27 @@ def compute():
|
|||||||
Find the sum of all the positive integers which cannot be written as the
|
Find the sum of all the positive integers which cannot be written as the
|
||||||
sum of two abundant numbers.
|
sum of two abundant numbers.
|
||||||
"""
|
"""
|
||||||
LIMIT = 28124
|
|
||||||
divisorsum = [0] * LIMIT
|
|
||||||
for i in range(1, LIMIT):
|
|
||||||
for j in range(i * 2, LIMIT, i):
|
|
||||||
divisorsum[j] += i
|
|
||||||
abundantnums = [i for (i, x) in enumerate(divisorsum) if x > i]
|
|
||||||
|
|
||||||
expressible = [False] * LIMIT
|
limit = 28124
|
||||||
for i in abundantnums:
|
divisor_sum = [0] * limit
|
||||||
for j in abundantnums:
|
for i in range(1, limit):
|
||||||
if i + j < LIMIT:
|
for j in range(i * 2, limit, i):
|
||||||
|
divisor_sum[j] += i
|
||||||
|
|
||||||
|
abundant_nums = [i for (i, x) in enumerate(divisor_sum) if x > i]
|
||||||
|
|
||||||
|
expressible = [False] * limit
|
||||||
|
for i in abundant_nums:
|
||||||
|
for j in abundant_nums:
|
||||||
|
if i + j < limit:
|
||||||
expressible[i + j] = True
|
expressible[i + j] = True
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
ans = sum(i for (i, x) in enumerate(expressible) if not x)
|
ans = sum(i for (i, x) in enumerate(expressible) if not x)
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print(f"Result for Problem 23 is {compute()}")
|
||||||
print(f"Result for Problem 23: {compute()}")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user