Toni Posted November 30, 2017 Posted November 30, 2017 Hello This might be a math combination problem or alike (I can not come with a better expression in english). I would want a set of random numbers to be matched to a sum. For example I have numbers: 9,17 and 4. Then there is another set with sum = 29. The first set has a sum of 30 while the second is 29. What I want to do is fill the second set with numbers from first until there is no more room. So in this example I would use only number 9 and 17 and leave 4 out. The remainder from set two is 3 (29 - 9 - 17 = 3). I would want this remainder to be the smallest possible. To achieve this I thought of ordering numbers in descending order, higher numbers at the top and so on, leaving the smallest at the bottom. This way I believe I can fill the pool of the second set better with the smallest remainder possible. Do you think this is correct, is there any other better method to achieve it?
jbante Posted December 1, 2017 Posted December 1, 2017 What you're describing is the knapsack problem. The Wikipedia pages includes descriptions of several approaches to solving it for you to consider.
Toni Posted December 1, 2017 Author Posted December 1, 2017 Thank you jbante, a lot to read for today. I wish I was at my 20s again
Fitch Posted December 1, 2017 Posted December 1, 2017 If your goal is to use the fewest items to fill the knapsack, I think your initial idea to sort the numbers descending would work. Keep in mind that you wouldn't necessarily stop when you reach a number that doesn't fit, you'd skip that one and move on to the next number, which might be small enough to fit. This would be fairly simple to do in a script using a loop. (nice link, jb)
Toni Posted December 1, 2017 Author Posted December 1, 2017 Yes Fitch, that what I was thinking. A script with loop which would tick each record that fulfills the condition. But interesting reading about knapsack nonetheless, integrating that into FM is another story.
Recommended Posts
This topic is 2610 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now