Skip to content

Instantly share code, notes, and snippets.

@coleea
Created August 29, 2024 16:49
Show Gist options
  • Save coleea/f9a0418cc614135c29e4431b61db284a to your computer and use it in GitHub Desktop.
Save coleea/f9a0418cc614135c29e4431b61db284a to your computer and use it in GitHub Desktop.
% 가족 관계 정의
parent(john, mary).
parent(john, mike).
parent(susan, mary).
parent(susan, mike).
parent(mary, ann).
parent(mary, tom).
parent(mike, emma).
% 조부모 관계 규칙
grandparent(X, Y) :-
parent(X, Z),
parent(Z, Y).
% 형제 관계 규칙
sibling(X, Y) :-
parent(Z, X),
parent(Z, Y),
X \= Y.
% 사촌 관계 규칙
cousin(X, Y) :-
parent(P1, X),
parent(P2, Y),
sibling(P1, P2).
% 조상 관계 규칙 (재귀적 정의)
ancestor(X, Y) :-
parent(X, Y).
ancestor(X, Y) :-
parent(X, Z),
ancestor(Z, Y).
% 가족 구성원 찾기
family_members(X, Members) :-
findall(Y, (ancestor(X, Y); Y = X), Members).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment