Skip to content

Instantly share code, notes, and snippets.

@alskipp
Created November 21, 2015 17:49
Show Gist options
  • Save alskipp/6caf9acb845f1f7aab5f to your computer and use it in GitHub Desktop.
Save alskipp/6caf9acb845f1f7aab5f to your computer and use it in GitHub Desktop.
The FizzBuzzTizzWuzz challenge
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
@alskipp
Copy link
Author

alskipp commented Nov 21, 2015

Output sample:

1
2
Fizz
4
Buzz
Fizz
Tizz
8
FizzWuzz
Buzz
11
Fizz
13
Tizz
FizzBuzz
16
17
FizzWuzz
19
Buzz
FizzTizz
22
23
Fizz
Buzz
26
FizzWuzz
Tizz
29
FizzBuzz
31
32
Fizz
34
BuzzTizz
FizzWuzz
37
38
Fizz
Buzz
41
FizzTizz
43
44
FizzBuzzWuzz
46
47
Fizz
Tizz
Buzz
…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment