Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import System.Random
- import Control.Monad.State
- type RandomMonad a = State StdGen a
- randomRState :: Random a => (a, a) -> RandomMonad a
- randomRState rt = get >>= (\(a, g) -> put g >> return a) . randomR rt
- randomBool :: RandomMonad Bool
- randomBool = randomRState (False,True)
- unfoldM :: Monad m => (a -> m a) -> (a -> Bool) -> a -> m [a]
- unfoldM f s a = do
- v <- f a
- if s v
- then return []
- else liftM (v :) (unfoldM f s v)
- whiteout :: Char -> RandomMonad Char
- whiteout c = do
- r <- randomBool
- if r
- then return c
- else return ' '
- blank :: String -> Bool
- blank = all (== ' ')
- disintegrate :: String -> RandomMonad [String]
- disintegrate = unfoldM (mapM whiteout) blank
- main :: IO ()
- main = do
- r <- getStdGen
- i <- getLine
- mapM_ putStrLn $ evalState (disintegrate i) r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement