Fix minimizer
This commit is contained in:
parent
fb5250d501
commit
c0125afce5
1 changed files with 6 additions and 4 deletions
|
|
@ -37,8 +37,9 @@ fun main() {
|
|||
// Minimize transactions:
|
||||
for ((user, transactions) in payments.iterator()) {
|
||||
for ((target, pay) in transactions.iterator()) {
|
||||
val payback = payments[target]?.firstNotNullOf { (other, euros) ->
|
||||
assert(user == other)
|
||||
val payback = payments[target]
|
||||
?.filter { (other, _) -> other == user }
|
||||
?.firstNotNullOfOrNull { (_, euros) ->
|
||||
euros
|
||||
} ?: continue
|
||||
val common = min(pay, payback)
|
||||
|
|
@ -51,6 +52,7 @@ fun main() {
|
|||
payments[target] = payments[target]!!.also {
|
||||
it[user] = newPayback
|
||||
}
|
||||
println("Minimized $user -> $target for $common")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue