module Utils where import System.Random import Text.Read shuffle :: StdGen -> [a] -> [a] shuffle g xs = shuffle' (randoms g) xs shuffle' :: [Int] -> [a] -> [a] shuffle' _ [] = [] shuffle' (i:is) xs = let (firsts, rest) = splitAt (1 + i `mod` length xs) xs in (last firsts) : shuffle' is (init firsts ++ rest) chunksOf :: Int -> [a] -> [[a]] chunksOf n [] = [] chunksOf n xs = take n xs : chunksOf n (drop n xs) query :: Read a => String -> IO a query s = do putStrLn s l <- fmap readMaybe getLine case l of Just x -> return x Nothing -> query s