Skip to content

Instantly share code, notes, and snippets.

@ahodroj
Created August 28, 2011 23:05
Show Gist options
  • Save ahodroj/1177359 to your computer and use it in GitHub Desktop.
Save ahodroj/1177359 to your computer and use it in GitHub Desktop.
Prolog factorial predicate
:- class('MyMath').
factorial(0,1).
factorial(N,F) :- N > 0, M is N - 1, factorial(M,Fm), F is N * Fm.
fib(0,1).
fib(1,1).
fib(N,F) :- N > 1, N1 is N - 1, N2 is N - 2, fib(N1,F1), fib(N2,F2), F is F1+F2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment