All challenges

Challenge 23

Who Owes Whom After the Trip?

Six friends paid for different things on a trip. Work out the fewest bank transfers that make everyone square again.

IntermediateComplexity:Time: 30–40 min

Your task

Six friends paid for different things on a trip. Work out who should pay whom, and keep it to the fewest transfers that settle everything.

Your bonus task

Three of the costs were paid in dollars or pounds. Convert them at that day's ECB rateThe daily reference exchange rate published by the European Central Bank. Asking for a past date always gives the same answer. before settling, and show how the answer changes.

Example use cases

  • Six friends back from a week away, with ten receipts and nobody keen to do the maths.
  • Flatmates splitting a month of shared shopping without an app that wants their bank details.
  • Any job where a pile of numbers has to become a short list of actions – stock to reorder, invoices to chase, shifts to swap.

Before you start

  1. 01

    Sign up for n8n Cloud or open your n8n workspace. No other account is needed.

  2. 02

    The receipts are a practice file: trip-expenses.json holds six people and ten costs, each with a date, who paid, an amount and a currency.

  3. 03

    Exchange rates for the bonus come from the free Frankfurter API, which needs no key and serves the European Central Bank's daily rates. Because the trip is in the past, the rates never change.

  4. 04

    You will write a few lines of JavaScript in the Code node. The solution is about fifteen lines, and every other step is an ordinary node.

What the workflow must do

  1. 01

    The workflow prints a short list of transfers, each with who pays, who is paid and how much, and nobody both sends and receives money.

  2. 02

    For the euro costs the total is 2261.50 euros, a fair shareThe total cost divided by the number of people. Everyone should end up having paid this much, no matter who held the card on the day. of 376.92 each, and five transfers settle it, the largest being Chiara paying Bruno 376.92.

  3. 03

    Chiara paid for nothing in euros and is still included in the split – a person who never paid must not be left out of the share. Bonus: with the dollar and pound costs converted the total becomes 3226.98, and the largest transfer is Dmytro paying Bruno 353.43.

Solution

See the workflow challenge answer

Reveal the completed workflow only when you are ready to compare it with your own.

Submit as solved

Ready to submit?

Submit when your team has a working workflow to demonstrate.

Solution

Reveal the workflow solution?

This will show the completed workflow for this challenge. Are you sure you want to continue?

Mentor review

Find a mentor and ask them to review.

Show them your working workflow. Once they approve it, collect the balloon for this challenge.