Created
December 2, 2013 13:39
-
-
Save wlyecn/7749574 to your computer and use it in GitHub Desktop.
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
// prolog hanoi | |
move(1,X,Y,\_):-write('Move top disk from '),write(X),write(' to '), write(Y), nl. | |
move(N,X,Y,Z):-N>1,M is N-1,move(M,X,Z,Y),move(1,X,Y,\_),move(M,Z,Y,X). |
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
/* 事实 */ | |
male(baba). | |
male(yeye). | |
female(nainai). | |
female(mama). | |
male(wo). | |
father(yeye,baba). | |
father(baba,wo). | |
mother(nainai,baba). | |
mother(mama,wo). | |
/* 规则 */ | |
grandfather(X,Y):-father(X,Z),father(Z,Y). | |
grandmother(X,Y):-mother(X,Z),father(Z,Y). | |
daughter(X,Y):-parent(X,Y),female(Y). | |
son(X,Y):-parent(Y,X),male(X). | |
parent(X,Y):-father(X,Y);mother(X,Y). | |
ancestor(X,Y):-parent(X,Y). | |
ancestor(X,Y):-parent(X,Z),ancestor(Z,Y). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment