Skip to content

Instantly share code, notes, and snippets.

@msysyamamoto
Created October 18, 2012 13:55
Show Gist options
  • Save msysyamamoto/3911971 to your computer and use it in GitHub Desktop.
Save msysyamamoto/3911971 to your computer and use it in GitHub Desktop.
会話できる人工知能のプログラム (Haskell)
import System.Random
import System.Time
import Control.Monad.State
main :: IO ()
main = do
seed <- mkSeed
talk $ iSaid seed
mkSeed :: IO Int
mkSeed = do
(TOD _ pico) <- getClockTime
return $ fromIntegral pico
talk :: [String] -> IO ()
talk (x:xs) = do
youSaid <- getLine
if null youSaid
then return ()
else putStrLn x >> talk xs
iSaid :: Int -> [String]
iSaid seed = evalState randomWords (mkStdGen seed)
where
randomWords = do
n <- state random
ns <- randomWords
return (word n:ns)
word n = lexicon !! (abs n `mod` length lexicon)
lexicon = ["マジで", "ヤバい", "ウケルー"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment