Moved solutions till 35 to Python.

This commit is contained in:
2019-07-16 12:51:07 -04:00
parent f76b36c8d3
commit d94fc90600
13 changed files with 262 additions and 66 deletions

View File

@@ -1,29 +1,26 @@
from itertools import permutations
from lib_misc import permutations
def euler_024_library():
from itertools import permutations
return int("".join(list(permutations("0123456789"))[1000000 - 1]))
def permutations_(iterable):
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 n_th(generator, n):
def nth(generator, n):
for i in range(n):
next(generator)
return next(generator)
def nth_permutation(iterable, n):
""" Returns the nth permutation of the iterable. """
# XXX: Implement this!
return 0
def euler_024():
g = permutations_("0123456789")
return int(n_th(g, 1000000 - 1))
g = permutations("0123456789")
return int(nth(g, 1000000 - 1))
if __name__ == "__main__":