Created
June 20, 2015 23:23
-
-
Save zaltoprofen/13092e0a26af3e480531 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
power :: [a] -> [[a]] | |
power xs = let | |
go [] ys = ys | |
go (x:xs) ys = go xs $ map (\a -> a ++ [x]) ys ++ ys | |
in | |
go xs [[]] | |
pickRand :: RandomGen r => r -> [a] -> [a] | |
pickRand gen [] = [] | |
pickRand gen (x:xs) = let | |
r :: Double | |
(r, genN) = random gen | |
in | |
if r < 0.5 | |
then pickRand genN xs | |
else x : (pickRand genN xs) | |
printStrs :: [[Char]] -> IO () | |
printStrs xs = let | |
pr :: [[Char]] -> IO () | |
pr [] = return () | |
pr (x:[]) = putStr $ "\"" ++ x ++ "\"" | |
pr (x:xs) = do | |
_ <- putStr $ "\"" ++ x ++ "\", " | |
pr xs | |
in do | |
_ <- putStr "[" | |
_ <- pr xs | |
putStrLn "]" | |
main :: IO () | |
main = do | |
gen <- newStdGen | |
let x = pickRand gen $ power "寝る" in do | |
_ <- printStrs x | |
putStrLn $ case (length x) of | |
4 -> "寝る冪" | |
_ -> "寝る冪でない" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment