Created
May 19, 2015 16:23
-
-
Save omegahm/8feb8270b1969a2d2dd3 to your computer and use it in GitHub Desktop.
FizzBuzz in Elixir
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 fizzbuzz(n) do | |
whichfizz(rem(n, 3), rem(n, 5), n) | |
end | |
defp whichfizz(0, 0, _), do: "FizzBuzz" | |
defp whichfizz(0, _, _), do: "Fizz" | |
defp whichfizz(_, 0, _), do: "Buzz" | |
defp whichfizz(_, _, n), do: n | |
end | |
IO.inspect Enum.map(1..100, &FizzBuzz.fizzbuzz/1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment