prm

From The K Language Wiki
Prm
prm x
Supported in oK, K7, K9

prm generates all permutations of its input array.

If given a number, generates all permutations of the range !x.

In oK, the permutations are represented by the rows:

 prm "ABC"
("ABC"
 "ACB"
 "BAC"
 "BCA"
 "CAB"
 "CBA")

Shakti(K7) onwards does not accept arrays as an argument, so a construct like {x@prm#x} may be used.

 {x@prm#x}@"ABC"
ABC
BAC
BCA
ACB
CAB
CBA

Shakti(K9) returns the permutations as columns:

 prm 3
0 1 1 0 2 2
1 0 2 2 0 1
2 2 0 1 1 0