The Math of Fairness: How We Minimize Group Debt Transactions
When you have a group of 5 friends splitting costs, things get messy fast. Alice owes Bob $20, Bob owes Charlie $15, and Charlie owes Alice $10. In a naive system, that’s three separate transactions. But in a smart system, Alice just pays Bob $10 and Charlie $5. How do we get there?
The Efficiency vs. Accuracy Challenge
In the world of group finances, 'fair' doesn't just mean everyone pays their share—it means everyone pays their share with the minimum amount of effort. Circular debts are the enemy of a clean bank statement.
The Greedy Algorithm Explained
Dough uses a variation of the 'Greedy Algorithm' to simplify debts. Here is the high-level logic:
- Calculate Net Balances: We first find out exactly how much each person is 'up' or 'down' relative to the group average.
- Sort the Group: We identify the person who owes the most (the biggest debtor) and the person who is owed the most (the biggest creditor).
- Execute the 'Greedy' Step: The debtor pays as much as they can to the creditor. Either the debtor is fully paid up, or the creditor is fully satisfied.
- Repeat: We remove the satisfied party from the list and repeat the process until everyone’s balance is zero.
This approach transforms a tangled web of 'IOUs' into a linear series of payments. It’s the same logic that high-frequency trading systems use to net out positions, but built for your pizza parties.
We did the math so you can keep your friendships simple.