I have a transaction grouping problem that I'm having trouble to devise the algorithm to solve it. Not even ChatGPT (version 3.5) can solve this correctly.
Suppose I have five transactions:
- Transaction ID AA value 10
- Transaction ID BB value 20
- Transaction ID CC value 15
- Transaction ID DD value 17
- Transaction ID EE value 13
Sum them into two groups valued 25 and 50.
The correct answer for this example is:
- Group 1: Transaction IDs AA and CC, valued 10 + 15 = 25
- Group 2: Transaction IDs BB, DD, and EE, valued 20 + 17 + 13 = 50
Now for another example of the problem.
Suppose I have the following transactions:
- Transaction ID A698E2A9 value 145.16
- Transaction ID 973A82C7 value 10
- Transaction ID C46B6BC1 value 40.27
- Transaction ID 53241629 value 139.37
- Transaction ID EEC7F482 value 147.18
- Transaction ID 4AC7471C value 105.56
- Transaction ID E895678D value 72.04
- Transaction ID F8F6A46A value 40.27
- Transaction ID 694D6619 value 5.09
- Transaction ID 2A9F8A96 value 85.2
- Transaction ID 5DF1CDFE value 40.31
- Transaction ID 2F9B0025 value 690
- Transaction ID 0DA6F171 value 10
Sum them into three transactions valued 336.82, 145.16, and 1048.47.
Thus, what would be the best algorithm to create solve a generic version of this problem? That is, given a set of (transaction ID, value) pairs, and another set of value groups, group the transactions in the first set so that each groups' sums matches the desired value groups.