For my filter experiments I use that same idea, but an executable is overkill. I just store my 10% SMD resistor by bins, the program merges the values in a single list, and iterates for single resistor, series pair or parallel pair, giving relative error and precision of the result:
#SMD resistor bins.
res100 = [1., 5.1, 9.1, 33., 43., 47., 75., 82.]
res1k = [100., 110., 160., 180., 240., 390., 430., 750.]
res10k = [1.2e3, 1.5e3, 2.4e3, 3.3e3, 3.6e3, 3.9e3, 4.7e3, 5.1e3, 6.2e3, 7.5e3, 9.1e3]
res100k = [12e3, 15e3, 24e3, 36e3, 43e3, 47e3, 51e3, 68e3]
res1meg = [100e3, 120e3, 150e3, 180e3, 240e3, 300e3, 330e3, 360e3, 430e3, 670e3]
res10m = [1e6, 2.7e6, 4.7e6, 3.3e6]
res = [res100, res1k, res10k, res100k, res1meg, res10m]
target = input("Target: ")
# One resistor:
found = -1
diff = 10e10
eps = 0
for l in res:
for x in l:
eps = abs(x - target)
if (eps < diff):
found = x
diff = eps
print "\n\n1 resistor: ", found
print "Bounds: %f to %f"% (found * 0.99, found * 1.01)
print "Relative error: %f%%\n" % (100.0 * (found - target) / target)
#Pair:
found_s = -1
found_p = -1
diff_s = 10e10
diff_p = 10e10
eps_s = 0
eps_p = 0
for l1 in res:
for l2 in res:
for x in l1:
for y in l2:
eps_s = abs(x + y - target)
eps_p = abs(1/(1/x + 1/y) - target)
if (eps_s < diff_s):
found_s = (x,y)
diff_s = eps_s
if (eps_p < diff_p):
found_p = (x,y)
diff_p = eps_p
print "Series pair: ", found_s
print "Bounds: %f to %f" % ((found_s[0] + found_s[1])*0.99, (found_s[0] + found_s[1])*1.01)
print "Relative error: %f%%\n" % (100.0 * ((found_s[0] + found_s[1]) - target) / target)
print "Parallel pair: ", found_p
print "Bounds: %f to %f" % (1/(1/(found_p[0]*0.99) + 1/(found_p[1]*0.99)), 1/(1/(found_p[0]*1.01) + 1/(found_p[1]*1.01)))
print "Relative error: %f%%\n" % (100.0 * (1/(1/found_p[0] + 1/found_p[1]) - target) / target)
So, for example, if I need 374.628 ohms (as in a thread in other subforum

), my program gives:
Target: 374.628
1 resistor: 390.0
Bounds: 386.100000 to 393.900000
Relative error: 4.103270%
Series pair: (180.0, 180.0)
Bounds: 356.400000 to 363.600000
Relative error: -3.904673%
Parallel pair: (750.0, 750.0)
Bounds: 371.250000 to 378.750000
Relative error: 0.099299%
So a parallel combination of 750 ohms nails it. I've been thinking about getting serious and redoing the program with arbitrary depth, like A, A+B, A||B, A+B+C, A+(B||C), (A+B)||C, A||B||C, etc. But given the limitation of 2% precision in capacitance I work with, it'd be overkill.
Another very interesting problem is getting the minimum collection of resistor values that will guarantee less than 1% relative error for any value from 100 ohm to 1 meg, so I can get lots of these values and be done with that. I've never got serious enough to actually sit and compute it.