I’m trying to design a Ruby script that will help with RC/RL circuit design by taking values of E24 series resistors and E12 and E6 series capacitors and inductors. Basically just cycling through each possible combination with the equation F = 1 / ( 2 * Pi * R * C ) [for the RC circuit for eg].
I’m not after efficiency here, just reliability. I need it to cycle through every single combination of the resistor array and capacitor/inductor array (never all 3) using the values for the equation above and if it is within plus/minus x% of a certain value to return which values in the array it used. I can nest 2 for loops to go through each combination, but I want it to not just return values within a tolerance but tell me which value is the closest (or exact).
This is a mild refactoring of your code: