14

Jelly, 2 bytes _S Try it here! Takes the entering currents in the first argument, and the leaving currents in the second argument. _ subtracts them pairwise, leaving the single element from the longer list as-is, and S sums the result.


12

Mathematica, 151 122 characters Expects the target resistance to be stored in r and the list of available resistors in l. SortBy[Join[{#,#}&/@l,Join@@(#@@@Union[Sort/@N@l~Tuples~{2}]&/@{{"+",##,#+#2}&,{"|",##,#*#2/(#+#2)}&})],Abs[#[[-1]]/r-1]&] Less golf: SortBy[Join[{#, #} & /@ l, Join @@ (# @@@ Union[Sort /@ N@l~Tuples~...


12

05AB1E, 5 3 bytes zOz Try it online! Explanation z # compute 1/x for each x in input O # sum input z # compute 1/sum


10

APL (102) {V←{⊃¨⍺{⍺,⍺⍺,⍵,'=',⍺⍵⍵⍵}⍺⍺/¨Z/⍨≤/¨Z←,∘.,⍨⍵}⋄K[⍋|¯1+⍺÷⍨0 4↓K←↑('|'{÷+/÷⍺⍵}V⍵),('+'+V⍵),{⍵,' =',⍵}¨⍵;]} This takes the target resistance as the left argument and a list of available resistors as the right argument. Explanation: V←{...}: V is a function that: Z/⍨≤/¨Z←,∘.,⍨⍵: finds every unique combination of two values in ⍵, Z←,∘.,⍨⍵: join each ...


9

Haskell, 14 bytes (.sum).(-).sum Usage example: ( (.sum).(-).sum ) [5,7,3,4,5,2] [8,4,5,2,1] -> 6. Sum each list and take the difference.


9

Mathematica, 33 bytes So close to Pyth... l/Tr[l={#,#2(x=100Pi*I),1/x/#3}]& This is an unnamed function, which takes R, L and C as its three arguments and returns a list of complex numbers as the result (in the required order VR, VL, VC). Example usage: l/Tr[l={#,#2(x=100Pi*I),1/x/#3}]&[1, 1, 0.00001] (* {0.0548617 + 0.22771 I, -71.5372 + 17.2353 ...


9

Haskell, 18 16 bytes (1/).sum.map(1/) Try it online!


9

MATLAB, 14 bytes In MATLAB norm(...,p) computes the p-norm of a vector. This is usually defined for \$p \geqslant 1\$ as $$\Vert v \Vert_p = \left( \sum_i \vert v_i \vert^p \right)^{\frac{1}{p}}.$$ But luckily for us, it also happens to work for \$p=-1\$. (Note that it does not work in Octave.) @(x)norm(x,-1) Don't try it online!


7

Pyth, 30 29 28 bytes L*vw*100.l_1)K[Qy0c1y1)cRsKK Try it online.


7

Jelly,  5  3 bytes İSİ Try it online! How? Initially I forgot this form from my electronic engineering days ...how easily we forget. İSİ - Link: list of numbers, R e.g. [r1, r2, ..., rn] İ - inverse (vectorises) [1/r1, 1/r2, ..., 1/rn] S - sum 1/r1 + 1/r2 + ... + 1/rn İ - inverse ...


6

J - 86 71 70 char ((]/:[|@<:@%~2{::"1])(;a:,<)"0,[:,/(<,.+`|,.+/;+&.%/)"1@;@((<@,.{:)\)) I'm not going to bother to explain every little detail because a lot of the code is spent syncing up the results of different functions, but here's the gist of the golf: ;@((<@,.{:)\) makes every possible pair of resistors, to be connected either in ...


6

APL 190 Index origin 1. First loop (s) combines all resistors wired in series, second (p) those wired in parallel and the repeat to first loop to combine any parallel resistors now in series. The specification of the final zero resistor appears to be redundant. r←¯1↓⍎¨(c≠'/')⊂c o←⊃↑¨r r←⊃1↓¨r s:→(0=+/n←1=+/×r)/p ...


5

CJam, 8 6 bytes q~.-:+ Input uses two CJam-style arrays. Run all test cases. (This reads multiple test cases at once and includes a framework to process each line individually, discarding the expected result from the input.) Explanation q~ e# Read and evaluate input. .- e# Elementwise difference. :+ e# Get sum. .- works reliably because we're ...


5

Python, 329 chars import sys N=[[1]]+[map(int,x.split())for x in sys.stdin] N[-1][0]=1 n=len(N) S=[set([i])for i in range(2*n)] for x in range(n): C=S[2*x] for y in N[x][1:]:C|=S[2*y+1] for x in C:S[x]|=C V=[0]*(2*n-1)+[1] for k in range(999): for i in range(1,2*n-1):V[i]+=sum((V[j^1]-V[i])/N[j/2][0]for j in S[i])/9./len(S[i]) print 1/V[1]-2 Calculates ...


4

Python 3 - 250 247 270 bytes from itertools import* import sys r=sys.argv[1:] t=int(r.pop()) p=set(map(tuple,map(sorted,product(r,r)))) a=[('+'.join(b),sum(map(int,b)))for b in p]+[('|'.join(b),1/sum(map(lambda n:1/int(n),b)))for b in p] for s in sorted(a,key=lambda b:abs(float(b[1])/t-1)):print(s) Run like this: python resistors.py 100 150 220 330 470 ...


4

MATL, 3 4.0 bytes _hs Inputs are: leaving currents first, then entering currents. Try it online! _ % implicitly input array with leaving currents (except one). Negate h % implicitly input array with entering currents. Concatenate s % sum of all elements in concatenated array


4

Python 3, 97 bytes lambda n:[round(10**(i/n+2-(n<25)))+((.4<i/n<.67)-(.9<i/n<.92))*(n<25)+(i==185)for i in range(n)] The output values scaled from 1 to 10 are well-approximated by an exponential interpolation: 10**(i/n) Multiplying by 10 for 6, 12, 24 and 100 for 48, 96, 192 then rounding to the nearest integer round(10**(i/n+2-(n<...


4

Octave, 15 bytes @(x)1/sum(1./x) Try it online! Harmonic mean, divided by n. Easy peasy.


4

PowerShell, 22 bytes $args|%{$y+=1/$_};1/$y Try it online! Takes input via splatting and uses the same 1/sum of inverse trick as many of the others are doing


3

Javascript, 36 bytes (a,b)=>eval(a.join`+`+'-'+b.join`-`) f= (a,b)=> eval( a.join`+` +'-'+ b.join`-` ) document.body.innerHTML = '<pre>' + 'f([1,2,3],[1,2]) = ' + f([1,2,3],[1,2]) + '\n' + 'f([4,5,6],[7,8]) = ' + f([4,5,6],[7,8]) + '\n' + 'f([5,7,3,4,5,2],[8,4,5,2,1]) = ' + f([5,7,3,4,5,2],[...


3

05AB1E, 4 bytes Code: OEO- Explanation: O # Take the sum of the input list E # Evaluate input O # Take the sum of the input list - # Substract from each other Thanks to Luis Mendo for reminding me that I need to implement a concatenate function. If I've had implemented it sooner, it would have been 3 bytes: Non-competing version (3 ...


3

Julia - 179 163 bytes f(t,s)=(\ =repmat;m=endof(s);A=A[v=(A=s\m).>=(B=sort(A))];B=B[v];F=[s,C=A+B,A.*B./C];n=sum(v);print([[s P=[" "]\m P;A [+]\n B;A [|]\n B] F][sortperm(abs(F-t)),:])) This works the same as the old version, but the argument in the print statement has been organised slightly differently to reduce the number of square brackets necessary....


3

APL (Dyalog Unicode), 27 24 bytesSBCS Full program. Prompts for C, L, R in that order. (⊢÷+/)(⎕,⎕∘÷,÷∘⎕)÷○0J100 Try it online! 0J100 100 i ○ π times that ÷ reciprocal of that (…) apply the following tacit function:  ÷∘⎕ divide the argument by input (C)  ⎕∘÷, prepend input (L) divided by the argument  ⎕, prepend input (R) (…) apply the following ...


3

Octave / Matlab, 53 51 bytes function f(R,L,C) k=-.01j/pi;Z=[R L/k k/C];Z/sum(Z) Try it online Thanks to @StewieGriffin for removing two bytes.


3

JavaScript (ECMAScript 6) - 186 Characters f=(R,T)=>(D=x=>Math.abs(x[3]/T-1),r={p:(x,y)=>x*y/(x+y),s:(x,y)=>x+y},[...[[x,0,0,x]for(x of R)],...[[x,y,z,r[z](x,y)]for(x of R)for(y of R)for(z in r)if(x<=y)]].sort((a,b)=>D(a)-D(b))) Input: An array R of resistor strengths; and T, the target resistance. Output: An array of arrays (sorted by ...


3

Ruby 2.1, 156 154 bytes s=->(a,z){c={};a.map{|e|a.map{|f|c[e]=e;c[e+f]="#{e}+#{f}";c[1/(1.0/f+1.0/e)]="#{e}|#{f}"}};c.sort_by{|k,|(k/z.to_f-1).abs}.map{|e|puts"#{e[1]}=#{e[0]}"}} Ungolfed: s =->(a,z) { c={} a.map{|e| a.map{|f| c[e]=e c[e+f]="#{e}+#{f}" c[1/(1.0/f+1.0/e)]="#{e}|#{f}" } } c.sort_by{|k,| (k/z.to_f-...


3

For series-parallel circuits with few resistors, the resistances which can be created with n resistors but not with fewer are the numbers on the nth level of the Stern-Brocot tree. (This breaks later on, with 5/6 = 1/2 + 1/3 apparently a minimal counterexample). Instead of mapping from position in the Stern-Brocot tree to an S-P expression, it turns out to ...


3

J, 50 characters (3 :'0 a}1 b}y+1e_5*c=:+/(-/~y)%r+1e_4')^:_[0 %a{c Assumes the input is already stored in a set of global variables as: r is a 2D matrix of single-precision numbers a, b are 0-based indices of the two nodes Usage: r=: _ 2 _ _ r=:r,.2 _ 3 _ r=:r,._ 3 _ 4 r=:r,._ _ 4 _ a=:0 b=:3 (3 :'0 a}1 b}y+1e_4*c=:+/(-/~y)%r+1e_3')^:_<./r %a{c ...


3

Ruby 171 bytes Input as function argument. Output to stdout with trailing space (can be revised if necessary.) ->s{a,b,c,d=s.split.map{|z|[z[-1],z.to_f]}.sort.flatten %w{EA9.EAAVAA.WVA GS;.A?#WWV.RRR}.map{|w|m=w[n=(a+c+?!).sum%10].ord;print (b**(m%9-4)*d**(m/9-5))**0.5,w[n+7],' '}} Explanation All formulas can be expressed in the form b**x*d**y where ...


3

J, 33 26 bytes 0.46%92^39%~*@".{3+".,~1-# Try it online! Takes input as a string with gauges less than zero as a string of zeroes. Finds the index of that string and divides 0.46 (the diameter of 0000) by the 39th root of 92 (the ratio between gauges) that many times. Explanation 0.46%92^39%~*@".{3+".,~1-# Input: string S # ...


Only top voted, non community-wiki answers of a minimum length are eligible