Skip to content

Instantly share code, notes, and snippets.

@Yukaii
Last active August 29, 2015 14:13
Show Gist options
  • Save Yukaii/39ef9c91de2c8e26dfef to your computer and use it in GitHub Desktop.
Save Yukaii/39ef9c91de2c8e26dfef to your computer and use it in GitHub Desktop.

程式語言 Prolog 作業

##環境建制

  brew install gnu-prolog # 安裝 gnu prolog
  gprolog # 跑起來
  consult('pa3prolog.pl'). # 載入檔案
  # ...玩 

##結果 result

mother(X, Y) :- female(X), parent(X, Y).
father(X, Y) :- male(X), parent(X, Y).
child(X, Y) :- parent(Y, X).
sibling(X, Y) :- parent(TEMP, X), parent(TEMP, Y).
sister(X, Y) :- parent(TEMP, X), parent(TEMP, Y), female(X).
brother(X, Y) :- parent(TEMP, X), parent(TEMP, Y), male(X).
daughter(X, Y) :- parent(Y, X), female(X).
son(X, Y) :- parent(Y, X), female(X).
uncle(X, Y) :- sibling(X, F), parent(F, Y), male(X).
aunt(X, Y) :- sibling(X, F), parent(F, Y), female(X).
cousin(X, Y) :- parent(A, X), parent(B, Y), sibling(A, B).
male(mark).
male(mel).
male(richard).
male(tom).
male(adam).
female(amy).
female(jane).
female(joan).
female(betty).
female(rosa).
female(fran).
parent(mel, joan).
parent(jane, betty).
parent(jane, tom).
parent(richard, adam).
parent(richard, rosa).
parent(joan, fran).
parent(mark, jane).
parent(mark, richard).
parent(amy, jane).
parent(amy, richard).
parent(amy, joan).
cousin(betty, adam).
cousin(betty, rosa).
cousin(betty, fran).
sister(betty, tom).
brother(tom, betty).
uncle(richard, tom).
aunt(jane, adam).
child(rosa, richard).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment