I am a complete beginner to programming and have to create and solve a riddle in Prolog using GNU Prolog, similar to the Einstein riddle, albeit less sophisticated. I have been trying to create a riddle for the items contained within the following table.
My code so far look like this, but I really do not entirely understand what I am doing wrong or right here. I can compile the code in GNU Prolog, but it will not solve the riddle:
middle(M,[_,M,_]).
right(A,B,[[_|A]|B]).
left(A,B,[A|[B|_]]).
run:-
X = [_,_,_],
middle([_,brown,_],X), /* the brown guinea pig lives in the middle of the cage */
member([brown,carrots,_],X), /* the brown guinea pig loves to eat carrots */
member([_,salad,giggles],X), /* the salad eating guinea pig giggles */
right([_,salad,_],[brown,_,_],X), /* the salad eating guinea pig sits to the right of the brown guinea pig */
left([black,_,_],[_,_,squeaks],X), /* the black guinea pig sleeps to the left of the squeaking guinea pig */
member([black,_,grumbles],X), /* the black guinea pig grumbles */
member([grey,_,giggles],X), /* the grey guinea pig giggles*/
write(X),nl, /* write out all fur colors */
write('the '),write(N),write(' guinea pig loves to eat cucumbers'),nl. /* answer to the question */
I would greatly appreciate any help as I am quite unfamiliar with these things but have to figure out a solution for a class I am taking. Any tips would be of great help. Thanks!