家庭数据库中的双胞胎

时间:2017-10-29 12:00:36

标签: prolog

这是我的家庭数据库。但我无法从这个数据库中找到双胞胎婴儿。我给出了这个问题:定义关系twins(Child1,Child2)以在家庭数据库中查找双胞胎。

family(
    person(tom,right,date(17,may,1950),works(mathematician)),
    person(ann,right,date(29,may,1951),unemployed),
    [
        person(pat,right,date(5,may,1983),unemployed),
        person(max,right,date(5,may,1983),unemployed)
    ]).
family(
    person(nick,wellbard,date(15,september,1954),works(electrician)),
    person(cathrine,wellbard,date(11,march,1970),unemployed),
    [
        person(john,wellbard,date(15,may,1983),works(musician)),
        person(mike,wellbard,date(25,may,1989),unemployed),
        person(chloe,wellbard,date(15,may,1983),unemployed)
    ]).
family(
    person(john,brock,date(17,january,1978),unemployed),
    person(mary,brock,date(19,march,1951),works(teacher)),
    [
        person(tony,brock,date(20,may,1975),unemployed),
        person(sasha,brock,date(1,april,1979),unemployed),
        person(josh,brock,date(29,april,1983),unemployed)
    ]).
family(
    person(abc,xyz,date(17,may,1950),works(mathematician)),
    person(def,xyz,date(29,may,1951),unemployed),
    []).

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

嗯,很容易控制你有相同的姓氏和相同的出生日期。

in_list(person(Name,F,date(D,M,Y),W),[person(Name,F,date(D,M,Y),W)|_T]):-
 !.

in_list(X,[_|T]):-    
 in_list(X,T).

 twins(person(Nam,F,Date,W),person(Name,F,Date,We)):-
     family(person(_,F,_,_),person(_,F,_,_),T),
     in_list(person(Nam,F,Date,W),T),
     in_list(person(Name,F,Date,We),T).