Created
March 7, 2014 17:15
-
-
Save gouf/9415629 to your computer and use it in GitHub Desktop.
Haskell でFizzBuzz Ref: http://www.geocities.jp/m_hiroi/func/haskell.html#begin
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
toStr :: Int -> String | |
toStr x = if x `mod` 15 == 0 then "FizzBuzz" | |
else if x `mod` 3 == 0 then "Fizz" | |
else if x `mod` 5 == 0 then "Buzz" | |
else show x | |
fizzbuzz :: Int -> [String] | |
fizzbuzz n = map toStr[1 .. n] | |
main = do | |
print (fizzbuzz 15) | |
-- output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment