-
-
Save zloyrusskiy/b189e2f1f2bfdc946714067ab2dbaf5a to your computer and use it in GitHub Desktop.
elixir fizzbuzz
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 solve(n) when n > 100, do: nil | |
def solve(n) do | |
IO.puts calc(n) | |
:timer.sleep(50) | |
solve(n + 1) | |
end | |
defp calc(n) do | |
cond do | |
rem(n, 15) == 0 -> "FizzBuzz" | |
rem(n, 3) == 0 -> "Fizz" | |
rem(n, 5) == 0 -> "Buzz" | |
true -> n | |
end | |
end | |
end | |
Fizzbuzz.solve(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment