Skip to content

Instantly share code, notes, and snippets.

@kosugi
Last active April 3, 2016 07:52
Show Gist options
  • Select an option

  • Save kosugi/1fc2c8bb20feda47cef1 to your computer and use it in GitHub Desktop.

Select an option

Save kosugi/1fc2c8bb20feda47cef1 to your computer and use it in GitHub Desktop.
https://twitter.com/kosugi/status/710762099954221056 の清書 (+ 配列で返すようにした版)
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
(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))))
@kosugi
Copy link
Author

kosugi commented Mar 18, 2016

配列じゃなくてリストな.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment