fix tolerance

This commit is contained in:
Nikolai Hartmann 2023-09-19 12:28:02 +02:00
parent 798d068ec0
commit 9288c9dd56
2 changed files with 21 additions and 0 deletions

View file

@ -60,6 +60,8 @@ def solve(balances: dict[str, int], tolerance: int = 0) -> dict[tuple[str, str],
possibilities = []
for subgroup in zerosum_subgroups(balances, tolerance):
balances_sub, balances_other = split_dict(balances, lambda k, v: k in subgroup)
if abs(sum(balances_other.values())) > tolerance:
continue
transactions_sub = solve(balances_sub, tolerance)
transactions_other = solve(balances_other, tolerance)
possibilities.append(transactions_sub | transactions_other)