Open the context
Choose the project folder and name the files or behavior involved.
Recover the lexicographic permutation of size zero through ten at an integer rank. Check first and last ranks and the empty permutation, rejecting Boolean values and ranks outside the factorial count.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import factorial
def unrank_permutation(size, rank):
if type(size) is not int or not 0 <= size <= 10:
raise ValueError("size 0 through 10")
if type(rank) is not int or not 0 <= rank < factorial(size):
raise ValueError("rank outside permutation count")
available, result = list(range(size)), []
for remaining in range(size,0,-1):
index, rank = divmod(rank, factorial(remaining-1))
result.append(available.pop(index))
return resultThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.