Project Euler Problem#24

#python program to find the nth Lexicographic Permutations number
from itertools import permutations

def permutation(numbers, n):
    perms_list = list(permutations(numbers))
    nth_permutation=(perms_list[n-1])
    nth_num=''
    for i in nth_permutation:
        nth_num+=str(i)
    return nth_num

numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
n = 1000000

result = permutation(numbers, n)
print(result)
0
Subscribe to my newsletter

Read articles from Varjinth subramaniyan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Varjinth subramaniyan
Varjinth subramaniyan