module CardShuffle where cut xs = splitAt n xs where n = length xs `div` 2 riffle (x:xs, y:ys) = x : y : riffle (xs,ys) riffle (xs , ys) = xs ++ ys shuffle = riffle . cut apply n f = if n==0 then id else f . apply (n-1) f count f x = 1 + ch (f x) where ch y = if x==y then 0 else 1 + ch (f y) counts = map (count shuffle) [[1..n] | n <- [1..]] :: [Int] row (i,n) = show i ++ "\t" ++ show n ++ ":\t" ++ take n (repeat '#') graph n = mapM_ (putStrLn . row) (zip [1..n] counts) graph' n = mapM_ (putStrLn . row) (zip [0,2..n] (evens counts)) evens (x:_:xs) = x : evens xs evens xs = xs --------------------------------- rank = ("A23456789XJQK" !!) suit = (["♦","♣","♥","♠"] !!) red s = "\ESC[31m" ++ s ++ "\ESC[0m" card n = (if even (n `div` 13) then red else id) (rank r : suit s) where (s,r) = n `divMod` 13 -- where (r,s) = n `divMod` 4 prt = unwords . map card deck, six :: [Int] deck = [0..51] six = [0..23] try n cs = do putStr (show n ++ ":\t") putStrLn (prt cs) while (n > 0) (try (n-1) (shuffle cs)) run cs = do putStr ("\n\t" ++ prt cs) c <- getLine while (c /= "q") (run (shuffle cs)) while b p = if b then p else return ()