Skip to content

Instantly share code, notes, and snippets.

@ConnorBaker
Created October 7, 2019 17:11
Show Gist options
  • Select an option

  • Save ConnorBaker/30970316ffca6528e3c88c0ecf34a39c to your computer and use it in GitHub Desktop.

Select an option

Save ConnorBaker/30970316ffca6528e3c88c0ecf34a39c to your computer and use it in GitHub Desktop.
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