Created
November 21, 2015 17:49
-
-
Save alskipp/6caf9acb845f1f7aab5f to your computer and use it in GitHub Desktop.
The FizzBuzzTizzWuzz challenge
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 Data.Monoid | |
import Control.Applicative | |
import Data.Maybe | |
main = mapM_ putStrLn $ mapMaybe fizzy [1..315] | |
fizzy :: Int -> Maybe String | |
fizzy n = fizz <> buzz <> tizz <> wuzz <|> pure (show n) | |
where | |
fizz = modReplace 3 "Fizz" | |
buzz = modReplace 5 "Buzz" | |
tizz = modReplace 7 "Tizz" | |
wuzz = modReplace 9 "Wuzz" | |
modReplace m x = if n `mod` m == 0 then Just x else Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output sample: