Truth table for the zebra puzzle

Viewed 1284

I'm reading "Computer Science distilled" book and I've faced a trouble. Author suggests to solve Einstein's "Zebra puzzle" through truth table, but I can't figure out how. I can't find starting conditions and variables. Do you have any ideas of the smallest table possible? I suppose I can create only a 6^6 version

4 Answers

Take a look at the code I wrote for the puzzle-solvers package. It was made to solve a similar question right here on SO. Since it's a very small package, you can probably see how the code is written quite easily.

The code is the Solver class, which maintains a matrix of values and provides the methods you need to set up relationships that automatically prune the underlying graph of contradictory edges.

You can follow along with a detailed description of the logic from the docs. This really explains how the matrix representation of the graph is used to record the relationships in the rules. The gist of it is that each rule either sets up a direct link between two categories, which prunes all the contradictory edges, or eliminates an edge, which has implications as well.

Related