Created
October 18, 2012 13:55
-
-
Save msysyamamoto/3911971 to your computer and use it in GitHub Desktop.
会話できる人工知能のプログラム (Haskell)
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 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