Last active
January 15, 2018 09:35
-
-
Save pb10005/3457c4e08f6eea20f33dfb5662dcb04f to your computer and use it in GitHub Desktop.
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
fizzbuzz:: [Int] -> String | |
fizzbuzz xs = f xs "" | |
where | |
f [] s = s | |
f (y:ys) s = f ys (s++show(fizzbuzzfunc y)++footer) | |
fizzbuzzfunc x = header x ++ fizz x ++ buzz x | |
header x = show(x) ++ ": " | |
fizz x | mod x 3 == 0 = "fizz" | |
| otherwise = "" | |
buzz x | mod x 5 == 0 = "buzz" | |
| otherwise = "" | |
footer = "\n" | |
test:: [String]->IO() | |
test [] = putStrLn "" | |
test (x:xs) = putStrLn(x)>>= \_ -> | |
test(xs) | |
main = do | |
putStrLn "fizzbuzz in Haskell" | |
putStr $ fizzbuzz [1..30] | |
test ["a","b","c"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment