RosettaCodeData/Task/Topswops/D/topswops-1.d

16 lines
406 B
D

import std.stdio, std.algorithm, std.range, permutations2;
int topswops(in int n) pure @safe {
static int flip(int[] xa) pure nothrow @safe @nogc {
if (!xa[0]) return 0;
xa[0 .. xa[0] + 1].reverse();
return 1 + flip(xa);
}
return n.iota.array.permutations.map!flip.reduce!max;
}
void main() {
foreach (immutable i; 1 .. 11)
writeln(i, ": ", i.topswops);
}