Skip to content

Instantly share code, notes, and snippets.

@jadeallenx
Created September 6, 2012 16:00
Show Gist options
  • Save jadeallenx/3657830 to your computer and use it in GitHub Desktop.
Save jadeallenx/3657830 to your computer and use it in GitHub Desktop.
Fizzbuzz for Erlang
-module(fizzbuzz).
-export([t/0, t/1]).
t() ->
t(100).
t(Limit) when Limit > 0 ->
fizzbuzz(lists:seq(1, Limit));
t(_Limit) ->
erlang:error(badarg).
fizzbuzz([H | T]) ->
fizzbuzz({H rem 3, H rem 5}),
fizzbuzz(T);
fizzbuzz([]) ->
io:format("done~n");
fizzbuzz({0,0}) ->
io:format("fizzbuzz~n", []);
fizzbuzz({0, _}) ->
io:format("fizz~n", []);
fizzbuzz({_, 0}) ->
io:format("buzz~n", []);
fizzbuzz(_) ->
ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment