주어진 사람이 두 번째 조상의 조상인지 확인하는 작은 프롤로그 프로그램을 작성해야합니다. 사람이 다른 사람의 조상 인 경우프롤로그와 조상의 관계
mother(tim, anna).
mother(anna, fanny).
mother(daniel, fanny).
mother(celine, gertrude).
father(tim, bernd).
father(anna, ephraim).
father(daniel, ephraim).
father(celine, daniel).
parent(X,Y) :- mother(X,Y).
parent(X,Y) :- father(X,Y).
테스트 쉽습니다 : 이이 사실과 규칙이
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
하지만 지금은 (X, Y를하는 방법의 조상을 작성해야, Z)는 두 사람 사이의 관계를 인쇄합니다. 이 모양은 다음과 같아야합니다.
?- ancestor(ephraim, tim, X).
false.
?- ancestor(tim, ephraim, X).
X = father(mother(tim)).
그리고 이것이 문제입니다. 어떻게해야 할 지 모르겠습니다.
"Adapt": "수정"이라고 말하는 정중 한 방법입니다. –