factorial( N, NFact ) :-
( N > 0 ->
factorial( N, 1, NFact )
;
N =:= 0,
NFact is 1
).
factorial( 1, Acc, Acc ) :- !.
factorial( N, Acc, NFact ) :-
NxAcc is Acc * N,
NxN is N - 1,
factorial( NxN, NxAcc, NFact ).
/*
factorial( N, Acc, NFact ) :-
( N > 1 ->
NxAcc is Acc * N,
NxN is N - 1,
factorial( NxN, NxAcc, NFact )
;
NFact is Acc
).
*/