Skip to content

Instantly share code, notes, and snippets.

@mrsolarius
Created March 9, 2022 09:20
Show Gist options
  • Save mrsolarius/512dda2c2f964533636a5fd445d5631e to your computer and use it in GitHub Desktop.
Save mrsolarius/512dda2c2f964533636a5fd445d5631e to your computer and use it in GitHub Desktop.
Comment faire un factoriel en erlang
% Spéc
% fact/1 renvoie le factoriel de l'argument paser en parametre
% le fact(N) est N*(N-1)*...*2*1 N appartient à N
%
% Exemple :
% > fact(3) = 6
% Analyse sur N : 2 cas
% N = 0
fact(N)->1;
% N /= 0 donc il exist P/N=P+1
%fact(N)->
% P=N-1,
% F=fact(P),
% N*F.
% Ou bien
fact(N) when N>0 -> N*fact(N-1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment