Created
December 6, 2010 09:26
-
-
Save locks/730052 to your computer and use it in GitHub Desktop.
Prolog, miniteste 8h@06122010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p(L,L1,L2) :- length(L,C), C1 is C//2, p(L,C1,L1,L2). | |
p(L,0,[],L) :- !. | |
p([H|T],N,[H|LR],L2) :- N > 0, N1 is N-1, p(T,N1,LR, L2). | |
% a) Faça a tracagem do predicado quando é chamado da seguinte maneira: ?- p([1,2,3,4,5],L1,L2). | |
% b) Diga o que este predicado faz. Sem fazer traçagem diga o resultado da seguinte chamada: ?- p([1,30,24,56,100,33,23,12],L1,L2). | |
% c) O que aconteceria se o predicado fosse chamado da seguinte maneira: ?- p([1,2,3,4,5],[1,2,3],L2). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a) L1=[1,2] e L2=[3,4,5] | |
b) Divide a lista a meio. L1=[1,30,24,56] e L2=[100,33,32,12] | |
c) Iria responder "no". O primeiro predicado p2 falha porque o terceiro argument está instanciado e nunca irá ser []. O segundo predicado também falha devido a N ser 0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment