Posts Tagged ‘sparse squares’

Sparse and Magic Squares

April 20th, 2021

A while back, I had the insight that the 3×3 magic square could be transformed into a sparse square, or a set of cells within a square in a grid where every row and column contains the same number of cells. The converse transformation of turning a sparse square into a magic figure is not original to me, but applying it to the sparse square from the first transformation gave a pleasing result. And then I stopped there.

Or I almost did:

Right, so if I had set the 1 where the 34 is, and the 6 where the 26 is before running the solver, (and likewise the 4 and 9) that would have been more elegant.

This is a figure I came up with before my blogging hiatus that never made it into a post. The rows, columns, main diagonals, and 3×3 blocks all sum to 115. This could be seen as a version of my doubly transformed magic square on a slightly degenerate 3×3 magic square whose entries are all 5’s.

But it was hard to see where to go from there. The next size up, the 4×4 square, was unsuitable. Its magic sum is 34, and since we’d be using a 4×4 block, we wouldn’t be able to evenly split the squares from each row and column into four lines. And 5×5 seemed big enough to be a mess to work with. So I was done.

But it turns out we can do something nice with the 4×4 after all. Suppose we number the squares starting with 0 instead of 1. We still can’t use 4×4 blocks, but since the highest value is now 15, 3×5 blocks look like a possibility. And indeed, our magic sum is now 30, of which 3 and 5 are both factors, so it works:

There was an interesting bug in the code I used to produce this. I was looking for figures that are single, hole free polyrects. One way to help filter these out from other solutions is to check for 2×2 blocks with checkered corners. If one is present, you must have either a hole or more than one polyrect. But by accident the constraint I added was more broad; it applied to any 2×2 block with two dark and two light rects. I was not able to get a single polyrect solution with this constraint, but I did find something at least as interesting. Notice that every 3×5 block is the same, after swapping dark and light, as the complimentary block with the number that you get by subtracting from 15. This was not an explicit constraint in my code, so it’s interesting that this property managed to emerge. I still haven’t found a single hole-free polyrect solution without the buggy constraint, but I’m confident they are out there. My solver code is just too inefficient to find them in a reasonable amount of time.

Once I was back on the trail of magic sparse squares, I came back to the magic partition square I discussed in a previous post. (There are four ways to partition the numbers from 1 to 8 into two subsets of four numbers that sum to 18. Each of the 8 subsets is present as a row or column in the square.) Since this figure uses smaller blocks, my solver had no trouble with it.

My work on magic sparse squares is ongoing, and I hope to have more to share with you soon. I’ve put my solver code up on GitHub. I know I’ve had a long hiatus without coming up with new material, but I expect to have a few more blog posts in the coming months, and I hope you’ll enjoy the shiny objects that I find and share.

Pentomino Painting Robots

February 1st, 2017

In the diagram below, each row (reading from left to right) and column (reading from top to bottom) gives instructions for painting one of the 12 pentominoes:

Sometimes an idea languishes in one of my notebooks for a few years before I can come up with the right iteration of it. My original idea here was to use a 4×4 grid. That would give me 8 pentominoes, (perhaps 10 using diagonals) but elegance surely requires all 12 to be present.

A combination of circumstances led me back to this problem. Some friends of mine have a tradition of playing RoboRally on New Year’s Day every year. This is a board game where you use cards with arrows on them to instruct your robot to move around a grid of squares. Also, in returning to the magic 45-omino problem, I was considering grids that could be used in sparse magic squares.

It might be possible to make an interesting grid puzzle, along the lines of sudoku, using this kind of grid as a basis. Most of the grid would start empty, except for a few squares in which arrows would be given at the start. Then the solver would fill in the rest of the grid by logical deduction so that the horizontal and vertical lines contain instructions for paining all of the pentominoes as above. Since the grid would have significantly fewer squares than a sudoku, this puzzle might be quicker to solve, but that doesn’t mean that it would necessarily be less interesting.