[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(ledger?) The fair Christmas problem: splitting expenses automatically
From: |
Uwe Brauer |
Subject: |
(ledger?) The fair Christmas problem: splitting expenses automatically |
Date: |
Wed, 29 Dec 2021 17:09:40 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Hi
I am not sure whether this is the right place to ask this, but anyhow.
Suppose two friends want to buy Christmas presents, but when they have
finished, they want to have spent the same amount of money. If they
don't a compensation must be transferred.
Here is an example
** Start
#+name: presents
#+begin_src ledger
2010/01/01 * Starting balance
assets:bank:savings 0
income:starting balances
2021/12/01 User1:Jacket
expenses:User1:Jacket 80
income:User1:creditcard1
2010/07/24 User1:Pajama
expenses:User1:Pajama 30
income:User1:creditcard1
2010/07/23 User2:Flowers
expenses:User2:Flowers 20
income:User2:creditcard2
2010/07/23 User2:ChristmasTree
expenses:User2:ChristmasTree 40.00
income:User2:creditcard2
#+end_src
#+RESULTS: presents
#+begin_example
170 expenses
110 User1
80 Jacket
30 Pajama
60 User2
40 ChristmasTree
20 Flowers
-170 income
-110 User1:creditcard1
-60 User2:creditcard2
--------------------
0
#+end_example
So user1 spent 110, while user2 spent 60
** Compensation manually
So the compensation is (trivally)
| User1 | User2 | User2-->Uwer1 |
|-------+-------+---------------|
| 110 | 60 | -25 |
#+TBLFM: $3=($2-$1)/2;f2
Leading to
#+name: compensated
#+begin_src ledger
2010/01/01 * Starting balance
assets:bank:savings 0
income:starting balances
2021/12/01 User1:Jacket
expenses:User1:Jacket 80
income:User1:creditcard1
2010/07/24 User1:Pajama
expenses:User1:Pajama 30
income:User1:creditcard1
2010/07/23 User2:Flowers
expenses:User2:Flowers 20
income:User2:creditcard2
2010/07/23 User2:ChristmasTree
expenses:User2:ChristmasTree 40.00
income:User2:creditcard2
2010/07/23 User2:User1-Compensation
expenses:User2:User1-Compensation 25.00
expenses:User1:User1-Compensation
#+end_src
#+RESULTS: compensated
#+begin_example
170 expenses
85 User1
80 Jacket
30 Pajama
-25 User1-Compensation
85 User2
40 ChristmasTree
20 Flowers
25 User1-Compensation
-170 income
-110 User1:creditcard1
-60 User2:creditcard2
--------------------
0
#+end_example
The question is can this be done automatically?
By this I mean
can
2010/07/23 User2:User1-Compensation
expenses:User2:User1-Compensation 25.00
expenses:User1:User1-Compensation
Somehow be generated automatically?
smime.p7s
Description: S/MIME cryptographic signature
- (ledger?) The fair Christmas problem: splitting expenses automatically,
Uwe Brauer <=