Skip to content

Instantly share code, notes, and snippets.

@jjant
Last active November 10, 2018 23:40
Show Gist options
  • Select an option

  • Save jjant/2fd35584cffb3276950e0e515622cb1b to your computer and use it in GitHub Desktop.

Select an option

Save jjant/2fd35584cffb3276950e0e515622cb1b to your computer and use it in GitHub Desktop.
module FizzBuzz where
data FizzResult
= Val Int
| Fizz
| Buzz
| FizzBuzz
deriving (Show)
divisibleBy :: Int -> Int -> Bool
divisibleBy divisor x = x `mod` divisor == 0
fizzbuzz :: Int -> FizzResult
fizzbuzz x =
case (divisibleBy 3 x, divisibleBy 5 x) of
(True, True) -> FizzBuzz
(True, False) -> Fizz
(False, True) -> Buzz
(False, False) -> Val x
-- Run fizzbuzz over every int from 1 to 100 and print the result.
main :: IO ()
main = traverse (print . fizzbuzz) [1 .. 100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment