Skip to content

Instantly share code, notes, and snippets.

@Chirimen-Jako
Last active August 24, 2019 17:33
Show Gist options
  • Save Chirimen-Jako/51045f67aa40df78922c2dc928fcb1c3 to your computer and use it in GitHub Desktop.
Save Chirimen-Jako/51045f67aa40df78922c2dc928fcb1c3 to your computer and use it in GitHub Desktop.
おっぱいそんちくびんびん♪ (Haskell)
{-
おっぱい.hs
2019/07/13: initial version
Ubuntu 18.04.2 LTS (Bionic Beaver)
stack Version 2.1.3
GHC/GHCi version 8.6.5
base 4.12.0.0
random 1.1
random-shuffle 0.0.4
Dedicated to shirasu
https://gist.github.com/8q/a5331c6ef8a205b32125
-}
import System.Random (next, StdGen, newStdGen)
import System.Random.Shuffle (shuffle')
realStr = "おっぱいそんちくびんびん"
oppaiElements = [ "おっ", "ぱい", "そん", "ちく", "びん", "びん" ]
makeNumList :: StdGen -> [Int]
makeNumList gen = shuffle' [0..5] 6 gen
makeTestStr :: StdGen -> String
makeTestStr gen = concat $ map (oppaiElements !!) $ makeNumList gen
congratulations :: Int -> IO ()
congratulations count = do
putStr "おめでとうございます!\x20"
putStrLn $ concat ["あなたは", show(count), "回目に", realStr, "しました。"]
mainRecursion :: StdGen -> Int -> String -> IO ()
mainRecursion _ count testStr | testStr == realStr =
congratulations count
mainRecursion gen count _ = do
let nextCount = count + 1
nextTestStr = makeTestStr gen
(_, nextGen) = next gen
putStrLn $ concat [show(nextCount), " ", nextTestStr]
mainRecursion nextGen nextCount nextTestStr
main :: IO ()
main = do
gen <- newStdGen
mainRecursion gen 0 ""
putStrLn "end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment