On the Subject of making the Lights go Out

Who knew turning out all the lights was an optimizable task?

To disarm the needy, turn out all the lights by pressing the lights. Pressing a light will also toggle the orthogonally adjacent lights.

The below 3 algorithms can be used to toggle the state of a singular light based on whether it is in a corner, on an edge, or in the center.

The green cell represents the lit light, and the dots represent the lights to press. Note that rotational symmetry applies.

To find the optimal solution for a grid, apply the algorithms for every lit cell and xor them together. i.e. only include the lights which are pressed an odd number of times.