Here's a problem that I seem to be running into working with an accounting system.
I have a set of transactions, but their sum does not equal the amount that the accounting department thinks that it should. They are not questioning the math, just the transactions being included :p
Is there an algorithm that would help me determine which transactions in the set should not be included in order for the sum to match a given amount.
Given Set:
2
4
5
7
Given Sum Amount:
13
Result Set:
2
4
7
Edit: There's less than 100 transactions in the set. Does anyone have a C# example as there is not one on the Solving the NP-complete problem in XKCD question?
Man, I should have gotten a CS degree.
This is the Subset Sum problem, which is NP-Complete. But that doesn't mean there isn't an algorithm for finding a subset sum.
This is the Knapsack Problem and it's NP-Complete. You won't easily solve it exactly with anything except small input sets. For any decent-sized problem set, it's one of those lifetime-of-the-universe-to-solve problems.
That said, there are genetic-algorithm knapsack solvers out there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With