How do I learn RPL and solve this problem with it?

09262017, 01:02 PM
Post: #27




RE: How do I learn RPL and solve this problem with it?
I'd solve it like so:
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. 

« Next Oldest  Next Newest »

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