Group expense splitter for trips and parties

Expense splitter: enter who paid what to get each person's equal share and who owes whom, settled with the fewest possible payments.

更新日 検証済みの例:4

One payment per line: “Alex paid 120 for food” or “Alex, 120, food”.
Separate names with commas. Include people who paid nothing; leave blank to split among the payers only.
試す
Each person's share
$
Each person's share: $48.88
小数点以下の桁数:2;最も近い値へ、等距離なら末尾が偶数の値へ
Total spent
$195.50
Payments to settle up
3
People
4
Who pays whom
Jo pays Alex $48.88; Priya pays Alex $18.88; Sam pays Alex $3.38

4 people spent $195.50, so each owes $48.88. 3 payments settle everything: Jo pays Alex $48.88; Priya pays Alex $18.88; Sam pays Alex $3.38.

Paid minus share

Alex$71.13Sam−$3.38Priya−$18.88Jo−$48.88
Payments to settle up 行数:3
変換元変換先Amount
JoAlex$48.88
PriyaAlex$18.88
SamAlex$3.38
計算方法 S
  1. Total and equal share

    195.504=48.875\frac{195.50}{4} = 48.875
  2. Balance: paid minus share

    Alex 120 − 48.875 = 71.125; Sam 45.5 − 48.875 = −3.375; Priya 30 − 48.875 = −18.875; Jo 0 − 48.875 = −48.875

  3. Fewest payments

    4 people are owed or owe money. Grouping them into sets whose balances cancel exactly, each set of g people settles in g − 1 payments: 3 in total.

    Amounts are rounded to the cent for display, so a payment can differ from the exact balance by less than a cent.

Group expense splitter for trips and partiesについて

Each person's share is the total spent divided by the number of people. A balance is what someone paid minus that share: a positive balance is owed money and a negative one owes it. The calculator then splits the balances into as many groups as possible whose balances cancel out exactly, because a group of g people can always settle in g − 1 payments.

With the defaults, Alex, Sam and Priya paid 195.50 between them and Jo paid nothing, so each share is 48.875. Three payments settle everything: Jo pays Alex 48.88, Priya pays Alex 18.88 and Sam pays Alex 3.38.

Finding the fewest payments is NP-hard in general (Verhoeff, 2004), so the exact search runs when up to 16 people have a non-zero balance; larger groups fall back to paying the largest creditor from the largest debtor. Payments are shown to the cent, so each can differ from the exact balance by less than a cent.

計算例

Three payers and one person who paid nothing

Who paid what
Alex paid 120 for groceries Sam paid 45.50 for fuel Priya paid 30 for snacks
Everyone sharing the costs
Alex, Sam, Priya, Jo
Total spent
195.50
Each person's share
48.88
Payments to settle up
3
Who pays whom
Jo pays Alex $48.88; Priya pays Alex $18.88; Sam pays Alex $3.38

照合元:Python decimal: 195.50/4 = 48.875; balances −48.875, −18.875, −3.375 rounded half-even to cents; 3 payments by brute-force subset search

A case where matching the largest amounts first needs 4 payments, not 3

Who paid what
A paid 14 B paid 13 C paid 12 D paid 5 E paid 6
Each person's share
10.00
Payments to settle up
3

照合元:Python brute-force partition into zero-sum groups {A, E}, {B, C, D}: 5 − 2 = 3; largest-first greedy gives 4

Everyone paid the same

Who paid what
A, 10 B, 10 C, 10
Each person's share
10.00
Payments to settle up
0
Who pays whom
Everyone is even — no payments needed.

照合元:Definition: every balance is 0

A payer missing from the list is added

Who paid what
Alex paid 60 Sam paid 20 Kim paid 40
Everyone sharing the costs
Alex, Sam
People
3
Each person's share
40.00
Payments to settle up
1
Who pays whom
Sam pays Alex $20.00

照合元:Hand calculation: 120/3 = 40; Alex +20, Sam −20, Kim 0

よくある質問

How do you split expenses in a group?

Add up everything spent, divide by the number of people to get the equal share, then subtract that share from what each person paid. For 195.50 spent across four people the share is 48.875: Alex, who paid 120, is owed 71.125, and Jo, who paid nothing, owes 48.875. Everyone with a negative balance pays someone with a positive one.

What is the fewest number of payments needed to settle up?

At most one fewer than the number of people with a non-zero balance, and fewer when the balances split into groups that cancel out, since each group of g people needs g − 1 payments. Tom Verhoeff's 2004 paper shows that finding the minimum is at least as hard as the subset-sum problem, so an exact answer needs a search.

Why can paying off the biggest debts first need extra payments?

It can miss groups that cancel out. With balances of +4, +3, +2, −5 and −4 (people A to E in the worked example), matching the largest amounts first takes 4 payments. Splitting them into {+4, −4} and {+3, +2, −5} settles the first pair in 1 payment and the trio in 2, so 3 in total.

What if some costs are shared by only part of the group?

This splitter shares every cost equally among everyone listed. For a cost that only some people share, such as two people's train tickets, run it separately with just those people, then add the payments from both runs. The combined list settles every debt, though it may use one or two more payments than a single optimised plan.

「Group expense splitter for trips and parties」の精度はどのくらいですか?

精度は入力値と計算方法の前提に依存します。十進演算には有効数字50桁を使いますが、推定、数値計算手法、元データの精度はそれより低い場合があります。表示の丸め処理でこれらの制約がなくなるわけではありません。 独立した出典の解答と照合した計算例:4。 例えば、「Three payers and one person who paid nothing」はPython decimal: 195.50/4 = 48.875; balances −48.875, −18.875, −3.375 rounded half-even to cents; 3 payments by brute-force subset searchと照合しています。

この計算方法の出典は何ですか?

Verhoeff, T. (2004). Settling multiple debts efficiently: an invitation to computing science. Informatics in Education 3(1).

この計算機について

share=∑paidn,balancei=paidi−share,payments=k−max⁡(zero-sum groups)\text{share} = \frac{\sum \text{paid}}{n},\qquad \text{balance}_i = \text{paid}_i - \text{share},\qquad \text{payments} = k - \max(\text{zero-sum groups})

出典

  1. Verhoeff, T. (2004). Settling multiple debts efficiently: an invitation to computing science. Informatics in Education 3(1)

出典と照合済み

この計算機には、独立した出典の解答を使った計算例が 4 件あります。テストに組み込まれており、ここでも実行できます。

関連する計算ツール