Created
October 7, 2019 17:11
-
-
Save ConnorBaker/30970316ffca6528e3c88c0ecf34a39c to your computer and use it in GitHub Desktop.
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
| import Data.Maybe | |
| fizzBuzzList :: Int -> Maybe String | |
| fizzBuzzList n = list !! index where | |
| list = [ Just "fizzbuzz" | |
| , Nothing | |
| , Nothing | |
| , Just "fizz" | |
| , Nothing | |
| , Just "buzz" | |
| , Just "fizz" | |
| , Nothing | |
| , Nothing | |
| , Just "fizz" | |
| , Just "buzz" | |
| , Nothing | |
| , Just "fizz" | |
| , Nothing | |
| , Nothing] | |
| index = mod n 15 | |
| fizzBuzz :: Int -> String | |
| fizzBuzz n = result where | |
| maybeResult = fizzBuzzList n | |
| result = fromMaybe (show n) maybeResult | |
| main :: IO () | |
| main = mapM_ (print . fizzBuzz) [0 .. 32] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment