Created
August 7, 2016 19:01
-
-
Save rvcas/0c6b29e39c1cb917e8f840fe4e903b81 to your computer and use it in GitHub Desktop.
Classic Fizz Buzz with Pattern Matching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule FizzBuzz do | |
def fizzer(n), do: buzzer(rem(n, 3), rem(n, 5), n) | |
defp buzzer(0, 0, _), do: "Fizz Buzz" | |
defp buzzer(0, _, _), do: "Fizz" | |
defp buzzer(_, 0, _), do: "Buzz" | |
defp buzzer(_, _, n), do: n | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment