LLexiNest
Workflows

Coding workflows · Lexicographic permutation unranking

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Lexicographic permutation unranking

A concrete starting point
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 result

The 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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗