Cody

Problem 42495. N-th permutation.

Let write some permutations of positive integers.

    1:    1 2 3 4 5 6 ...
    2:    2 1 3 4 ...
    3:    1 3 2 4 ...
    4:    2 3 1 4 ...
    5:    3 1 2 4 ...
    6:    3 2 1 4 ...
   25:    1 2 3 5 4 ...
  120:    5 4 3 2 1 6 7 ...

Given an index, find appropriate permutation and truncate sorted part on the right side.

example:

323:    3 5 1 6 4 2 7 8 9 10 ...
>> n = 323;
>> whichperm(n)
ans = 
       3 5 1 6 4   

See also: 42494

Solution Stats

75.0% Correct | 25.0% Incorrect
Last solution submitted on Dec 11, 2018