Created
June 5, 2009 07:01
-
-
Save ddribin/124118 to your computer and use it in GitHub Desktop.
My first Haskell app
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
#!/usr/bin/env runghc | |
-- | Returns a Fizz Buzz string for a single number | |
toFizzBuzz :: Int -> String | |
toFizzBuzz n | |
| fizz && buzz = "FizzBuzz" | |
| fizz = "Fizz" | |
| buzz = "Buzz" | |
| otherwise = show n | |
where fizz = n `mod` 3 == 0 | |
buzz = n `mod` 5 == 0 | |
-- | Returns a list of Fizz Buzz strings for a list of numbers | |
fizzBuzz :: [Int] -> [String] | |
fizzBuzz = map toFizzBuzz | |
main = putStr $ unlines $ fizzBuzz [1..100] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment