Advertisement
przemko

Arytmetyka -- tablicowanie wyników

Jun 12th, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.32 KB | None | 0 0
  1. % fib.pl
  2.  
  3. :- dynamic fib/2.
  4.  
  5. fib(0, 0).
  6. fib(1, 1).
  7. fib(N, F) :-
  8.     N > 1,
  9.     N1 is N - 1,
  10.     N2 is N - 2,
  11.     fib(N1, F1),
  12.     fib(N2, F2),
  13.     F is F1 + F2,
  14.     asserta(fib(N, F)).
  15.  
  16. fib(0).
  17. fib(1).
  18. fib(X) :-
  19.     fib(0, 1, X).
  20.  
  21. fib(A, B, X) :-
  22.     S is A + B,
  23.     (   X = S
  24.     ;   fib(B, S, X)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement