diff --git a/imp/math/numbers.py b/imp/math/numbers.py new file mode 100644 index 0000000..f414ff0 --- /dev/null +++ b/imp/math/numbers.py @@ -0,0 +1,16 @@ +from imp.math.primefac import factors + +def divisors(n: int) -> int: + ''' + Returns the proper divisors of an integer n. + Also called the "aliquot parts" of n. + ''' + pf = factors(n) + for (prime, multiplicity) in pf: + + +def aliquots(n: int) -> int: + return proper_divisors(n) + +def amicable(n: int) -> int: + sum(proper_divisors()) diff --git a/imp/math/util.py b/imp/math/util.py index e6c160d..69631c6 100644 --- a/imp/math/util.py +++ b/imp/math/util.py @@ -1,2 +1,8 @@ +from itertools import chain, combinations + def digits(n: int) -> int: return len(str(n)) + +def powerset(iterable): + s = list(iterable) + return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))