The aim is simple: given the string of resistance values, draw the part of "electrical circuit" of those resistors. Examples follow.
Input:
3
. Output:--3--
Input:
1,2,3
. Output:--1----2----3--
Next, the resistors can be joined parallel (by 2 or 3 resistors per join), but the required depth of parallel joins is only 1.
Input:
1|2
. Output:|--1--| -| |- |--2--|
Input:
1|2|3
. Output:|--1--| -|--2--|- |--3--|
Note, that
--2--
resistor is now centered.Input:
1|2,3|4|5
. Output:|--1--| |--3--| -| |--|--4--|- |--2--| |--5--|
Combined joins:
Input:
1,2,3|4,5,6|7|8,9
. Output:|--3--| |--6--| --1----2---| |---5---|--7--|---9-- |--4--| |--8--|
If it would be more convenient, the input can be a two-dimensional array. I.e. the input for the last example would look like this: [1,2,[3,4],5,[6,7,8],9]
.
Some notes:
- No other forms of (in|out)puts are allowed.
- The resistance of each resistor can vary in the range from 1 to 9. Other values, like
-
,42
or0
are disallowed. - The joins like
1|2|3|4
are invalid. As already mentioned, max 3 per parallel join. Empty joins, i.e....,|,...
or...,,...
are invalid. - Oh, and this is code golf :)