使用逻辑编程Prolog解决难题

时间:2015-11-06 02:03:35

标签: prolog

下面是一本旧拼图书的拼图,我试图用逻辑编程语言prolog来解决这个问题。

  

在平原城市高中,化学,历史,   讲授拉丁语和数学,但不一定   分别由艾姆斯先生,布朗先生,克拉克小姐和戴维斯小姐担任。   根据学校的年鉴,

     

线索1.)当他们在大学时拉丁老师和   数学老师在allcampus探戈比赛中获得一等奖。

     

线索2.)艾姆斯夫人是平原城市P.T.A的主席。

     

线索3.)化学老师和数学老师   大学室友。

     

线索4.)化学老师也是足球教练。

     

线索5.)历史老师和拉丁老师都参与其中   其他

     

线索6.)艾姆斯先生,布朗先生和克拉克小姐不同   学院。

     

然而,众所周知,高中每年包含一定的   学校八卦的数量除了其实际摘要   一年的活动,因此并不总是完全可靠。在里面   目前的情况下,所给出的陈述中有五个是真实的,一个是   假的。

     

每个人教什么科目?

我已将这个谜题翻译成Prolog。但我错过了一些东西,因为我得到了很多答案,而不是4或6个答案。

  citizen(L):-L=[[a,_,_,_],[b,_,_,_],[c,_,_,_],[d,_,_,_]],
  Gender = [male, f], 
  Colleges = [college1, college2, college3],
  Subject = [latin, maths, hist, chem ],
  clue1(L,Gender,Colleges,Subject),
  clue2(L,Gender,Colleges,Subject),
  not(clue3(L,Gender,Colleges,Subject)),
  clue4(L,Gender,Colleges,Subject),
  clue5(L,Gender,Colleges,Subject),
  clue6(L,Gender,Colleges,Subject).

   clue1(L,Gender,Colleges,Subject) :-
            member([_,latin,G11,C11],L),
            member([_,maths,G12,C12],L),
  member(C11,Colleges), member(C12,Colleges), C11 = C12,
  member(G11, Gender), member(G12, Gender), G11 \= G12.

  clue2(L,Gender,Colleges,Subject) :-
            member([a,S21,male,_],L),
  member(S21, Subject),S21  \=  latin, S21  \=  hist.

  clue3(L,Gender,Colleges,Subject) :-
            member([_,chem,G31,C31],L),
            member([_,maths,G32,C32],L), 
  member(G31, Gender), member(G32, Gender),G31 = G32,
  member(C31,Colleges), member(C32,Colleges),C31 = C32.              

  clue4(L,Gender,Colleges,Subject) :-member([_,chem,male,_],L).

  clue5(L,Gender,Colleges,Subject) :-
            member([_,hist,G51,_],L),
            member([_,latin,G52,_],L),
    member(G51, Gender),  member(G52, Gender),  G51 \= G52.

  clue6(L,Gender,Colleges,Subject) :-
            member([a,_,_,C41],L),
            member([b,_,_,C42],L),
            member([c,_,_,C43],L),
    member(C41,Colleges),member(C42,Colleges),member(C43,Colleges),
      C41 \= C42, C41 \= C43, C43 \= C42.

我找不到遗漏点。请帮帮我..

在它下面编辑了更多帮助的问题。

  Below is a word problem. You can use tuples of the form      
  [name,subject,gender,college] since all the clues are about these four things.
In Plain City High, chem, math, latin, and history are taught, not nec. 
respectively, by Mr. Ames, Mr Brown, Miss Clark, and Miss Davis.       
 Find who teaches what, given that precisely one of the following clues is wrong.

 clue 1.the Latin and math teachers won a tango contest in college
        (can conclude they went to same college, and were of diff. gender)
 clue 2. Mrs. Ames is pres. of the PTA 
        (must interpret this to mean that Ames is not engaged)
 clue 3. chem and math were roommates in college
         (can conclude they are of same gender)
 clue 4. chem teacher coaches football 
         (can conclude is a male)
 clue 5. hist. and latin teachers are engaged 
         (can conclude diff. genders)
 clue 6. Ames, Brown and Clark went to diff. colleges

0 个答案:

没有答案