Permutation group operation
J, 30

I like the elegance of this:

[:A.[:{/]A.~/~i.@[


or this:

13 :'A.{/(i.x)(A.)~/y'


but they work like this:

3 f 2 5
3
12 f 8 9
17


So this is the valid entry:

([:A.[:{/i.@{.A.~/}.)".}.&gt;ARGV


Some explanations:


3 A. 0 1 2: gives the 3rd permutation of 0 1 2 (= 1 2 0)
0 1 2 (A.)~ 3: is the same but with arguments reversed
0 1 2 (A.)~/ 3 4 5 ... "applies" (A.)~ to 3 4 5 ..., so it gives the 3rd, 4th, 5th, ... permutation of 0 1 2.
A. 1 2 0: gives the order of the permutation of 1 2 0 (= 3)
i. n: gives the sequence 0 1 2 ... n-1
1 2 0 { 0 2 1 arranges 0 2 1 by 1 2 0 (= 2 1 0)