title: What algorithm to use to determine minimum number of actions required to get the system to "Zero" state?
body: <p>This is kind of more generic question, isn't language-specific. More about idea and algorithm to use.</p>
  <p>The system is as follows:</p>
  <p>It registers small loans between groups of friends. <code>Alice</code> and <code>Bill</code> are going to lunch, Bill's card isn't working, so Alice pays for his meal, $10.<br />
  The next day <code>Bill</code> and <code>Charles</code> meet each other on a railway station, Charles has no money for ticket, so <code>Bill</code> buys him one, for $5.
  Later that day <code>Alice</code> borrows $5 from <code>Charles</code> and $1 from <code>Bill</code> to buy her friend a gift.</p>
  <p>Now, assuming they all registered that <em>transactions</em> in the system, it looks like this:</p>
  <pre><code>Alice -&gt; Bill $10
  Bill -&gt; Alice $1
  Bill -&gt; Charles $5
  Charles -&gt; Alice $5
  </code></pre>
  <p>So, now, only thing that needs to be done is <code>Bill</code> giving <code>Alice</code> $4 (he gave her $1 and <code>Charles</code> <em>transferred</em> his $5 to <code>Alice</code> already) and they're at the initial state.</p>
  <p>If we scale that to many different people, having multiple transaction, what would be the best algorithm to get as little transactions as possible?</p>