Something I’ve found fun and educational is solving the kind of logic puzzles that involve filling out a table. I found a book of these in a remainder sale a while back and the first one goes like this:
Tackfield St Andrew is a lovely little Suffolk village whose inhabitants are very conservative – they still refer to a number of retired Londoners who moved there years ago as ‘the new people’. From the clues below, can you work out where in London each of ‘the new people’ came from, how long they’ve lived in the village, and the name of each one’s home there?
It has a diagram which shows there are four variables with three values each:
Names: Alan Bradley, Mavis Norton, Walter Young
Area: Battersea, Islington, Paddington
Period: 8, 11, 16 years
House: Meadow View, Rose Cottage, White Gates
Then there are four clues to fit these together:
- Walter Young, who lives at Meadow View, is not the former Londoner who used to live and work in Islington.
- The person whose ex-home was just behind Paddington railway station has lived in Tackfield St Andrew longer than Alan Bradley.
- The Resident in White Gates has lived in the village for more than 8 years.
- One of the ‘new people’ has actually been living at Rose Cottage for 16 years.
My solution from a while back (which I should probably revisit to see if I can improve it) is:
puzzle(People) :-
People = [newpeople(_, _, 8, _),
newpeople(_, _, 11, _),
newpeople(_, _, 16, 'Rose Cottage')],
member(newpeople('Alan Bradley', _, Period1, _), People),
member(newpeople('Mavis Norton', _, _, _), People),
member(newpeople('Walter Young', _, _, 'Meadow View'), People),
member(newpeople(_, _, Period2, 'White Gates'), People),
member(newpeople(_, 'Battersea', _, _), People),
member(newpeople(_, 'Islington', _, _), People),
member(newpeople(_, 'Paddington', Period3, _), People),
\+member(newpeople('Walter Young', 'Islington', _, _), People),
Period2 > 8,
Period3 > Period1.