Zagadka z GNU Prolog, podobna do Einsteina Riddle
Jestem kompletnym początkującym programistą i muszę stworzyć i rozwiązać zagadkę w Prologu za pomocą GNU Prolog, podobnego do zagadki Einsteina, choć mniej skomplikowanej. Próbowałem stworzyć zagadkę dla przedmiotów zawartych w poniższymstół.
Mój kod do tej pory wygląda tak, ale naprawdę nie do końca rozumiem, co robię źle lub tutaj. Mogę skompilować kod w GNU Prolog, ale nie rozwiąże on zagadki:
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 */
Byłbym bardzo wdzięczny za każdą pomoc, ponieważ nie znam tych rzeczy, ale muszę znaleźć rozwiązanie dla klasy, którą biorę. Wszelkie wskazówki byłyby bardzo pomocne. Dzięki!