Created
November 12, 2019 21:19
-
-
Save bjvoth/28b003a8df4b3061fb12ae81a6ca84ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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