title: Formula to split price equally among the people
body: <p>It's about 3 days that I'm trying to figure out a generic formula to split payment among people. So far, in java, I do something like this:</p>
  
  <pre><code>NameArray [Me, Dad, Mum, Sister]
  
  singlePayment[10,5,15,20,2,4]
  
  totalPaymentperPerson[25, 20, 6, 15]
  </code></pre>
  
  <p>Then, I order by highest price the <code>totalPaymentperPerson --&gt; [25,20,15,6]</code></p>
  
  <p>So the nameArray became <code>[Me, Dad, Sister, Mum]</code></p>
  
  <p>(All the price and the name are added dynamically by the user)</p>
  
  <p>So now, the total cost is: <code>66</code></p>
  
  <p>The price per person is: <code>16.5 --&gt; 66/4</code></p>
  
  <pre><code>debtorArray [Sister, mum] --&gt; the pay 15 and 6, under the cost per person of 16.5
  
  receiverArray[Me, Dad] --&gt; [20.5, 3,5]
  
  differenceArray[1.5, 10.5] ---&gt; cpp - debtorArray
  </code></pre>
  
  <p>Now I have to make something like that:</p>
  
  <ul>
  <li>Mum owes Me 8.5</li>
  <li>Mum owes Dad 6.5</li>
  <li>Sister owes Dad 1.5</li>
  </ul>
  
  <p>I can't figure out how to achieve this..If I do a formula for 3 participants, then if I have 6 participants, the formula doesn't work anymore..or maybe it work if I have 3 payments, but not with 5..Is there any way to do that with logic? I have too much "if-else" in my code...</p>