## Tuesday, August 18, 2015

### Logic Puzzle

From page 262 of 'The Art of Prolog' by Leon Sterling and Ehud Shapiro.

"The challenge is to write a Prolog program to solve the following logic puzzle.
(a) The Englishman lives in the red house.
(b) The Spaniard owns the dog.
(c) Coffee is drunk in the green house.
(d) The Ukrainian drinks tea.
(e) The green house is immediately to the right (your right) of the ivory house.
(f) The Winston smoker owns snails.
(g) Kools are smoked in the yellow house.
(h) Milk is drunk in the middle house.
(i) The Norwegian lives in the first house on the left.
(j) The man who smokes Chesterfields lives in the house next to the man with the fox.
(k) Kools are smoked in the house next to the house where the horse is kept.
(1) The Lucky Strike smoker drinks orange juice.
(m) The Japanese smokes Parliaments.
(n) The Norwegian lives next to the blue house.

Who owns the Zebra? Who drinks water?"
They provide the solution to a simpler problem.

Clare had a go and figured out that the water-drinker might be Norwegian, then things bogged down a little. My own programming efforts, meanwhile, were mired in bugs.

It is often the little things in life which absurdly please. Imagine my delight (spoilers follow) when my Prolog program produced the following output:
Logic Puzzle v. 0082
Persons = [person(yellow,norwegian,fox,water,kools,1),
person(blue,ukranian,horse,tea,chesterfield,2),
person(red,english,snails,milk,winston,3),
person(ivory,spanish,dog,orange,luckystrike,4),
person(green,japanese,zebra,coffee,parliaments,5)]

S = [['The zebra is owned by the ', japanese], ['the ', norwegian, ' drinks water']].
For my next trick it's implementing one of those block-stacking planning programs, to be followed by Eliza. And after that, let's put them all together and have a go at a more interesting conversationalist.