I use variation in Einstein Riddle and I am having problems.
When trying to calculate the solution, I will try the following:
solve(Street) :- Street = [_House1,_House2,_House3,_House4,_House5], %hint one goes here %hint two goes here %etc.
Then I can set the solution by typing: solve (Street)
However, this appears as a solution:
- house (flower, food, pet, sport)
- house (flower, food, pet, sport)
- house ( x , food, pet, sport)
- house (flower, food, pet, sport)
- house ( x , flower, pet, sport)
As you can see there 2 times x , the rest are all kinds of products, flowers, pets and sports. But each type is unique: if one person likes flower X, no one else can like X.
Now, why my solution gives 2 x is easy to see: we are given the number of hints, but only 4 colors are mentioned in all the hints. Therefore, Prolog does not know that there is another flower, and simply uses x twice, simply because it is possible and follows all the other prompts.
I want to say that all types of products and colors, etc. on the street are unique, so it should leave a space when it has already used all types. 3 will look like this: house(x , food, pet ,sport) and 5 will look like this: house(_, flower, pet, sport) .
I also tried adding this to the prompts: (say, βcactusβ is one of the colors not mentioned in the prompts) member(house(cactus,_,_,_), Street)
However, then my program does not end ...
A hint might look like this: is_neighbour(house(_,_,_,football),house(_,_,fish,_), Street), with: is_neighbour(A,B,List) giving true when A and B are next to each other in List . The hint can be translated into: a person who loves football lives next to a person who has fish.
If you need more information, I am ready to develop. :)