RosettaCodeData/Task/Topswops/Haskell/topswops-1.hs

13 lines
331 B
Haskell

import Data.List (permutations)
topswops :: Int -> Int
topswops n = maximum $ map tops $ permutations [1 .. n]
where
tops (1:_) = 0
tops xa@(x:_) = 1 + tops reordered
where
reordered = reverse (take x xa) ++ drop x xa
main =
mapM_ (putStrLn . ((++) <$> show <*> (":\t" ++) . show . topswops)) [1 .. 10]