Skip to content

Instantly share code, notes, and snippets.

@spiegela
Created October 21, 2013 02:21
Show Gist options
  • Select an option

  • Save spiegela/7077808 to your computer and use it in GitHub Desktop.

Select an option

Save spiegela/7077808 to your computer and use it in GitHub Desktop.
Fizzbuzz implemented with tail-recursion in erlang.
-module(fizzbuzz).
-compile(export_all).
run() ->
run(lists:seq(1,100), []).
run([], Acc) ->
lists:reverse(Acc);
run([H|T], Acc) ->
run(T, [print_string(H)|Acc]).
print_string(X) when X rem 15 =:= 0 ->
"FizzBuzz";
print_string(X) when X rem 3 =:= 0 ->
"Fizz";
print_string(X) when X rem 5 =:= 0 ->
"Buzz";
print_string(X) ->
integer_to_list(X).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment