The logic behind this is as follows: the recursive subselect implements the variable-bit-encoding algorithm for generating the n'th permutation of a list (essentially converting n into the factorial base); the column p is the output generated so far, a is the array items not used so far, and b is the current base. At each recursion level, one element is chosen and appended to p, removed from a, and the base decremented. Recursion ends when b=0, and that row contains the desired result.

Iteration of this subselect for values over [0..n!-1] generates all permutations.