资 源 简 介
A scenario that motivated me to develop this python script was when I went camping with friends. Different people paid upfront for different things and not everyone uses every item. After dividing and distributing the amounts, the settlement could involve n(n-1)/2 payments among n people in the worst case. But there is a simple way to resolve this in which a person does not have to pay/collect from n-1 other people. In fact, we can first resolve the debt between any two persons. Then, we transfer all the debts/credits of either of the two to the other (like they were married and one spouse died). This way, we reduce the problem of resolving debts among n people to n-1 people. And, you know, we are done by induction. This python script does exactly this. It computes who should pay whom for how much. It also does a little checking at the end to make sure everyone pays and receives the amount they are supposed to. For n people, the script is guaranteed to generate a settlement involvin