ILP Part 73 — Matchstick puzzle

This is the seventieth third part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra

Today we’re going to solve a matchstick puzzle. Move one stick to make the equality hold:

which is 6 + 2 = 9.

Solution is rather trivial but let’s encode it in ILP:

We use 7 segment displays with elements in this order:

so it is top, top-right, bottom-right, bottom, bottom-left, top-left, middle.

In line 1 we specify initial state. In lines 2-3 we define how many moves to make and how many digits in total we have.
Next, in line 6 we define matches, and in line 9 we define variables for digits.

In lines 12-14 we specify that digits must be less than ten. Next, in lines 16-17 we specify that at most one match of the initial state can be moved.

Next, in lines 19-52 we translate 7 segment displays to digits. We define patters in lines 22-33. Next, in liens 35-51 we iterate over patterns, take respective segments, and make sure that if segments are set then digit is formed accordingly.

Finally, in line 54 we define the equation.


It worked in 0.02 second.