Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:33:25+00:00 2026-05-16T10:33:25+00:00

I’m trying to solve a problem (in php, but programming language doesn’t matter). I’m

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:33:26+00:00Added an answer on May 16, 2026 at 10:33 am

    In theory this could be framed as an optimization problem:

    Basically we’re going to establish a set of constraints that enumerate the structure of your problem, seed the initial values, and make sure that we allocate all the money as you’ve indicated.

    Initial condition constraints:

    A_paid = 100
    B_paid = 200
    C_paid = 50
    D_out  = 24
    E_out  = 175
    F_out  = 151
    

    Amount paid out cannot exceed the amount available: (we define D_to_A as a variable holding the amount paid from person D to person A)

    D_out >= D_to_A + D_to_B + D_to_C
    E_out >= E_to_A + E_to_B + E_to_C
    F_out >= F_to_A + F_to_B + F_to_C
    

    Amount paid to each individual must be equal to what they’ve already paid:

    A_paid = D_to_A + E_to_A + F_to_A
    B_paid = D_to_B + E_to_B + F_to_B
    C_paid = D_to_C + E_to_C + F_to_C
    

    If we were to stop now and solve this as a linear program we’d find any solution spanning the entire variable space, but you’re looking to minimize the number of actual payments. We can do this by minimizing over all X_to_Y variables in concert with the constraints above.

    min: D_to_A + D_to_B + D_to_C + ...
    

    You can use your favorite optimization technique to solve the problem, there’s plenty of available linear program solvers, I like lpsolve.

    Though this solves the specific example you described it’s easy to see how it can be expanded to larger problems by adding more variables…but the problem grows in complexity substantially as you add people. If I recall correctly the knapsack problem is NP or NP-hard, so this isn’t unexpected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.