# Coloring the squares

You can choose from 4 colors to color every square of the following $$10\times 10$$ grid.

After you finish, I'm going to take a connected block with at most three colors away. Your goal is to minimize the number of squares I can take away. How should you color the grid?

Two squares are connected if they share a common side. The block in the upper right quadrant is connected, the one in the lower left is not, because the green and blue squares share no common side with any other squares.

• Am I missing something, in this way, you can get all the squares but one? You can pick any 3 in a row or column and take it away. May 26 at 10:17
• @I'mNobody I can only take one connected block away.
– Eric
May 26 at 10:24
• I found that 3-color grids that are 6x6 and larger can be done with at most 8 squares. The optimal sequence for N>=1 is: 1, 3, 5, 6, 7, 8, 8, 8, ... May 30 at 11:02
• For 4 colors and an $n \times n$ grid, the optimal sequence for $n \ge 1$ starts with $1, 3, 7, 9, 12, 13, 16, 16$. May 30 at 13:15
• yep that's what I got. For n=9 I got 18. May 30 at 14:52

Here's a solution that lets you take away at most

18 squares:

This solution tiles infinitely with a period of 8 horizontally and 6 vertically.

• I got a checkmark already? Surely there must be some local improvements. May 26 at 17:07
• Local improvements？Why?
– Eric
May 26 at 23:44
• How do we know that this is optimal? May 27 at 4:28
• @DmitryKamenetsky We don't. But it seems so. Let me uncheck it for now, in case someone comes up with a better idea, or prove this is optimal.
– Eric
May 27 at 7:31
• Seems optimal. Every single square is used for the purpose of creating its diamond-shaped "pen". Super efficient.
– JLee
May 30 at 11:22

Well, this puzzle looks so cool. I wish I could skip work and continue messing with it, but I just had 20 minutes. The best I see so far is this.

where you will get

28 blocks by choosing red, green, yellow and taking the long diagonals.

I highly doubt this is optimal.

I wrote a solver that finds approximate solutions using simulated annealing. The best solution I found has at most

18 squares

I found several solutions with the same score:

They all have a pattern similar to Magma's answer. For 9x9 the best I can do is also 18 squares, so I believe 18 for 10x10 is optimal, because it cannot be less than the 9x9 score.

2 2 0 3 0 2 2 1 3 0
1 0 0 3 2 0 1 2 2 3
0 1 3 2 3 1 0 1 3 2
0 3 1 2 1 3 0 3 1 2
3 0 2 1 2 0 3 0 2 1
3 2 0 1 0 2 3 2 0 1
2 3 1 0 1 3 2 3 1 0
1 1 3 0 3 1 2 1 3 0
2 2 2 3 0 2 1 0 0 3
3 0 3 2 2 0 0 1 3 2

0 1 1 2 3 1 3 1 0 2
1 0 3 3 2 1 3 0 1 1
1 3 0 2 1 2 0 3 0 2
3 3 2 0 1 0 2 3 2 0
0 2 3 1 0 1 3 2 3 1
1 2 1 3 0 3 1 2 1 3
2 1 2 0 3 0 2 1 2 0
0 1 0 2 3 2 0 1 0 2
1 0 1 3 2 3 1 0 3 3
2 3 3 1 2 1 3 0 3 2

2 3 3 0 0 1 1 2 2 3
3 2 0 3 1 0 2 1 3 2
2 0 2 1 3 2 0 3 1 3
0 1 1 2 2 3 3 0 0 1
1 0 2 1 3 2 0 3 1 0
3 2 0 3 1 0 2 1 3 2
2 3 3 0 0 1 1 2 2 3
2 2 0 3 1 0 2 1 3 3
1 0 2 1 3 2 0 3 1 0
0 1 1 2 2 3 3 0 0 1

• Can you share your code? May 30 at 21:22
• "approximate solutions using simulated annealing" . Can you explain your method in layman terms ? Secondly, any proof that this is optimal ? Jun 23 at 11:54