Wow, yes, this is not the best description of the algorithm :).
My interpretation is that they want you to do the following:
fannkuch (n) {
int maxFlips = 0, printCount = 0;
foreach permutation p of [1..n] {
maxFlips = max (maxFlips, flipCount (p));
if (printCount ++ & lt 30) printPermutation (p);
}
print (maxFlips);
}
flipCount (p) {
int count = 0;
while (p [0]! = 1) {
reverse (p, p + p [0]);
count ++;
}
return count;
}
Gary linscott
source share