title: Reconcile two datasets/collections when number of reconciling combinations is unknown
body: <p>So I work as a consultant doing accounting.  One of my tasks is to reconcile transactions between data sets.  One-to-one matching between the collections is pretty easy to solve, programatically.  I bascially dumped the data into two separate arrays and started checking for matches using nested for-loops.<br>
  My question is about how reconcile transactions when the number of transactions in either data set isn't known until run-time.  Further, the sums of the transactions have to be equal on both sides.<br>
  Ie.  </p>
  
  <pre><code>DataSet #1    DataSet #2
  A/%/k  $11    A/%/k  $22
  A/%/k  $11    A/%/k  $33
  A/%/k  $11
  A/%/k  $11
  A/%/k  $11
  </code></pre>
  
  <p>Above, don't be confused about (A), (%), or (k).  These are just identifying primary keys, if you will.  Ie.  They are matching contract numbers, invoice numbers, etc.  What is important is that in Dataset#1, 5 transactions total $55.  In Dataset#2, 2 transactions total $55.  The two sets reconcile.  Theoretically, you could have n Choose r number of transactions, whose sum on in Set#1 equals the sum in Set#2.  Less abstract, you could have 8 transactions in Set#1 whose sum equals 3 transactions in Set#2.  (8C3 = 56, btw)</p>
  
  <p>Does anyone have any thoughts about an algorithm and/or array or other kind of data structure, where all possible combinations of sums are checked against the other collection?  Is there something in a library out there that could help?  My thoughts harken to recursive algorithms that calculate factorials to solve such a problem but once the combinatorics are calculated-- what then??  How do I calculate all 56 sums (see above)?  Really, there are X sums.  </p>
  
  <p>Again, the total matching number of transactions won't be known until run-time.  One last challenge is that I'd like to do this in VBA/Excel.  That's where my data lie and that's where my employer will support a technical solution.  Sorry, I cannot program in Python nor is it technically feasible where I work.  Also, apologies for not displaying code, as I have no code written yet. </p>