Skip to content

Instantly share code, notes, and snippets.

@zloyrusskiy
Last active May 21, 2017 13:48
Show Gist options
  • Save zloyrusskiy/b189e2f1f2bfdc946714067ab2dbaf5a to your computer and use it in GitHub Desktop.
Save zloyrusskiy/b189e2f1f2bfdc946714067ab2dbaf5a to your computer and use it in GitHub Desktop.
elixir fizzbuzz
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