dragonwasrobot / learn-prolog-now-exercises

My solutions to the exercises and practical sessions of the book 'Learn Prolog Now!' by Patrick Blackburn, Johan Bos, and Kristina Striegnitz.
288 stars 81 forks source link

Update chapter 6 exercises #55

Open D3usXMachina opened 1 year ago

D3usXMachina commented 1 year ago

Add colours of houses to body of zebra_owner predicate.

The puzzle can be solved without knowing the colour of the last house, but a priori we wouldn't know that.

A minimal example that yields the entire solution would be:

solvesPuzzle(Street) :- 
    Street = [_,_,_],
    member(house(green,_,_), Street),
    member(house(red,english,_), Street),
    member(house(_,spanish,jaguar), Street),
    sublist([house(_,_,snail),house(_,japanese,_)], Street),
    sublist([house(_,_,snail),house(blue,_,_)], Street),
    member(house(_,_,zebra), Street).

which yields:

Street = [house(red, english, snail), house(blue, japanese, zebra), house(green, spanish, jaguar)] .