for the heck of it, I rewrote the Prolog version of my code as I couldn't find it (of course). The program is nothing more than a table of values of resistors in the form of value(10.0) for instance. I could have just used the 1% bins and multiplied them but I didn't to keep the goal seeking program easily understandable so you wouldn't have to go learn Prolog. I used SWI Prolog by the way.
The command 'value(A)' looks in the 'value' table and assigns the first value to the variable 'A'. It then does the same with the next goal 'value(B)'. After assigning values to A and B, it does the parallel resistor math resulting in the instantiation of C. If C is equal to the required value or within a range, the program succeeds, otherwise you get a false return meaning it couldn't find a solution. You can ask for more solutions by pressing the space bar.
Here is the goal and the output for finding a resistor between 70 and 70.1:
?- value(A), value(B), C is (1/(1/A + 1/B)), C > 70.0, C<70.2.
A = 76.8,
B = 806.0,
C = 70.11871318531944
A = 78.7,
B = 634.0,
C = 70.00954118142276
A = 78.7,
B = 649.0,
C = 70.18867665246668
A = 80.6,
B = 536.0,
C = 70.06422315926045
A = 82.5,
B = 464.0,
C = 70.04574565416286
A = 84.5,
B = 412.0,
C = 70.11883182275932
A = 97.6,
B = 249.0,
C = 70.11656087709174
A = 249.0,
B = 97.6,
C = 70.11656087709174
A = 412.0,
B = 84.5,
C = 70.11883182275932
A = 464.0,
B = 82.5,
C = 70.04574565416286
A = 536.0,
B = 80.6,
C = 70.06422315926045
A = 634.0,
B = 78.7,
C = 70.00954118142276
A = 649.0,
B = 78.7,
C = 70.18867665246668
A = 806.0,
B = 76.8,
C = 70.11871318531944
That's about as easy as it gets and it finds the first solution as fast as you press enter with each additional solution just as fast. This is using a table of values from .1 to 1000.
When I tested it originally I knew there was a value of 140 in the table so I tried the following thinking it would spit out A=140 and B = 140 with C = 70:
?- value(A), value(B), C is (1/(1/A + 1/B)), C = 70.0.
A = 105.0,
B = 210.0,
C = 70.0
A = B, B = 140.0,
C = 70.0
A = 210.0,
B = 105.0,
C = 70.0
false.
I was surprised to see the 105 and 210 come up first followed by A and B being equal to 140. How many of us would have grabbed two 140 ohm resistors to hit 70 in parallel (assuming there is no 70 ohm resistor) without thinking of 105 and 210?
This one threw me off as well:
?- value(A), value(B), C is (1/(1/A + 1/B)), C = 50.0.
A = 75.0,
B = 150.0,
C = 50.0
A = B, B = 100.0,
C = 50.0
A = 150.0,
B = 75.0,
C = 50.0
false.
I am always grabbing two, 100 ohm resistors to make a perfect 50 ohms without thinking of 150 and 75 ohms.
Anyway, I plan to keep this around and expand it to the next few decades up to 10Meg.