I want to solve this logic puzzle with Prolog without using any built-in functions or libraries. The problem is I don't know how to formulate the negative terms in the code. The negative terms are in the second, the third, and the seventh part.
For example, if I want to negate East Africa in the second sentence like this: adventure(B, T), hunter(B, doctor), not(place(B, east_africa)), the solver won't know there is this option between the places.
The logic puzzle:
Five men sit at the table in the hunting club and talk about their latest incredible experiences. They all struggled one animal at a time, in strange circumstances. Based on the information provided, determine where these adventures took place, what kind of animals they were, and by what tools they struggled.
- The professor tossed the animal with a suddenly grabbed large stone.
- The doctor did not hunt in East Africa and was not attacked by a hippopotamus.
- The colonel’s rhino adventure was not in Central Africa, where one of the hunters chased away an animal with his bare hands.
- The bison attacked one of the hunters in North Africa.
- The fire chief hunted in South Africa.
- The puma was hit in the head by the captain with an empty gun.
- The hunter in West Africa did not have any guns, and he was not the one who fight his attacker with a garment.
- The elephant was not chased away with a stick.
The code I wrote:
solve(T) :-
adventure(A, T), hunter(A, professor), tool(A, stone),
adventure(B, T), hunter(B, doctor),
adventure(C, T), hunter(C, colonel), animal(C, rhino),
adventure(D, T), place(D, central_africa), tool(D, bare_hands),
adventure(E, T), place(E, north_africa), animal(E, bison),
adventure(F, T), hunter(F, fire_chief), place(F, south_africa),
adventure(G, T), hunter(G, captain), animal(G, puma), tool(G, empty_gun),
adventure(H, T), place(H, west_africa),
adventure(I, T), animal(I, elephant).
adventure(X, adventures(X,_,_,_,_)).
adventure(X, adventures(_,X,_,_,_)).
adventure(X, adventures(_,_,X,_,_)).
adventure(X, adventures(_,_,_,X,_)).
adventure(X, adventures(_,_,_,_,X)).
hunter(a(X,_,_,_),X).
place(a(_,X,_,_),X).
animal(a(_,_,X,_),X).
tool(a(_,_,_,X),X).