Skip to content

Instantly share code, notes, and snippets.

@tommyip
Created August 9, 2016 11:16
Show Gist options
  • Save tommyip/8b2c6787081d79a7d9653675d8e68e4f to your computer and use it in GitHub Desktop.
Save tommyip/8b2c6787081d79a7d9653675d8e68e4f to your computer and use it in GitHub Desktop.
FizzBuzz test with no conditional statement in Erlang
-module(fizzbuzz).
-export([fizzbuzz/0]).
fizzbuzz() -> N = 1, fizzbuzz({N rem 3, N rem 5, N}).
fizzbuzz({N3, N5, N}) when N =< 100 ->
case {N3, N5, N} of
{0, 0, _} -> io:format("FizzBuzz~n");
{0, _, _} -> io:format("Fizz~n");
{_, 0, _} -> io:format("Buzz~n");
{_, _, N} -> io:format("~w~n", [N])
end,
fizzbuzz({(N+1) rem 3, (N+1) rem 5, (N+1)});
fizzbuzz({_, _, _}) -> finished.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment