Question: Splitwise is a popular app that allows a group of people to settle debts to one another after multiple transactions where, in each transaction, one

Splitwise is a popular app that allows a group of people to settle debts to one another after multiple transactions where, in each transaction, one person pays for the group. Suppose Ross and Lily are joined by Alice and the three people go on a trip. Alice, Lily, and Ross each pay for separate meals that the three agree to split evenly. I.e., Alice pays X for meal 1, Lily pays Y for meal 2, and Ross pays Z for meal 3, and they agree to settle debts so that everyone pays (X+Y+Z)/3 by the end of the trip. provide a function in R programming named splitwise that takes in arguments for how much Alice, Lily, and Ross spent on their meals and outputs the withdraws and transfers such that the three settle up their debts to each other in the most efficient way possible.

First, you will need to withdraw the amount each have spent on meals. Then, transfer money around in the least number of transactions such that debts are settled. Kudos for efficient coding here! Use of many if statements is OK.

Note: You will need to consider the following 3 cases: 1. Where only one person needs to pay one other person. 2. Where one person needs to pay two people. 3. Where two people need to pay one person.

provide the r code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!