Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (14 sloc) 279 Bytes
-module(factorial).
-export([compute/1, compute2/1]).
compute(N) when N < 2 ->
1;
compute(N) ->
compute(N - 1) * N.
% attempt tail-recursion
compute2(N) ->
compute2(N, 1).
compute2(N, Acc) when N < 2 ->
Acc;
compute2(N, Acc) ->
compute2(N - 1, Acc * N).
% memoize?