/********************************************************************************* Logic puzzle from www.logic-puzzles.org Figure out the reservation, first name, superhero and language for each person using the clues given. Reservations: 5:00pm, 5:30pm, 6:30pm, 7:00pm First Names: Caleb, Emanuel, Johnathan, Karen Superheros: Batman, Hellboy, Iron Man, Spiderman Languages: ASP, Cold Fusion, PHP, Python Clues: 1. The Batman fan is not Caleb. 2. Of Karen and Caleb, one specializes in PHP applications and the other has the 5:30pm reservation. 3. The Hellboy fan has an earlier reservation than the PHP programmer. 4. Emanuel isn't well-versed in Python or Cold Fusion. 5. The person with a reservation at 7:00pm specializes in Cold Fusion applications. 6. The Spiderman fan is Karen. 7. The ASP programmer doesn't care for Spiderman and is not Karen. 8. Either the Cold Fusion programmer or the PHP programmer collects anything even remotely related to Iron Man. 9. Caleb doesn't care for Iron Man and doesn't have the 6:30pm reservation. 10. The ASP programmer is not Johnathan. 11. The PHP programmer doesn't care for Iron Man. 12. The Spiderman fan has an earlier reservation than the Cold Fusion programmer. ********************************************************************************/ puzzle(List) :- % Generate List = [person(T1,F1,S1,L1),person(T2,F2,S2,L2),person(T3,F3,S3,L3),person(T4,F4,S4,L4)], permutation([5:00,5:30,6:30,7:00], [T1,T2,T3,T4]), permutation([caleb,emanuel,johnathan,karen], [F1,F2,F3,F4]), permutation([batman,hellboy,iron_man,spiderman], [S1,S2,S3,S4]), permutation([asp,cold_fusion,php,python], [L1,L2,L3,L4]), % Test % 1. The Batman fan is not Caleb member(person(_,F_batman,batman,_), List), F_batman \= caleb, % 2. Of Karen and Caleb, one specializes in PHP applications and the other has the 5:30pm reservation. ( sublist([person(_,caleb,_,php),person(5:30,karen,_,_)], List) ; sublist([person(5:30,caleb,_,_),person(_,karen,_,php)], List) ), % 3. The Hellboy fan has an earlier reservation than the PHP programmer. member(person(T_hellboy,_,hellboy,_), List), member(person(T_php,_,_,php), List), earlier(T_hellboy, T_php), % 4. Emanuel isn't well-versed in Python or Cold Fusion. member(person(_,emanuel,_,L_emanuel), List), \+ member(L_emanuel, [python,cold_fusion]), % 5. The person with a reservation at 7:00pm specializes in Cold Fusion applications. member(person(7:00,_,_,cold_fusion), List), % 6. The Spiderman fan is Karen. member(person(_,karen,spiderman,_), List), % 7. The ASP programmer doesn't care for Spiderman and is not Karen. member(person(_,F_asp,S_asp,asp), List), F_asp \= karen, S_asp \= spiderman, % 8. Either the Cold Fusion programmer or the PHP programmer collects anything even remotely related to Iron Man. member(person(_,_,iron_man,L_iron_man), List), member(L_iron_man, [cold_fusion,php]), % 9. Caleb doesn't care for Iron Man and doesn't have the 6:30pm reservation. member(person(T_caleb,caleb,S_caleb,_), List), T_caleb \= 6:30, S_caleb \= iron_man, % 10. The ASP programmer is not Johnathan. member(person(_,F_asp,_,asp), List), F_asp \= johnathan, % 11. The PHP programmer doesn't care for Iron Man. member(person(_,_,S_php,php), List), S_php \= iron_man, % 12. The Spiderman fan has an earlier reservation than the Cold Fusion programmer. member(person(T_spiderman,_,spiderman,_), List), member(person(T_cold_fusion,_,_,cold_fusion), List), earlier(T_spiderman, T_cold_fusion), !. sublist([], _). sublist([X|L], List):- member(X, List), sublist(L, List). earlier(H1:_, H2:_) :- H1 < H2, !. earlier(H:M1, H:M2) :- M1 < M2.