Formula to figure out who owes who how much money for shared expenses

86 Views Asked by At

I feel like this is a super basic math problem but I've had a long day and it's stumping me.

Two people are paying for some shared expenses. Some expenses are private. Some expenses are not shared and one person owes the other.

I'm trying to come up with a formula to figure what each person owes the other.

I have these variables:

  • aPaid = what person a paid for the shared expense
  • aPrivate = what person a paid but is private to them (for example, a drink from a shared dinner bill)
  • aOwesB = an ad-hoc amount of money that person a owes b
  • bPaid = what person b paid for the shared expense
  • bPrivate = what person b paid but is private to them
  • bOwesA = an ad-hoc amount of money that person b owes a

Now I need a formula that says how much money a and b need to exchange to balance the books.

I know how to calculate what the shared amount that needs to be split is:

sharedAmount = (aPaid - aPrivate) + (bPaid - bPrivate)

For example:

variable value
aPaid 1000
aPrivate 200
aOwesB 100
bPaid 800
bPrivate 100
bOwesA 50

Then sharedAmount is 1500 ((1000 - 200) + (800 - 100)).

So each person's share is $750.

But I don't know how to take that and figure out who needs to send how much money to balance the books.