Skip to content

Instantly share code, notes, and snippets.

@andypike
Created January 4, 2016 10:30
Show Gist options
  • Save andypike/58d8ea00c003b96808c1 to your computer and use it in GitHub Desktop.
Save andypike/58d8ea00c003b96808c1 to your computer and use it in GitHub Desktop.
FizzBuzz in Elixir
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)
@andypike
Copy link
Author

andypike commented Jan 4, 2016

There's probably a better way to do this, but it's my first bit of Elixir so just happy it works 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment