fork download
  1. // written in the D programming language
  2. import std.algorithm;
  3. import std.array;
  4. import std.random;
  5. import std.range;
  6. import std.stdio;
  7.  
  8. void main ()
  9. {
  10. immutable int n = 4;
  11. immutable int steps = n ^^ n;
  12. int [n] p;
  13. int [int [n]] d;
  14. foreach (step; 0..steps)
  15. {
  16. p[] = n.iota.array;
  17. int v = step;
  18. foreach (i; 0..n)
  19. {
  20. int j = v % n;
  21. v /= n;
  22. swap (p[i], p[j]);
  23. }
  24. d[p] += 1;
  25. }
  26. writefln ("%(%s %s\n%)", d);
  27. }
  28.  
Success #stdin #stdout 0s 2708KB
stdin
Standard input is empty
stdout
[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