Created
January 4, 2016 10:30
-
-
Save andypike/58d8ea00c003b96808c1 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 convert_num(0, 0, _), do: "FizzBuzz" | |
def convert_num(0, _, _), do: "Fizz" | |
def convert_num(_, 0, _), do: "Buzz" | |
def convert_num(_, _, n), do: n | |
def fizz_buzz(n) do | |
convert_num rem(n, 3), rem(n, 5), n | |
end | |
def fizzify(range) do | |
Enum.map range, &(fizz_buzz(&1)) | |
end | |
end | |
IO.inspect FizzBuzz.fizzify(1..20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's probably a better way to do this, but it's my first bit of Elixir so just happy it works 😄