[Shootout-list] fannkuch for GHC (correction)

Greg Buchholz sleepingsquirrel@member.fsf.org
Fri, 31 Dec 2004 16:37:39 -0800 (PST)


--0-265960590-1104539859=:60521
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

   Whoops, I didn't read the description close enough.  Here's a copy of
the program with the correctly formated output.

Greg Buchholz




		
__________________________________ 
Do you Yahoo!? 
Send a seasonal email greeting and help others. Do good. 
http://celebrity.mail.yahoo.com
--0-265960590-1104539859=:60521
Content-Type: text/x-haskell; name="fannkuch.hs"
Content-Description: fannkuch.hs
Content-Disposition: inline; filename="fannkuch.hs"

-- Haskell implementation of fannkuch benchmark
-- compile with:  ghc -O2 -o fannkuch fannkuch.hs
-- Greg Buchholz

import System(getArgs)

main = do   [n] <- getArgs
            let p = permutations [1..(read n)]
            putStr $ "Pfannkuchen(" ++ n ++ ") = "
            print $ maximum $ map (flop 0) p
            
flop acc (1:xs) = acc
flop acc list@(x:xs) = flop (acc+1) mangle
    where   mangle = (reverse front) ++ back
            (front,back) = splitAt x list

permutations []         =  [[]]
permutations (x:xs)     =  [zs | ys <- permutations xs, zs <- interleave x ys ]
  where interleave x []     =  [[x]]
        interleave x (y:ys) =  [x:y:ys] ++ map (y:) (interleave x ys)

--0-265960590-1104539859=:60521--