From New Scientist #1289, 21st January 1982 [link] [link]
A is a grid of 63 matchsticks. B shows one way of removing 21 matches so as to “spoil” all the triangles in the grid (there are 78 of various sizes) by removing one or more matches from the boundary of each. And C shows a way (an improvement due to Miss Gregory and Mr Buckle on the previously published solution to Enigma 82) of removing 20 matches so as to spoil all the 492 quadrilaterals. The problem now is: what is the smallest number of matches you must remove so as to spoil all the triangles and all the quadrilaterals in A?
Note that C actually has 21 matches removed, although it is possible to solve Enigma 82 by removing only 20 matches (see the diagram attached to my solution).
[enigma144]
As noted this problem is an extension of Enigma 82. I augmented the program I wrote for Enigma 82 to generate a suitable data file for the GLPK solver, although I found running glpsol on the output was taking too much time and memory (much more than for the equivalent problem for Enigma 82), so I used lp_solve which seemed to be both faster and use less memory (and can take the same format data). But even then it took 8h57m to complete an exhaustive search (although it finds the solution after only 5m26s, so if you already know the answer you can use the [[
-o
]] option to find a solution of the appropriate size). A commercial ILP solver, that’s able to use multiple CPU cores would no doubt improve on this.Solution: The smallest number of matches required to spoil all quadrilaterals and triangles is 29.
Here’s the Python program I used to generate the data for the ILP solver.
And the LP model:
I would then run the solver like this:
For N=6, lp_solve 5.5.2.0 finds a minimal solution in 8h57m. If [[
-o 29
]] is applied the solution is found in 5m26s.For N=5, lp_solve 5.5.2.0 finds a minimal solution in 24.5s. If [[
-o 20
]] is applied the solution is found in 122ms.As noted, this problem is an extension of Enigma 82, so here is an extension to my code that uses the Minimum Hitting Set implementation in MiniZinc that I used to solve Enigma 82, along with neater code for generating the triangles.
The size 6 grid is solved in 5.3 seconds, the size 7 grid in 22 seconds, the size 8 grid in 44 seconds, the size 9 grid in 4 minutes, and the size 10 grid in 12 hours (using the
highs
solver).Solution: The smallest number of matches required to spoil all quadrilaterals and triangles is 29.