0
$\begingroup$

I know I can use the factorial number system to calculate ordered permutations of a set efficiently, given a constant length (for example, [(1, 2, 3), (1, 3, 2), ..., (3, 2, 1)]), but can it be used for non-constant lengths?

For example, my set is {a, b, c}. and the function input/outputs:

f(0) = a
f(1) = b
f(2) = c
f(3) = ab
f(4) = ac
f(5) = ba
...

That is, after the permutations of size 1, there comes permutations of size 2, then size 3, etc., to infinity.

$\endgroup$

1 Answer 1

2
$\begingroup$

If f(x) = y and the set $S$ is {a, b, c}, then given $x = 999$:

  1. subtract the set size $3!$ ($999 - 3! = 993$) to "complete" all permutations of size 1
  2. repeat this with $4!$ ($993 - 4! = 969$) to "complete" all permutations of size 2
  3. then $5!$, $969 - 5! = 849$
  4. then $849 - 6! = 129$

since we repeated 4 times, we have completed all permutations up to size 4.

This means that $999$ is for a permutation of size 5. You can now use the factorial number system with $x = 129$ to calculate ordered permutations of a set of a constant size ($5$).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.