Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Created January 3, 2018 08:27
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 scrubmx/5d3bd044ae7a56c35bfc94acbb313976 to your computer and use it in GitHub Desktop.
Save scrubmx/5d3bd044ae7a56c35bfc94acbb313976 to your computer and use it in GitHub Desktop.
FizzBuzz in Elixir
defmodule FizzBuzz do
def print do
Enum.each(1..100, &FizzBuzz.print/1)
end
def print(n) do
result = cond do
divisible_by_3?(n) && divisible_by_5?(n) -> "FizzBuzz"
divisible_by_3?(n) -> "Fizz"
divisible_by_5?(n) -> "Buzz"
true -> n
end
IO.puts(result)
end
def divisible_by_3?(n) do
rem(n, 3) == 0
end
def divisible_by_5?(n) do
rem(n, 5) == 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment