The following python-like pseudocode will accomplish this, although it will switch some cells multiple times. So let switch
be only from x
to o
, without effect on cells which already are in state o
.
for i in 0 .. size: # iteration
for j in 0 .. i: # both end points are inclusive
switch(x - i + j, y + j)
switch(x - i + j, y - j)
switch(x + i - j, y + j)
switch(x + i - j, y - j)