Skip to content

Instantly share code, notes, and snippets.

@le0pard
Created January 6, 2012 18:40
Show Gist options
  • Select an option

  • Save le0pard/1571839 to your computer and use it in GitHub Desktop.

Select an option

Save le0pard/1571839 to your computer and use it in GitHub Desktop.
Erlang factorial
-module(recursive).
-export([fac/1, tail_fac/1]).
fac(N) when N == 0 -> 1;
fac(N) when N > 0 -> N*fac(N-1).
tail_fac(N) -> tail_fac(N,1).
tail_fac(0,Acc) -> Acc;
tail_fac(N,Acc) when N > 0 -> tail_fac(N-1,N*Acc).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment