Created
March 21, 2016 12:01
-
-
Save nabe256/4a1a33d0467f89e7fcbe 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 | |
main = do | |
gen1 <- getStdGen | |
let rand = getRandom gen1 | |
print . showKiyoshi . getKiyoshi $ rand | |
text :: [String] | |
text = ["zun", "doko", "kiyoshi"] | |
terminator :: [Int] | |
terminator = [0,0,0,0,1] | |
getRandom :: StdGen -> [Int] | |
getRandom = randomRs (0,1) | |
getNth :: Int -> [a] -> [a] | |
getNth n = take (n+5) | |
findMatch :: Int -> [Int] -> Int | |
findMatch n list = if drop n (getNth n list) == terminator | |
then n | |
else findMatch (n+1) list | |
showText :: Int -> String | |
showText n = text!!n | |
getKiyoshi :: [Int] -> [Int] | |
getKiyoshi list = getNth (findMatch 0 list) list | |
showKiyoshi :: [Int] -> [String] | |
showKiyoshi list = map showText (list ++ [2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment