# Parse the resistors

The aim is simple: given the string of resistance values, draw the part of "electrical circuit" of those resistors. Examples follow.

1. Input: 3. Output:

--3--

2. 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.

1. Input: 1|2. Output:

 |--1--|
-|     |-
|--2--|

2. Input: 1|2|3. Output:

 |--1--|
-|--2--|-
|--3--|


Note, that --2-- resistor is now centered.

3. Input: 1|2,3|4|5. Output:

 |--1--|  |--3--|
-|     |--|--4--|-
|--2--|  |--5--|


Combined joins:

1. 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 or 0 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 :)
• Thanks for the correction, it's a fixed numbers of dashes. The separate resistors are preceded and followed by two dashes. Dec 25 '15 at 15:13
• Can the first and third line be padded with spaces to even the length of the lines? Dec 25 '15 at 18:45
• @Tfeld Trailing/leading spaces are allowed before/after the whole output, but not between the resistors. Dec 25 '15 at 18:54
• Are leading/trailing empty lines allowed when there are no parallel resistors? Dec 26 '15 at 3:40
• @Pietu Hm, let it be yes :) Dec 26 '15 at 5:31

ƛI⁼[h\-dpømð5*:‟W|ƛ|--pøm;:L2=[÷|   øm$W]];DvhṄ,ƛ1i;\-j,vtṄ,  Try it Online! # 05AB1E, 45 42 bytes ε€…--ÿDgið.ø.BëÁð3×ª3£À'|ì… - SδìÅ\]€.ºøJ»  Try it online! ## Python 2, 195 bytes a=b=c='' B=' '*5 H='--' S=' |'+H;E=H+'| ' for x in input(): if x>9:a+=S+x[0]+E;c+=S+x[-1]+E;b+='-|'+[B,H+x[1]+H][len(x)>2]+'|-' else:b+=H+x+H;a+=B;c+=B print[b,a+'\n'+b+'\n'+c]['|'in a]  Takes input as: [1,2,[3,4],5,[6,7,8],9]  Output:  |--3--| |--6--| --1----2---| |---5---|--7--|---9-- |--4--| |--8--|  • Save a few bytes by making H a function lambda V:f'--{V}--'? – user100690 Jun 9 at 13:56 # JavaScript (Node.js), 149 bytes n=>(H=M=>n.map(e=>(T=e[M]||e[1])? |${(G=e=>--${e}--)(T)}| :' ').join)(0)+${n.map(e=>+e?G(e):-|${e[2]?G(e[1]):' '}|-).join} +H(2)  Try it online! No need to overcomplicate things, just keep it simple # Haskell, 132 bytes foldr(zipWith(:))e.(>>=g) a=" - " b="|||" s%c=[a,b,c,c,s,c,c,b,a] g[x]=[a,a,' ':x:" ",a,a] g[x,y]=[x,' ',y]%"- -" g z=z%"---" e=[]:e  Try it online! Takes input as a [[Char]] and outputs a list of lines. # Julia 1.5, 129 bytes s=" "^5 +x="--$x--"