Skip to content

Instantly share code, notes, and snippets.

@alskipp
Created November 21, 2015 17:49
Show Gist options
  • Select an option

  • Save alskipp/6caf9acb845f1f7aab5f to your computer and use it in GitHub Desktop.

Select an option

Save alskipp/6caf9acb845f1f7aab5f to your computer and use it in GitHub Desktop.

Revisions

  1. alskipp created this gist Nov 21, 2015.
    14 changes: 14 additions & 0 deletions FizzBuzzTizzWuzz.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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