Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %fibonacii(1,1):-!.
- %fibonacii(N,R):- fibonacii(N,R,[1,1],2).
- %fibonacii(N,R,[R|_],N):-!.
- %fibonacii(N,R,[X1,X2|Ost],X):-N>X,Xp1 is X+1,B is X1+X2,fibonacii(N,R,[B,X1,X2|Ost],Xp1).
- %Pologicko resenie
- fibonacii(1,1):-!.
- fibonacii(N,R):- fibonacii(N,R,1,1,2).
- fibonacii(N,R,R,_,N):-!.
- fibonacii(N,R,X1,X2,X):-N>X,Xp1 is X+1,B is X1+X2,fibonacii(N,R,B,X1,Xp1).
- % sekogas e lista od listi [[a,b,c],[d],[e,f],...]
- izramni_simple([L],L):-!.
- izramni_simple([Pl|Ol],R):- izramni_simple(Ol,Rr),merge(Pl,Rr,R).
- e_lista([]).
- e_lista([_|_]).
- merge([],L2,L2):-!.
- merge([X|Ost],L2,[X|Ost1]):-merge(Ost,L2,Ost1).
- izramni([],[]).
- izramni([Prv_clen|Ol],R):-
- izramni(Ol,Rr),
- (
- e_lista(Prv_clen),
- izramni(Prv_clen,Rr2),
- merge(Rr2,Rr,R),!
- ;
- R=[Prv_clen|Rr]
- ).
- test_izramni:-
- izramni([1,2,3],[1,2,3]),
- izramni([[[[1]]],2,3,[4,[5,[6],7,[8,9,[10,11],[12]]],13],14],[1,2,3,4,5,6,7,8,9,10,11,12,13,14]),
- not(izramni([[[[1]]],2,3,[4,[5,[6],7,[8,9,[10,11],[12]]],13],14],[1,2,3,4,5,6,7,8,9,10,11,12,11,14])).
- test_fib :-
- fibonacii(1,1),
- fibonacii(2,1),
- fibonacii(3,2),
- fibonacii(4,3),
- not(fibonacii(1,2)),
- not(fibonacii(2,2)),
- not(fibonacii(3,3)),
- not(fibonacii(4,5)),
- not(fibonacii(3,1)),
- not(fibonacii(4,2)),
- fibonacii(5,5),
- fibonacii(6,8),
- fibonacii(33 , 3524578),
- fibonacii(40 , 102334155),
- fibonacii(27 , 196418).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement