Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/dc1cf59989e0b899e728 to your computer and use it in GitHub Desktop.
Save pmarreck/dc1cf59989e0b899e728 to your computer and use it in GitHub Desktop.
My version of FizzBuzz in Elixir
defmodule FizzBuzz do
def fizzbuzz(n) when is_integer(n), do: fizzbuzz(n, {rem(n,3), rem(n,5)})
def fizzbuzz(_, {0,0}), do: :fizzbuzz
def fizzbuzz(_, {0,_}), do: :fizz
def fizzbuzz(_, {_,0}), do: :buzz
def fizzbuzz(n, {_,_}), do: n
def run(i \\ 100), do: (1..i) |> Enum.map(&fizzbuzz/1)
end
IO.inspect FizzBuzz.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment