Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Divmod solution in Clear category for Reversed Permutation Index by sMiTeOne
from math import factorial
def reversed_permutation_index(length: int, index: int) -> tuple[int]:
index -= 1
permutation = []
numbers = list(range(length))
for x in range(length):
number, index = divmod(index, factorial(length-x-1))
permutation.append(numbers.pop(number))
return tuple(permutation)
Jan. 5, 2022
Comments: