27
5
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.
1What output do you expect for situations like
"TRR\nB B\nRRT"
? – Howard – 2013-01-29T06:05:26.477111\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. – beary605 – 2013-01-29T06:22:41.7301Can we assume that each input array will contain only one complete circuit running from top to bottom as in your example or do we have to code for multiple separate circuits starting anywhere in the array? – Graham – 2013-01-29T11:32:45.570
@Graham: There will only be one redstone circuit for each input. – beary605 – 2013-01-29T14:26:29.033
1Knowing the game Minecraft, I think that in your example given the block on line 2 does not stop the adjacent torch from giving power (the redstone doesn't actually connect to the block). Is this an error or a meant simplification? – tomsmeding – 2013-01-29T19:15:07.540
Also, can we expect a maximum input size for the array? – tomsmeding – 2013-01-29T21:36:22.630
@tomsmeding: simplification purposes. Maximum size? How about 64x64, that's nice :) – beary605 – 2013-01-30T00:19:35.843
Does whitespace after the end of the line matter in the output? Also, should the output end with a newline? – Quelklef – 2016-08-03T06:01:01.163
I must answer this in Minecraft... – HyperNeutrino – 2017-04-17T01:30:16.770