Skip to content

Instantly share code, notes, and snippets.

@nabe256
Created March 21, 2016 12:01
Show Gist options
  • Save nabe256/4a1a33d0467f89e7fcbe to your computer and use it in GitHub Desktop.
Save nabe256/4a1a33d0467f89e7fcbe to your computer and use it in GitHub Desktop.
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