Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
There's a good news and a bad news.
Good news: you got a Christmas present from Santa. (Already?! Christmas is two weeks away!)
Bad news: the present is locked with a laser lock. And a note next to it says:
Only the ones who can properly open the lock deserve the present inside. If you force it or fail to open in 24 hours, the present will turn into a piece of coal.
You carefully examine the laser lock. It has a laser, a sensor, and a grid of square cells. Some cells already have a piece of mirror, and some of the empty ones are colored red; the others are green.
+-+-+-+-+-+-+-+
laser --> |G|G|R|\|G|G|G|
+-+-+-+-+-+-+-+
|\|R|/|G|R|G|\| --> sensor
+-+-+-+-+-+-+-+
You immediately think, "Aha, so I'm supposed to place some mirrors on some of the green cells so the laser goes to the sensor."
So one possible solution to the above would be:
+-+-+-+-+-+-+-+
laser --> |.|.|R|\|.|/|\|
+-+-+-+-+-+-+-+
|\|R|/|\|R|/|\| --> sensor
+-+-+-+-+-+-+-+
Task
In this task, the positions of the laser and the sensor are fixed, and the height of the grid is always 2. Given the state of the lock as a 2-by-N grid, output a possible solution.
The input grid is given as a 2D string like
GGR\GGG
\R/GRG\
but the following variations (and combinations thereof) are allowed:
- an array of rows / a matrix / a flattened string or array
- charcodes instead of characters
- transposed grid (in other words, columns instead of rows)
- lowercase instead of uppercase
The output must be in the same format as the input, with each G
replaced with .
(nothing) or one of \/
(a mirror). Replacing all R
s with .
in addition to the above is allowed.
..R\./\ or ...\./\
\R/\R/\ \./\./\
You may assume that the solution always exists. If there are multiple solutions, you may output any one of them.
No other alternative I/O formats are allowed.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
G
G
->
\
\
GG
RG
->
.\
R\
G\/R/\/GG
GRGGGRGR\
->
\\/R/\/.\
\R...R/R\
G\
G\
->
.\ or .\ or .\
.\ /\ \\
"g\grr/\ggrggg\"
(column first) allowed? \$\endgroup\$