// written in the D programming language
import std.algorithm;
import std.array;
import std.random;
import std.range;
import std.stdio;
void main ()
{
immutable int n = 4;
immutable int steps = n ^^ n;
int [n] p;
int [int [n]] d;
foreach (step; 0..steps)
{
p[] = n.iota.array;
int v = step;
foreach (i; 0..n)
{
int j = v % n;
v /= n;
swap (p[i], p[j]);
}
d[p] += 1;
}
writefln ("%(%s %s\n%)", d);
}
Standard input is empty
[0, 2, 1, 3] 10 [1, 0, 3, 2] 15 [0, 1, 3, 2] 10 [3, 0, 1, 2] 8 [3, 2, 0, 1] 10 [1, 2, 3, 0] 14 [2, 3, 0, 1] 11 [0, 1, 2, 3] 10 [2, 1, 0, 3] 9 [3, 1, 0, 2] 9 [0, 2, 3, 1] 14 [0, 3, 2, 1] 9 [3, 2, 1, 0] 10 [3, 0, 2, 1] 9 [3, 1, 2, 0] 8 [0, 3, 1, 2] 11 [2, 0, 1, 3] 11 [1, 3, 2, 0] 11 [1, 3, 0, 2] 11 [2, 3, 1, 0] 10 [1, 2, 0, 3] 14 [1, 0, 2, 3] 10 [2, 0, 3, 1] 11 [2, 1, 3, 0] 11