factorial(0, 1). factorial(N, Fact) :- N > 0, PrevN is N - 1, factorial(PrevN, PrevFact), Fact is N * PrevFact. binom_down(N, 0, 1) :- !. binom_down(N, K, Res) :- K > 0, K < N, PrevK is K-1, PrevN is N-1, binom_down(PrevN, PrevK, PrevRes), binom_down(PrevN, K, CurRes), Res is CurRes + PrevRes. binom_down(N, N, 1) :- !. binom_down(N, K, Res) :- K =:= N, Res is 1, !. binom_down(N, K, Res) :- K> N, Res is 0, !.
Write, Run & Share Prolog code online using OneCompiler's Prolog online compiler for free. It's one of the robust, feature-rich online compilers for Prolog language. Getting started with the OneCompiler's Prolog editor is easy and fast. The editor shows sample boilerplate code when you choose language as Prolog and start coding.