Sitemap

Member-only story

A Prime Example of Pruning

5 min readOct 27, 2026

--

How a little number theory and factorizing make a Bayesian network much more efficient.

Barry Leung posed this little number puzzle:

The numbers 2, 3, 4, 5, 6, 7 and 8 are to be placed in the empty circles so that (i) there is one number in each circle, and (ii) the sum of the numbers in each pair of adjacent circles is prime.

How many possible values are there for x?

Press enter or click to view image in full size

This is a very straightforward Constraint Satisfaction problem. We can use the picture above as our guide. Since the top node is a constant, we leave it unconnected to the rest of the network (but it can be referenced internally).

Press enter or click to view image in full size
Network before compiling equations

In this topology, all the constraint equations will be in the central node, but it creates a gigantic table:

There are 7⁷ = 823,543 entries!

The needed equations are fairly simple: We make sure that all values are all different, and then the sum is prime iff it is odd and not divisible by 3, or just itself 3.

Valid (A1, A2, A3, A4, A5, A6, X) =…

--

--

Pascal Bercker
Pascal Bercker

Written by Pascal Bercker

Philosophy | philosophy of science | logic | Bayesian networks and logic puzzles | keen on the use of Bayesian networks to solve Smullyan-type logic puzzles