Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

What you're describing is the knapsack problem. The Wikipedia pages includes descriptions of several approaches to solving it for you to consider.

  • Author

Thank you jbante, a lot to read for today. I wish I was at my 20s again :)

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)

  • Author

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.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.