Download code

Jump to: navigation, search

Back to Fibonacci_numbers_(Prolog)

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

fibonacci.pl

1 fib(0, A, _, A).
2 fib(N, A, B, F) :- N1 is N - 1, Sum is A + B, fib(N1, B, Sum, F).
3 fib(N, F) :- fib(N, 0, 1, F).


fibonacci_naive.pl

1 fib(0, 0).
2 fib(1, 1).
3 fib(N, NF) :-
4     A is N - 1, B is N - 2,
5     fib(A, AF), fib(B, BF),
6     NF is AF + BF.
7