Created
February 5, 2011 10:42
-
-
Save dan5/812360 to your computer and use it in GitHub Desktop.
Haskellでプログラムを書く勉強会#0の成果
This file contains 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
main = putStrLn $ concat $ map addln $ map fizzbuzz [1..20] | |
addln str = concat [str, "\n"] | |
fizzbuzz a = if (a `mod` 3) == 0 then "fizz" | |
else if (a `mod` 5) == 0 then "buzz" | |
else show a |
This file contains 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
main = putStrLn $ concat $ map addln $ map fizzbuzz [1..20] | |
addln str = concat [str, "\n"] | |
fizzbuzz a | (a `mod` 15) == 0 = "fizz buzz" | |
| (a `mod` 3) == 0 = "buzz" | |
| (a `mod` 5) == 0 = "buzz" | |
| otherwise = show a |
This file contains 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 | |
main = do | |
args <- getArgs | |
putStrLn $ unlines $ fizzbuzz (read $ head args) | |
fizzbuzz n = map _fizzbuzz [1..n] | |
_fizzbuzz a | (a `mod` 15) == 0 = "fizz buzz" | |
| (a `mod` 3) == 0 = "buzz" | |
| (a `mod` 5) == 0 = "buzz" | |
| otherwise = show a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment