Hello, I'm trying to solve a problem (in php, but programming language doesn't matter). I'm having a n number of persons that have paid money, and I have got a m number of persons that are going to pay the same amount as the sum of what the n number of people have paid. I want to calculate the shortest route of money transfers between these persons. It is possible to split the payments and pay to different persons. The ideal is that one person only makes one or two transactions. Can someone maybe point me in the right direction or help me with this?
An example: person A has paid $100
person B has paid $200
person C has paid $50
person D will pay $24
person E will pay $175
person F will pay $151
One possible solution to this is
person E pays $100 to person A,
person E pays $75 to person B,
person F pays $125 to person B,
person F pays $26 to person C
person D pays $24 to person C