Skip to content

Instantly share code, notes, and snippets.

@ramirez7
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save ramirez7/8921289 to your computer and use it in GitHub Desktop.

Select an option

Save ramirez7/8921289 to your computer and use it in GitHub Desktop.
fizzCases = [(3, "Fizz"), (5, "Buzz"), (7, "Baz")]
fizzBuzz :: Int -> String
fizzBuzz n = case (foldl fizzBuzzify "" fizzCases) of
"" -> show n
s -> s
where
fizzBuzzify acc (i, s) = if ((n `mod` i) == 0) then acc ++ s else acc
-- map fizzBuzz [1..100] will do the correct behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment