Moved solutions till 35 to Python.
This commit is contained in:
@@ -136,9 +136,10 @@ def collatz_sequence_length(n):
|
||||
|
||||
@lru_cache(maxsize=10000)
|
||||
def factorial(n):
|
||||
if n == 1:
|
||||
return 1
|
||||
return n * factorial(n - 1)
|
||||
p = 1
|
||||
for i in range(1, n + 1):
|
||||
p *= i
|
||||
return p
|
||||
|
||||
|
||||
def proper_divisors(n):
|
||||
@@ -177,3 +178,25 @@ def sum_proper_divisors(n):
|
||||
s += q
|
||||
d += 1
|
||||
return s
|
||||
|
||||
|
||||
def permutations(iterable):
|
||||
"""
|
||||
Generator that returns all permutations for the iterable.
|
||||
|
||||
Generates equivalent result to itertools.permutations.
|
||||
"""
|
||||
if not iterable:
|
||||
yield iterable
|
||||
for i in range(len(iterable)):
|
||||
elem = iterable[i:i + 1]
|
||||
rest = iterable[:i] + iterable[i + 1:]
|
||||
for ps in permutations(rest):
|
||||
yield elem + ps
|
||||
|
||||
|
||||
def gcd(a, b):
|
||||
""" Returns the greatest commond divisor of a and b. """
|
||||
if b == 0:
|
||||
return a
|
||||
return gcd(b, a % b)
|
||||
|
||||
Reference in New Issue
Block a user