[Haskell-cafe] Re: Progress on shootout entries

Josh Goldfoot j_goldfoot at yahoo.com
Tue Jan 3 22:00:16 EST 2006

Keep in mind that the shootout requires that the first 30 permutations printed out by the Fannkuch benchmark to be exactly those given in the "example."  Any other order of permutations gets your code labeled "Error" by the shootout administrators.  See the discussion here:


The version of Fannkuch on the site before I got there used a permutation function that did not comply with this requirement.  My only contribution was to translate the acceptable algorithm into Haskell.  (The inefficient flop stuff and the other errors were not my fault, I swear!)  The resulting (slow) code can definitely be sped up, but unfortunately the shootout benchmark favors imperative languages (and impure functional languages, I guess).

I suppose we could have two permutation-generating functions:  One used only to generate the first 30 required by the benchmark, and another that is actually used to calculate the fannkuch value.  It's not clear how the shootout rule-lawyers would look that.  It seems to violate the "same way" rule.

I was able to significantly speed up the code by replacing the flip function with a function that relies entirely on pattern matching (no splitAts or reverses).  It looks ugly, though:

mangle list@(1:xs) = list
mangle (2:x2:xs) = x2:2:xs
mangle (3:x2:x3:xs) = x3:x2:3:xs
... and so on.

More information about the Haskell-Cafe mailing list