我对实现Fannkuch的指令感到困惑。
指令:http://www.haskell.org/haskellwiki/Shootout/Fannkuch
在“计算翻转次数,这里是5”之后,我不知所措。
哇,是的,这不是最好的算法描述 :)
我的理解是他们希望你执行以下操作:
fannkuch(n) { int maxFlips = 0, printCount = 0; 遍历[1..n]的排列p { maxFlips = max(maxFlips, flipCount(p)); 如果(printCount++ < 30) 打印排列(p); } 打印(maxFlips); }
flipCount(p) { int count = 0; 当(p[0] != 1)时 { 反转(p, p + p[0]); count++; } 返回count; }