Let's define some names:
- : the number of parties
- : the fee coefficient (a coefficient between 0 and 1)
- : the fee constant, applied after the coefficient is applied
- : the initial amount
- : the gross payment made in each transaction
- : the net amount that every one will have in the end
We are asked to derive for given , , and with the following constraints:
In a transaction, the received amount () is the paid amount () with fees applied:
= (1 − ) −
After making 4 transactions, the payer is left with the same amount as the receivers have ():
= − ( − 1)
This set of equalities can be resolved as follows:
(1 − ) − = − ( − 1)
⇔ (1 − ) + ( − 1) = +
⇔ ( − ) = +
⇔ = ( + ) / ( − )
For the given example, we have this input:
= 5
= 0.019
= 0.10
= 1000
The result is thus:
= ( + ) / ( − ) = (1000 + 0.10) / (5 − 0.019) = 200.78297530616342...
Verification of constraints:
= (1 − ) − = 200.78297530616342 * (1 − 0.019) − 0.10 = 196.8680987753463...
= − ( − 1) = 1000 − 200.78297530616342 * (5 − 1) = 196.8680987753463...
As we deal with dollars, we must round to the cent, and so there will be slight divergence.
The first party will pay 200.78 in 4 transactions and after these, each party will have 196.87, except the first party; they will have one cent more: 196.88
Snippet
Here is a little runnable code, where you can input the parameters and see the result:
const roundCents = x => Math.round(x * 100) / 100;
// Apply formula, but rounded to the cent
function solve (n, r, c, a) {
const g = roundCents((a + c) / (n - r));
const p1 = roundCents(g * (1 - r) - c);
const p2 = roundCents(a - g * (n - 1));
return [g, p1, p2];
}
// I/O management
document.addEventListener("input", refresh);
const inputs = document.querySelectorAll("input");
const outputs = document.querySelectorAll("span");
function refresh() {
const [n, pct, c, a] = Array.from(inputs, input => +input.value);
const results = solve(n, pct/100, c, a);
outputs.forEach((output, i) => output.textContent = results[i].toFixed(2));
}
refresh();
input { width: 5em}
Number of parties: <input type="number" value="5" min="2"><br>
Fee percentage: <input type="number" value="1.9" min="0" max="100" step="0.1"><br>
Fee constant: <input type="number" value="0.10" min="0" step="0.01"><br>
Initial amount: <input type="number" value="1000" min="0" step="0.01"><br>
<hr>
Gross payments: $<span></span><br>
Net received: $<span></span><br>
Net remaining: $<span></span><br>