Redstone is a material in the game Minecraft, and it is used for many complex contraptions. For this program, you will only need to simulate three items: the redstone wire (noted with R), redstone torch (noted with T), and block (noted with B).
Here are a list of basic rules about how redstone works:
A redstone torch sends power to any adjacent redstone wire.
TRRRR
^This redstone wire is powered.
Redstone wire can only hold power for 15 blocks.
TRRRRRRRRRRRRRRRR
^This last wire is unpowered, because the torch is >15 blocks away.
A block is said to be powered if a powered redstone wire is found adjacent to it.
TRRRB
^This block is powered.
If a block next to a redstone torch is powered, then the torch stops emitting power.
T
R
R
R
B <This block is powered.
T <This redstone torch does not emit power because of the block next to it.
R <This redstone is unpowered because the torch is not providing power.
R
Input will be given in two dimensional arrays up to a size of 64x64, like this:
TRRR
B
TBRTRR
R
RRRRRRRRR
R
RRRRRR
It is guaranteed that the input will not have any "clocks", or redstone powered by a torch pointing to the block that the torch is on. There will only be one redstone circuit in every input.
Your program must change each character to be a 1 or a 0, 1 indicating if this item is powered/emitting power, and a 0 if it is unpowered/not emitting power.
This input should have this output:
1111
1
100000
1
111111111
1
001111
This is a code-golf, so shortest code wins, as always.
"TRR\nB B\nRRT"
? \$\endgroup\$111\n0 1\n000
is the output; it seems to be sound within the rules. I will put an input restriction saying you cannot have any situations likeTRR B R RRR
, where it flashes repeatedly. \$\endgroup\$