e5f4633c39
which included commits to RCS files with non-trunk default branches. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@5 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
35 lines
802 B
Plaintext
35 lines
802 B
Plaintext
|
|
/*
|
|
**********************************************************************
|
|
*
|
|
* CLP(R) Version 2.0 (Example Programs Release)
|
|
* (C) Copyright, March 1986, Monash University
|
|
*
|
|
**********************************************************************
|
|
*/
|
|
|
|
%
|
|
% Simple recursive formulation of fibonacci numbers.
|
|
% The goal ?- go shows how the definition can be used for
|
|
% both finding a a fibonacci number given its index, and finding the index
|
|
% of a given fibonacci number.
|
|
%
|
|
|
|
fib(0, 1).
|
|
fib(1, 1).
|
|
fib(N, X1 + X2) :-
|
|
N > 1,
|
|
fib(N - 1, X1),
|
|
fib(N - 2, X2).
|
|
|
|
go:- fib(10, Z),
|
|
printf("forward: fib(10) = %d\n",[Z]),
|
|
fib(Y, Z),
|
|
printf("backward: fib(%d) = %d\n",[Y,Z]).
|
|
|
|
% Answer:
|
|
% forward: fib(10) = 89
|
|
% backward: fib(10) = 89
|
|
|
|
?- printf("\n>>> Sample goal: go/0\n", []).
|