If you’ve ever reconciled a bank statement, you know that not every transaction on the bank statement always has a one-to-one relationship with a single transaction on the general ledger. There may be times when multiple transactions on the general ledger sum together to make up one debit on the bank statement – or vice versa. This is just one example of how useful it can be to have a tool that can produce all sum permutations of a set of numbers to determine which combination of those numbers can be added together to produce a known outcome. While we can certainly go through every permutation manually, this is not ideal for situations where the number set is large. More specifically:
Total Combinations = 2n – 1, where n = total numbers in the set
Using this formula, if we had a set of 15 numbers and we wanted to know which combination of those numbers could be added together to equal a specific outcome, there would be 32,767 different possible combinations we’d have to try!
To make this process easier, below is a simple Python script that can find the combination of numbers that sums together to produce a given output, if one exists:

Let’s test the script. Using our bank reconciliation example, let’s assume we have the following 16 check deposits recorded on our general ledger: $45,709, $12,516, $1,009, $508, $12, $13,555, $81,321, $59, $921, $41,891, $822, $14, $190, $234, $2,075, $42,243. On the bank statement, assume we have a deposit for $43,743 which we know is a total of several checks deposited at one time, we just don’t know which checks. We type all 16 numbers in and type “STOP” at the end so the script can begin going through all possible number combinations. We also must enter the expected output. The script produces a set of five numbers: $508, $12, $59, $921, and $42,243 – these are the five checks that makeup the $43,743 deposit on the bank statement!
