Fibonacci sequence: Difference between revisions

Content deleted Content added
Added solution for Action!
Line 9,525: Line 9,525:
=== Efficient implementation ===
=== Efficient implementation ===
<lang Prolog>
<lang Prolog>
% John Devou: 26-Nov-2021
% Efficient program to calculate n-th Fibonacci number.
% Efficient program to calculate n-th Fibonacci number.
% Works fast for n ≤ 1 000 000 000.
% Works fast for n ≤ 1 000 000 000.
Line 9,537: Line 9,538:
fib(N,F):- b(N,[],Bs), f(Bs,0,1,2,F), !.
fib(N,F):- b(N,[],Bs), f(Bs,0,1,2,F), !.
</lang>
</lang>
{{out}}
Regarding performance:
<pre>
<pre>
?- time(fib(30,X)).
?- time(fib(30,X)).