Post Reply 
How do I learn RPL and solve this problem with it?
09-26-2017, 01:02 PM
Post: #27
RE: How do I learn RPL and solve this problem with it?
I'd solve it like so:
  1. Sort the list of resistor values.
  2. Copy the list into an array for faster access (see below).
  3. For the resistor whose value is closest to the desired resistance. This is your starting point for a solution.
  4. For each resistor in the set
  5. Subtract it from the target resistance. Find the resistor in the set with this value, or the two that are closest.
  6. Compute the resistance of putting these in series. If the resistance is better than your best solution so far, then replace the solution with the new one.
  7. Now do the same for connecting in parallel: compute the value that gets you to the target, find the values closest to it and if the answer is better than before, then use it.


To help with this, you should write (or find) a binary search function for finding a value in an array. I'd call it binSearchLEQ. It finds the closest value that is less than or equal to a given value. It returns the INDEX to the value, not the value itself. That way you can get the next largest item easily. The binary search is why you want to work with an array: finding the N'th value in an array takes constant time, whereas finding the Nth value in a list takes N time.

That should be fast enough. A faster way would start at each end of the array and work towards the center. At each step you'd pick a value from one side and then move find the value on the other side that gives the best fit. This way the whole process would make one pass for finding the best serial combination. For parallel combinations it might be more involved.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How do I learn RPL and solve this problem with it? - David Hayden - 09-26-2017 01:02 PM



User(s) browsing this thread: 2 Guest(s)