2 ms·
That's why I like Prolog: factorial(0,F,F). factorial(N,A,F) :- N > 0, A1 is N*A, N1 is N -1, factorial(N1,A1,F). Because 90
by YeGoblynQueenne 7y ago
That's why I like Prolog:
factorial(0,F,F).
factorial(N,A,F) :-
N > 0,
A1 is N*A,
N1 is N -1,
factorial(N1,A1,F).
Because 90% of variables in 90% of the Prolog code I've ever read * are named A, B, C, D, H, I, J, K, L, M, N, P, Q, R, S, T, U, V, W, X, Y or Z. Or with an "s" (as in Xs, Ys, Zs...) to denote a list. Or a number to denote a new version (where you'd like to put a "'" but syntax doesn't let you).
Theeere you are. No need to think hard.
:dusts hands:
(Tail-recursive factorial predicate from here: https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_2.html https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_2.html)
______________
* Including my own code that I've written before reading it.