2012-05-15 52 views
0

我有以下規則:Prolog的名單問題

/*The structure of a subject teaching team takes the form: 
    team(Subject, Leader, Non_management_staff, Deputy). 
Non_management_staff is a (possibly empty) list of teacher 
structures and excludes the teacher structures for Leader and 
Deputy. 
teacher structures take the form: 
teacher(Surname, Initial, 
     profile(Years_teaching,Second_subject,Club_supervision)). 
    Assume that each teacher has his or her team's Subject as their 
main subject.*/ 

team(computer_science,teacher(may,j,profile(20,ict,model_railways)), 
[teacher(clarke,j,profile(32,ict,car_maintenance))], 
teacher(hamm,p,profile(11,ict,science_club))). 

team(maths,teacher(vorderly,c,profile(25,computer_science,chess)), 
[teacher(o_connell,d,profile(10,music,orchestra)), 
    teacher(brankin,p,profile(20,home_economics,cookery_club))], 
teacher(lynas,d,profile(10,pe,football))). 

team(english,teacher(brewster,f,profile(30,french,french_society)), 
[ ], 
teacher(flaxman,j,profile(35,drama,debating_society))). 

team(art,teacher(lawless,m,profile(20,english,film_club)), 
[teacher(walker,k,profile(25,english,debating_society)), 
    teacher(brankin,i,profile(20,home_economics,writing)), 
    teacher(boyson,r,profile(30,english,writing))], 
    teacher(carthy,m,profile(20,music,orchestra))). 

我應該帶回任何一個領導者的初始和姓在了含有總計2名或更多的教師與信息通信技術作爲他們的第二個主題團隊。

我是新來prolog所以不確定這一點。另外,我已經正確地得到了結果,但它被返回了3次。

任何幫助,將不勝感激。

另外,我的aplogies,如果這是非常容易。

回答

0

你沒有提供你用來尋找這些老師的代碼,所以我不能肯定地說,但是如果有一個團隊有3個成員w/ict作爲他們的第二個主題(例如computer_science),那麼將會有3種方法找到2(AB,AC和BC),這將解釋你的多個結果。但是說如何修改你的代碼來解決這個問題需要看到代碼被修復。

+0

答案(名稱,初始化): - 球隊(_,鉛,工作人員,DEP), \t鉛=老師(名稱,初始化,_), \t人=老師(_,_,型材(_,信息和通信技術(_,ict,_),[Lead,Dep | Staff]), –