The puzzle goes like this: on an island there are 4 temples. Each temple has a name, location and date it was build. You get 4 clues to help you determine which 4 combinations (name, location, date) are correct. I have to solve this using prolog.
The names of the temples are: hori_takesi, okabe honzo, sama takako and takahashi. The locations are: funai, toyagi, uchida and usui. The dates are 1525, 1585, 1645 and 1705.
You are given the following clues:
- Of the shrine in Uchida and the temple built in 1645, one is sama takako and the other is okabe honzo.
- The temple in Funai was built before takahashi
- The temple in toyagi was built 120 years before the temple in usui
- Hori takesi wasa built after sama takako
I created the following knowlegde base which holds all possible combinations.
temple(hori_takesi, Location, Y).
temple(okabe_honzo, Location, Y).
temple(sama_takako, Location, Y).
temple(takahashi, Location, Y).
temple(Name, funai, Y).
temple(Name, toyagi, Y).
temple(Name, uchida, Y).
temple(Name, usui, Y).
temple(Shrine, Location, 1525).
temple(Shrine, Location, 1585).
temple(Shrine, Location, 1645).
temple(Shrine, Location, 1705).
The query you gonna ask prolog is: ?-solution(X). This has to return all 4 correct combinations. So X is a list of 4 elements namely the temples.
solution(X). Is true if all clues are true. So I did the following:
clue1(X) :- temple(Name, uchida, Y), Y\= 1645
clue2(X) :- temple(Name, funai, Y), temple(Shrine, takahashi, Y1), Y < Y1.
clue3(X) :- temple(Name, toyagi Y), temple(Shrine, usui, Y1). Y1 is Y + 120.
clue4(X) :- temple(hori_takesi, Loc, Y), temple(sama_takako, Loc, Y1) Y > Y1.
solution(X) :- clue1(X), clue2(X), clue3(X), clue4(X).
I'm not sure on how to proceed onwarts from here. Another tip i got is to use member/2. But im not sure on how to implement it. Love it if someone can help me.