Move sum_proper_divisors into util
This commit is contained in:
parent
32d74a1e6f
commit
dcea822a1d
9
0021.py
9
0021.py
@ -5,19 +5,14 @@ import util
|
|||||||
|
|
||||||
target = 31626
|
target = 31626
|
||||||
|
|
||||||
def sum_proper_divisors (nbr):
|
|
||||||
proper_divisors = util.divisors(nbr)[0:-1]
|
|
||||||
|
|
||||||
return reduce(lambda x, y: x + y, proper_divisors)
|
|
||||||
|
|
||||||
r = 10000
|
r = 10000
|
||||||
|
|
||||||
amicable_numbers = []
|
amicable_numbers = []
|
||||||
|
|
||||||
for i in range(1, r + 1):
|
for i in range(1, r + 1):
|
||||||
s = sum_proper_divisors(i)
|
s = util.sum_proper_divisors(i)
|
||||||
|
|
||||||
if (s != i and sum_proper_divisors(s) == i):
|
if (s != i and util.sum_proper_divisors(s) == i):
|
||||||
amicable_numbers.append(i)
|
amicable_numbers.append(i)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
5
util.py
5
util.py
@ -1,6 +1,11 @@
|
|||||||
from collections import Counter
|
from collections import Counter
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
|
def sum_proper_divisors (nbr):
|
||||||
|
proper_divisors = divisors(nbr)[0:-1]
|
||||||
|
|
||||||
|
return reduce(lambda x, y: x + y, proper_divisors)
|
||||||
|
|
||||||
def divisors(num):
|
def divisors(num):
|
||||||
result = []
|
result = []
|
||||||
def recurse(tuples, product = 1):
|
def recurse(tuples, product = 1):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user