Jump to content

combinations or ...


Toni

This topic is 2332 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This topic is 2332 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.