larznetting
Settle a tangle of debts with the fewest payments.
Nets each person to a single balance, then settles the whole group: the greedy plan clears everyone in at most n-1 payments, and an optimize mode finds the provably minimum number of payments by discovering internally-cancelling groups. Exact integer minor units, so a settlement reconciles to the cent.
larzscript pkg install netting
What you get
- Minimal-payment debt settlement
- Greedy (<= n-1) or provably optimal
- Nets mutual debts first
- Exact money, reconciles to the cent
Try it
import "netting" as netting
let debts = [
{"from": "alice", "to": "bob", "amount": 1000},
{"from": "bob", "to": "carol", "amount": 1000},
{"from": "carol", "to": "alice", "amount": 400}
]
print(netting.settle(debts))Output
[{from: alice, to: carol, amount: 600}]Why it's in the Larz Stack
larznetting is a real Larzscript package (larzscript pkg install netting) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.