Welcome to the GitHub repository for the core algorithm behind "Split", a mobile application designed to simplify group expense management. This algorithm efficiently calculates the minimal number of transactions required to settle debts within a group, making it easier for friends and families to manage shared expenses without the hassle of complex debt chains.
- Minimal Transactions: The algorithm identifies the optimal way to settle all debts with the fewest transactions possible.
- Simplicity: It accepts a list of expenses and automatically calculates who owes whom and how much.
- Flexibility: You can easily add or modify expenses, accommodating changes in group activities and expenses.
- Clarity: Outputs clear, straightforward transactions needed to balance the group's expenses.
-
Define Expenses: Start by creating a list of expenses. Each expense should be a list containing the payer's name, the amount paid, and the names of the beneficiaries.
expenses = [ ["Alice", 120, "Bob", "Charlie"], ["Bob", 150, "Alice", "Charlie"], ["Charlie", 180, "Alice", "Bob"] ]
-
Initialize the Algorithm: Create an instance of the
Splitclass with your list of expenses.split_instance = Split(expenses)
-
Calculate Transactions: Use the
balancemethod to calculate the minimal transactions required.transactions = split_instance.balance()
-
Review Transactions: The output will be a list of transactions, where each transaction indicates who should pay whom and the amount.
for transaction in transactions: print(transaction)
Given the expenses:
- Alice paid 120 euros for Bob and Charlie.
- Bob paid 150 euros for Alice and Charlie.
- Charlie paid 180 euros for Alice and Bob.
The algorithm might output a single transaction:
- ['Charlie', '45.0', 'Alice'].
This indicates that to settle all debts within the group, only one transaction is necessary.
This algorithm is based on the original work available at davymariko's Tricount GitHub repository. We extend our heartfelt gratitude to the original creator for their innovative approach to simplifying group expense management.