Improper Prolog logic for logic test

50 views Asked by At

Below is a Prolog problem in my textbook that is a variation of the Zebra problem. Instead of the original, it asks you to find the location of the pizza out of 4 people who each ordered a unique food and drink. I've seen solutions to similar problems with lists and libraries but I don't think that's the intended approach in the textbook.

Consider the following problem: Donna, Danny, David, and Doreen were seated at a table in a restaurant. The men sat across from each other, as did the women. They each ordered a different main course with a different beverage. in addition, – Doreen sat beside the person who ordered steak. – The chicken came with a Coke. – The person with the lasagna sat across from the person with milk. – David never drinks coffee – Donna only drinks water – Danny could not afford to order steak.

Who ordered the pizza? Write a prolog program that solves this problem by displaying who ordered each of the main courses and each of the beverages. Hint: Begin by writing clauses defining predicates beside(x,y), which holds if person x is sitting beside person y, and across(x,y), which holds if person x is sitting across from person y.

My thought process in my current solution was to define 4 positions and then designate which positions would be across and beside each other. However, when I input the query solution(pizza), it returns false. My best guess would be that this method of defining across and beside is not logically correct. Here is the code that I currently have:

person(donna). person(danny). person(david). person(doreen).
position(1). position(2). position(3). position(4).
% 1 [] 3
% 2 [] 4
% ^Seating arrangement with table
uniq_people(A,B,C,D) :-
    person(A), person(B), person(C), person(D),
    A\=B, A\=C, A\=D,
          B\=C, B\=D,
                C\=D.

across(1,3).
across(2,4).
across(X,Y) :- across(Y,X).
beside(1,2).
beside(3,4).
beside(X,Y) :- beside(Y,X).

solution(pizza) :-
    uniq_people(donna,danny,david,doreen),
    uniq_people(steak,chicken,lasagna,pizza),
    uniq_people(coffee,water,coke,milk),
    uniq_people(1,2,3,4),

    across(danny,david),
    across(donna,doreen),

    beside(doreen,steak),
    chicken = coke,
    across(lasagna,milk),
    donna = water,
    david \= coffee,
    danny \= steak.
0

There are 0 answers