poetix

this time for sure

Numbers in Haskell

import List

import Random

shuffleWith :: IO [Int]

shuffleWith = randomIO >>= seed -> return $ randoms (mkStdGen seed)

shuffle :: (Ord a) => [a] -> IO [a]

shuffle xs = shuffleWith >>= nums -> return $ (map snd . sort . zip nums) xs

getInt :: IO Int

getInt = do line <- getLine

return (read line :: Int)

play :: [Int] -> Int -> IO ()

play numbers steps = do

putStrLn $ (unwords . map show) numbers

putStr "Reverse how many? "

flipCount <- getInt

let numbers' = (reverse . take flipCount) numbers ++ (drop flipCount numbers)

if numbers' == sort numbers

then putStrLn $ "Done! That took you " ++ (show steps) ++ " steps."

else play numbers' (steps + 1)

main :: IO ()

main = do

numbers < - shuffle [1..9]

play numbers 1