Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Permutation Index by ssk8
from math import factorial
from typing import Tuple
def permutation_index(numbers: Tuple[int])->int:
permutation, index = list(numbers), 1
for length in range(len(permutation), 0, -1):
current = permutation.pop(0)
permutation = [x - 1 if x > current else x for x in permutation]
index += current * factorial(length - 1)
return index
Jan. 16, 2020
Comments: