or
Mathgeek
array-manipulation sorting
Now to start thinking laterally!

For an array of N distinct numbers in increasing order, there are N! ways to permute that array. Those permuted arrays can then also be sorted, prioritizing whichever array has the smallest element in the first position, then breaking ties with the second position, etc.

The input is an array and a number M with 0 <= M < N! , and the output should be, if one sorted all N! permutations of the original array, the Mth element of that list of permutations. So, M = 0 would give your original sorted array, and M=N!-1 would be the array in reverse.

| Input | Output |
|-------|--------|
|[1, 2, 3, 4], 5|[1, 4, 3, 2]|
|[1, 4, 7], 2|[4, 1, 7]|
|[3, 4, 6, 9, 10], 114|[10, 9, 3, 4, 6]|
|[1, 2, 3], 0|[1, 2, 3]|
Bubbler
# [J], 2 bytes

A.

[Try it online!][TIO-k663bb82]

[J]: http://jsoftware.com/
[TIO-k663bb82]: https://tio.run/##PY07C4NAEITr218xpBFhc@w9VBRShEAgEAikPWwtUkgK/f2X9TAWy843s49PPtlqwmVABYZg0Dpb3N7Pe77aXOcGExw8AiL5oiM6ci6qVg8tejgh@Y8RlSP0mL/rYl7roo2SY3hGYMSR0ZiNY2E/0g6dJt4kVW4DSqHYLaNXSzTVp7opxdjD8TituZgDqP4B "J – Try It Online"

Sorry for the boring answer, but this is a bulit-in function which computes the nth permutation of the given array in the increasing order.


5 A. 1 2 3 4
1 4 3 2

114 A. 3 4 6 9 10
10 9 3 4 6

Sorted Order of Arrays
Mathgeek
> an array of N distinct numbers in increasing order
Bubbler
Can we assume the elements of the array are distinct?
Mathgeek
N is inferred from array length. I like the reworked wording. Thanks!
xnor
@Mathgeek
xnor
May we take N as input as well, or does that have to be inferred from the array length?
xnor
Nice challenge! I tried cleaning up some wording. Feel free to change stuff back if you don't like it.