# Algorithm to solve this grid puzzle?

You paint the grid green, one square at a time. You can only paint a square green if it shares an edge with 1 or 3 yellow squares (diagonals don't count). What's the maximum number of squares you can color?

I knew the answer was 24 because I played a handled puzzle game called "lights out" as a kid. It had the same rules as applied here, except every square you hit that wasn't lit would light up, and every square you hit that was lit would go dark. In addition, every square that shared an edge with the square that you hit would invert its state (again, diagonals don't count). Thus if the square above the one you touched was off, it would turn on and vice versa.

There were hundreds of pre-progrmmaed starting configurations, the goal being to get all the lights out, then there was a mode that you could set the starting lights yourself and try to solve. After many tries I realized it was impossible to begin with every square lit and get them all to go out. There would always be one...

I'd like to see an algorithm that can accomplish this in plug & play fashion. I suspect the developers knew one, as there were so many pre-programmed puzzles.

Note: obviously you can't do 25 because the last tile won't share an edge with any other yellow tiles

EDIT: The rules for the handheld game "lights out" are a bit different in that you can hit any square, and all the squares that share an edge invert their state (on/off). Every "level of the game starts with a different combination of lights on, that require an increasing number of steps to turn off. Is there an algorithm or equation that can be used to find various combinations of starting states (i.e. Which lights are on and which ones are off) that can all be solved?

for i=1..5, j=1..5

This closes the lights $2,1,4,3,5$ in every line and the lights $1,2,3,4$ of the last line