Skip to content

Instantly share code, notes, and snippets.

@kblake
Created December 2, 2014 23:51
Show Gist options
  • Save kblake/0ab83cb9bc7714e07c93 to your computer and use it in GitHub Desktop.
Save kblake/0ab83cb9bc7714e07c93 to your computer and use it in GitHub Desktop.
Fizz Buzz in Elixir
defmodule FizzBuzz do
def compute(n) do
s = case {rem(n, 3), rem(n, 5)} do
{0, 0} -> :FizzBuzz
{0, _} -> :Fizz
{_, 0} -> :Buzz
_ -> n
end
IO.puts(s)
end
end
Enum.map(1..15, &FizzBuzz.compute/1)
# or as list comprehension:
# for i <- 1..15, do: FizzBuzz.compute(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment