Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Perfect-shuffle/Haskell/perfect-shuffle.hs
Normal file
12
Task/Perfect-shuffle/Haskell/perfect-shuffle.hs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
shuffle :: [a] -> [a]
|
||||
shuffle lst = let (a,b) = splitAt (length lst `div` 2) lst
|
||||
in foldMap (\(x,y) -> [x,y]) $ zip a b
|
||||
|
||||
findCycle :: Eq a => (a -> a) -> a -> [a]
|
||||
findCycle f x = takeWhile (/= x) $ iterate f (f x)
|
||||
|
||||
main = mapM_ report [ 8, 24, 52, 100, 1020, 1024, 10000 ]
|
||||
where
|
||||
report n = putStrLn ("deck of " ++ show n ++ " cards: "
|
||||
++ show (countSuffles n) ++ " shuffles!")
|
||||
countSuffles n = 1 + length (findCycle shuffle [1..n])
|
||||
Loading…
Add table
Add a link
Reference in a new issue