Telephone Conversation Logic Puzzle {Prolog} -
year('1928'). year('1929'). year('1932'). year('1935'). person(gertie). person(herbert). person(miriam). person(wallace). exchange(al). exchange(be). exchange(pe). exchange(sl). solve:- year(y1), year(y2), year(y3), year(y4), unique([y1,y2,y3,y4]), exchange(gertex), exchange(herbex), exchange(mirex), exchange(wallex), unique([gertex,herbex,mirex,wallex]), triples= [[gertie,y1,gertex], [herbert,y2,herbex], [miriam,y3,mirex], [wallace,y4,wallex]], %herberts first exchange \+ member([herbert,be,_],triples), %neither herberts nor gerties first exchange sl \+ ( member([herbert,sl,_],triples); member([gertie,sl,_],triples) ), %the exchange wasnt made in 1935 \+ member([_,be,'1935'],triples), %neither al nor exchanges made in 1932 \+ ( member([_,al,'1932'],triples); member([_,be,'1932'],triples) ), %the pe exchange made in 1929 member([_,pe,'1929'],triples), %wallace's first exchange al member([wallace,al,_],triples), writer(gertie,y1,gertex), writer(herbert,y2,herbex), writer(miriam,y3,mirex), writer(wallace,y4,wallex). writer(x,y,z):- write(x), write(' made '), write(y), write(' exchange in '), write(z), nl. unique([h | t]) :- member(h, t), !, fail. unique([_ | t]) :- unique(t). unique([_]).
i try run returns false statement. got question http://www.cis.upenn.edu/~matuszek/cis554-2012/assignments/prolog-01-logic-puzzle.html , can see it's same it's-a-tie.pl sample apart of atoms used , of logic involved...anybody have idea i'm doing wrong?
seems there swapped fields. changing triples this
triples= [[gertie,gertex,y1], [herbert,herbex,y2], [miriam,mirex,y3], [wallace,wallex,y4]],
i get
?- solve. gertie made 1928 exchange in herbert made 1929 exchange in pe miriam made 1932 exchange in sl wallace made 1935 exchange in al true .
Comments
Post a Comment