Skip to content

Instantly share code, notes, and snippets.

@P7h
Created February 4, 2017 15:50
Show Gist options
  • Save P7h/1a79b21aa1a9a1b17701b99c53b51c84 to your computer and use it in GitHub Desktop.
Save P7h/1a79b21aa1a9a1b17701b99c53b51c84 to your computer and use it in GitHub Desktop.

Revisions

  1. P7h created this gist Feb 4, 2017.
    25 changes: 25 additions & 0 deletions FizzBuzz.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    -- FizzBuzz in Haskell

    fizzbuzz :: Int -> String
    fizzbuzz n = if fb /= ""
    then fb
    else show n
    where fb = fizz n ++ buzz n


    fizz:: Int -> String
    fizz n | n `mod` 3 == 0 = "Fizz"
    | otherwise = ""


    buzz:: Int -> String
    buzz n | n `mod` 5 == 0 = "Buzz"
    | otherwise = ""


    main = do
    mapM_ (putStrLn) [fizzbuzz x | x <- [1..100]]


    -- ghc fizzbuzz.hs
    -- fizzbuzz.exe