17
After you wake in a dark room, you see a rectangular grid of lights with corresponding switches. You decide to use a coordinate system with the bottom left light representing (1,1) and the coordinates increasing as you go up (y direction) and to the right (x direction). The grids are identical in that flipping the switch at (a,b) toggles (turns from off to on or from on to off) the light at (a,b) as well as the lights in the same column or same row as (a,b).
Your input will be a rectangular grid of two distinct characters representing on and off (I use 1 and 0, respectively). Also, a part of the input will be a series of at least one coordinate pair (with whatever format and separation you want) that will represent switches that you flip.
The output will be the same grid, with the "flip" applied at each of the coordinate pairs that were given as input. You may choose how to format your input, though the output must be a grid, not an array.
Samples
Sample input 1
111111
111111
111111
111111
(3,2)
Sample output 1
110111
110111
000000
110111
Sample input 2
01101
10100
00010
11111
10110
(1,1), (5,5)
Sample output 2
00010
00101
10011
01110
01000
Sample input 3
1
(1,1)
Sample output 3
0
Sample input 4
00000
11111
00000
11111
(2,3), (2,3)
Sample output 4
00000
11111
00000
11111
This is code golf. Standard rules apply. Shortest code in bytes wins.
Related: http://codegolf.stackexchange.com/questions/65738/crack-the-safe. Not the same problem, though. The goal of the other challenge was to find out which moves to make, this one is about applying a given list of moves.
– Reto Koradi – 2015-12-14T05:38:03.393@RetoKoradi It's also not quite the same operation. (The fact that the chosen cell itself is toggled too makes this significantly trickier.) – Martin Ender – 2015-12-14T15:24:57.687
Can I request the input be like
<grid><RETURN><coordinate_x><RETURN><coordinate_y><RETURN>
? – cat – 2015-12-14T15:41:19.050whichever format and separation: Does that mean they can be separate inputs (that is, "separator" is "enter" key)? – Luis Mendo – 2015-12-14T23:04:55.487
@LuisMendo Yes, if that works. – EEEEEEridan – 2015-12-15T00:10:43.733
What do you mean with "output must be a grid"? Is a list of lists a grid? Or do we have to print a graphical representation (newline separated rows)? If the latter, does the "two distinct characters" rule still apply, i.e. no spaces or other separators in-between? – nimi – 2015-12-15T01:27:13.143