Skip to content

Instantly share code, notes, and snippets.

@bjvoth
Created November 12, 2019 21:19
Show Gist options
  • Save bjvoth/28b003a8df4b3061fb12ae81a6ca84ad to your computer and use it in GitHub Desktop.
Save bjvoth/28b003a8df4b3061fb12ae81a6ca84ad to your computer and use it in GitHub Desktop.
defmodule FizzBuzz do
def run() do
Enum.each(1..100, fn number ->
IO.puts(fizz_buzz(number))
end)
end
def fizz_buzz(n) do
cond do
is_divisible_by_3?(n) and is_divisible_by_5?(n) -> "FizzBuzz"
is_divisible_by_3?(n) -> "Fizz"
is_divisible_by_5?(n) -> "Buzz"
true -> n
end
end
def is_divisible_by_3?(n), do: rem(n, 3) == 0
def is_divisible_by_5?(n), do: rem(n, 5) == 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment