I am trying to solve the following real problem that you might run into:
You had lunch with your friends, and you all agreed to split the bill evenly. Except that when the bill finally arrives, you will find that not everyone has enough money for them (if they are, cheap bastards).
So, some of you pay more than others ... After that, you come home and try to decide, "who should, what amount?".
This, I'm trying to solve algorithmically and fairly :)
It seems so easy at first, but I'm stuck with rounding, and what not, I feel like a complete failure;)
Any ideas on how to handle this?
EDIT: some python code to show my confusion
>>> amounts_paid = [100, 25, 30]
>>> total = sum(amounts_paid)
>>> correct_amount = total / float(len(amounts_paid))
>>> correct_amount
51.666666666666664
>>> diffs = [amnt-correct_amount for amnt in amounts_paid]
>>> diffs
[48.333333333333336, -26.666666666666664, -21.666666666666664]
>>> sum(diffs)
7.1054273576010019e-015
, ?
:)
>>> amounts_paid = [100, 50, 150]
>>> total = sum(amounts_paid)
>>> correct_amount = total / float(len(amounts_paid))
>>> correct_amount
100.0
>>> diffs = [amnt-correct_amount for amnt in amounts_paid]
>>> diffs
[0.0, -50.0, 50.0]
>>> sum(diffs)
0.0