Эйнштейн Риддл с перечнем терминов
Я реализовал Einstein Riddle в Прологе и пытаюсь выяснить, у кого дома была рыба.
Я не могу найти ошибку в этом коде, и опция трассировки не помогает с этой проблемой;)
Правила:
Норвежец живет в первом домеАнгличанин живет в красном доме.Зеленый дом расположен прямо на левой стороне белого дома.Дейн пьет чай.Легкий курильщик живет рядом с заводчиками кошек.Житель желтого дома курит сигару.Немец курит водопровод.Житель центра дома пьет молоко.У легкого курильщика есть сосед, который пьет воду.Курите сигареты без фильтра разведения птиц.Шведская порода собак.Норвежец живет рядом с синим домом.Заводчик лошадей живет рядом с желтым домом.Дым ментол пью пиво.В теплице пьют кофе.Вот мой код:
on_the_left(X, Y, N) :-
Y is X - 1,
\+ Y < 1,
\+ X > N.
next_to(X, Y, N) :-
( Y is X + 1;
Y is X - 1),
\+ X > N,
\+ Y > N,
\+ X < 1,
\+ Y < 1.
fish(Who) :-
Houses = [
house(1, _Color1, _From1, _Animal1, _Drink1, _Smoke1),
house(2, _Color2, _From2, _Animal2, _Drink2, _Smoke2),
house(3, _Color3, _From3, _Animal3, _Drink3, _Smoke3),
house(4, _Color4, _From4, _Animal4, _Drink4, _Smoke4),
house(5, _Color5, _From5, _Animal5, _Drink5, _Smoke5) ],
N is 5,
%-- hint 1
member(house(1, _, norway, _, _, _), Houses),
%-- hint 2
member(house(_, red, england, _, _, _), Houses),
%-- hint 3 - on_the_left
member(house(GREEN, green, _, _, _, _), Houses),
member(house(WHITE, white, _, _, _, _), Houses),
on_the_left(GREEN, WHITE, N),
%-- hint 4
member(house(_, _, denmark, _, tea, _), Houses),
%-- hint 5 - next_to
member(house(LIGHT, _, _, _, _, light), Houses),
member(house(CAT, _, _, cat, _, light), Houses),
next_to(LIGHT, CAT, N),
%-- hint 6
member(house(_, yellow, _, _, _, cigar), Houses),
%-- hint 7
member(house(_, _, germany, _, _, waterpipe), Houses),
%-- hint 8
member(house(3, _, _, _, milk, _), Houses),
%-- hint 9 - next_to
member(house(WATER, _, _, _, water, _), Houses),
next_to(LIGHT, WATER, N),
%-- hint 10
member(house(_, _, _, bird, _, nofilter), Houses),
%-- hint 11
member(house(_, _, sweden, dog, _, _), Houses),
%-- hint 12 - next_to
member(house(NORWAY, _, norway, _, _, _), Houses),
member(house(BLUE, blue, _, _, _, _), Houses),
next_to(NORWAY, BLUE, N),
%-- hint 13 - next_to
member(house(HORSE, _, _, horse, _, _), Houses),
next_to(HORSE, GREEN, N),
%-- hint 14
member(house(_, _, _, _, beer, menthol), Houses),
%-- hint 15
member(house(_, green, _, _, coffee, _), Houses),
%-- FINAL QUESTION - WHO LET THE FISH OUT?
member(house(_, _, _, fish, _, _), Houses),
member(house(_, _, Who, fish, _, _), Houses).
Я пробовал много комбинаций, но:
? - рыба (Кто).
ложный.
Редактировать:
Код работает сейчас, что я изменил:
1 * От:
%-- hint 5 - next_to
member(house(LIGHT, _, _, _, _, light), Houses),
member(house(CAT, _, _, cat, _, light), Houses),
Для того, чтобы:
%-- hint 5 - next_to
member(house(LIGHT, _, _, _, _, light), Houses),
member(house(CAT, _, _, cat, _, _), Houses),
2 * От:
%-- hint 13 - next_to
member(house(HORSE, _, _, horse, _, _), Houses),
next_to(HORSE, GREEN, N),
Для того, чтобы:
%-- hint 13 - next_to
member(house(YELLOW, yellow, _, _, _, _), Houses),
member(house(HORSE, _, _, horse, _, _), Houses),
next_to(HORSE, YELLOW, N),
Если вы читаете эту статью, посмотрите на комментарий @Enigmativity о структурах в предикатах помощника.