2
$\begingroup$

After celebrating the new year, me and my pals wanted to split the costs of our mischief. I started wondering about the best way to toss money around, i.e. a way to systematically minimise the amount of transactions. So the problem is that everyone should pay equally, even though one or few have already payed for the bills.

The obvious worst case scenario is that for $p$ people out of $n$ that have payed for something, the other $n-1$ pay for their share, $p$ times. If a single person pays for everything, the solution is easy enough: everyone pays for their share. For 2 out of $n$ people my best guess is this. First we total the money spent. Then one of the two pays the other such that they only pay for their share. The others pay the first guy as previously. This can be generalised. For $p$ out of $n$ that do the spending, let's choose 1 that is the hub of all transactions. Again, let's combine the total costs of everything, and let the chosen hub equalise the loss or win of those that payed something. Finally $n-p$ people simply pay for their share.

Is this the optimal strategy?

In a special case, where for example the non-hub spender spent 16 € and the share is 8 €, one of the people can pay their share to the non-hub, eliminating a transaction with the hub. But any amount that doesn't exactly get the spending of a non-hub equal to the share doesn't help.

I know this is neither the trickiest of questions nor one of utmost importance, but I thought someone might enjoy giving it a go. Happy New Year!

$\endgroup$
0
$\begingroup$

Your question is quite confusingly worded, but I think I know what you are asking.

Each person should end up paying the proper share, and there should be as few transactions as possible - that minimizes "tossing money around".

The problem seems to be that some people have already paid the full bill at some of the establishments you visited, and now you have to even up.

Figure out the amount owed (the total of the bills divided by the number of people).

Clearly you might need one transaction for each of the $n$ people who aren't even. Here's a way to do that. Among the people not even there must be at least one who has paid less than their fair share. Let one of those people hand the balance owed to anyone else. Now that payer is even (all paid up). If you're still not all even, do it again.

This will take at most $n$ transactions, fewer if by chance someone receiving money was evened up along the way. At each stage you can look for such a coincidence and take advantage of it.

$\endgroup$
  • $\begingroup$ Thanks for the answer! I edited the question slightly to confirm your interpretation of the question, sorry. But to your answer. It takes at most $n$ transactions. I reckon the hub solution I proposed also takes that amount, and now looking at it, no less should be expected beyond the special cases. But this does have the advantage of not piling the transactions onto one hub. Cheers! $\endgroup$ – Felix Jan 3 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.