Last active
April 3, 2016 07:52
-
-
Save kosugi/1fc2c8bb20feda47cef1 to your computer and use it in GitHub Desktop.
https://twitter.com/kosugi/status/710762099954221056 の清書 (+ 配列で返すようにした版)
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 Data.Bits | |
| import System.Random | |
| zundoko :: Int -> (Int, String) | |
| zundoko n = (n, ["ズン", "ドコ"] !! n) | |
| zundokos :: StdGen -> [(Int, String)] | |
| zundokos gen0 = let (n, gen1) = randomR (0, 1) gen0 in | |
| (zundoko n) : (zundokos gen1) | |
| scan :: [(Int, String)] -> [String] | |
| scan = scan_ 2 [] | |
| where | |
| scan_ :: Int -> [String] -> [(Int, String)] -> [String] | |
| scan_ n ys ((m,y):xs) = if n == 1 then reverse $ "キヨシ" : ys else | |
| scan_ ((n + n + m) .&. 31) (y:ys) xs | |
| main :: IO () | |
| main = do | |
| gen <- newStdGen | |
| putStrLn $ unwords $ scan $ zundokos gen |
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
| (use srfi-27) | |
| (let loop ((n 9) (xs '()) (zundoko (vector "ズン" "ドコ"))) | |
| (if (= n 1) | |
| (reverse (cons "キ・ヨ・シ!" xs)) | |
| (let ((x (random-integer 2))) | |
| (loop (logand #x1f (+ n n x)) | |
| (cons (vector-ref zundoko x) xs) | |
| zundoko)))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
配列じゃなくてリストな.