Skip to content

Instantly share code, notes, and snippets.

@pasberth
Last active December 29, 2015 10:49

Revisions

  1. pasberth revised this gist Nov 26, 2013. 1 changed file with 15 additions and 12 deletions.
    27 changes: 15 additions & 12 deletions gistfile1.hs
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,20 @@
    --ちんちんっぽいことするやつ
    import System.Random
    chimpo :: String -> String
    randomString :: String -> String
    chimpo :: String -> IO String
    randomString :: String -> IO String

    chimpo c = if take 4 c == "ABCDE"
    then c ++ ("なんか終わりました" ++ (show (length c )))
    else chimpo (randomString c)
    chimpo c = do s <- randomString c
    if take 4 c == "ABCDE"
    then return $ c ++ ("なんか終わりました" ++ (show (length c )))
    else chimpo s

    randomString s = getStdRandom(randomR(0,4)) >>= \r -> case r of
    0 -> ("A" ++ s)
    1 -> ("B" ++ s)
    2 -> ("C" ++ s)
    3 -> ("D" ++ s)
    4 -> ("E" ++ s)
    randomString s = getStdRandom (randomR ((0, 4)::(Int,Int))) >>= \r -> case r of
    0 -> return ("A" ++ s)
    1 -> return ("B" ++ s)
    2 -> return ("C" ++ s)
    3 -> return ("D" ++ s)
    4 -> return ("E" ++ s)

    main = putStrLn (chimpo (randomString ""))
    main = do x1 <- randomString ""
    x2 <- chimpo x1
    putStrLn x2
  2. @haru2036 haru2036 created this gist Nov 26, 2013.
    17 changes: 17 additions & 0 deletions gistfile1.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    --ちんちんっぽいことするやつ
    import System.Random
    chimpo :: String -> String
    randomString :: String -> String

    chimpo c = if take 4 c == "ABCDE"
    then c ++ ("なんか終わりました" ++ (show (length c )))
    else chimpo (randomString c)

    randomString s = getStdRandom(randomR(0,4)) >>= \r -> case r of
    0 -> ("A" ++ s)
    1 -> ("B" ++ s)
    2 -> ("C" ++ s)
    3 -> ("D" ++ s)
    4 -> ("E" ++ s)

    main = putStrLn (chimpo (randomString ""))