Prolog; try to make fibonacci more effective?
This logic programming is really making a lap dance on my imperative programming skills. This is homework, so please just don't drop me the answer. This is what I have: fibo(N,1) :- N < 2, !. fibo(N,R) :- N1 is N-1, N2 is N-2, fibo(N1,R1), fibo(N2,R2), R is R1+R2. I'm suppose to make another function that looks like this; fib(N,Value,LastValue) . N is the n'th number, and value is the return value. I don't understand how I can rewrite this using accumulation. And since it counts backwards I don't see how it can "know" a last value before it calculates anything. :s Any input is appreciated. I