Skip to content

Instantly share code, notes, and snippets.

@eibrahim
Created February 2, 2016 14:01
Show Gist options
  • Save eibrahim/bc13234ade2a9a991e01 to your computer and use it in GitHub Desktop.
Save eibrahim/bc13234ade2a9a991e01 to your computer and use it in GitHub Desktop.
Fizzbuzz with conditional logic
def fizzbuzz n do
_fizzbuzz 1..n
end
defp _fizzbuzz a..n do
cond do
(rem(a,3) == 0 and rem(a,5) == 0) ->
IO.puts "fizzbuzz"
(rem(a,3) == 0) ->
IO.puts "fizz"
(rem(a,5) == 0) ->
IO.puts "buzz"
true ->
IO.puts a
end
cond do
a < n ->
_fizzbuzz (a+1)..n
true -> :ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment