JSFiddle - React, Tailwind, and code Playground
JavaScript
const r = 0.3107954365513382, dr = 0.22339354437585907;
const sin45deg = Math.sqrt(2)/2;
const x = t => r * sin45deg * (1 - t + Math.sin(t) - Math.cos(t) + Math.PI) + dr,
y = t => r * sin45deg * (1 + t - Math.sin(t) - Math.cos(t) - Math.PI) + dr,
yd = t => r * sin45deg * (1 - Math.cos(t) + Math.sin(t));
const getXForY = y0 => {
let t = Math.PI, yt = y(t) - y0;
for(let i = 0; i < 10; i++){
const tNext = t - yt / yd(t);
yt = y(tNext) - y0;
const dt = tNext - t;
t = tNext;
if(Math.abs(yt) < 1e-20 || Math.abs(dt) < 1e-15){
break;
}
}
return x(t);
}
const paretoDistributionPredictionFor = (numberOfPeople, personAtIndex) => {
if(personAtIndex < 1 || personAtIndex > numberOfPeople){
return null;
}
const fracInStart = (personAtIndex - 1)/numberOfPeople,
fracInEnd = personAtIndex/numberOfPeople;
const fracOutStart = 1 - getXForY(1 - fracInStart),
fracOutEnd = 1 - getXForY(1 - fracInEnd),
fracOutDiff = -fracOutEnd + fracOutStart;
return (fracOutDiff * 100).toFixed(2).replace(/\.0+$/, '')+'%';
}
console.log('f(2, 1) = ' + paretoDistributionPredictionFor(2, 1));
console.log('f(2, 1) = ' + paretoDistributionPredictionFor(2, 2));
console.log(Array(80).fill('-').join(''));
console.log('f(3, 1) = ' + paretoDistributionPredictionFor(3, 1));
console.log('f(3, 2) = ' + paretoDistributionPredictionFor(3, 2));
console.log('f(3, 3) = ' + paretoDistributionPredictionFor(3, 3));
console.log(Array(80).fill('-').join(''));
console.log('f(4, 1) = ' + paretoDistributionPredictionFor(4, 1));
console.log('f(4, 2) = ' + paretoDistributionPredictionFor(4, 2));
console.log('f(4, 3) = ' + paretoDistributionPredictionFor(4, 3));
console.log('f(4, 4) = ' + paretoDistributionPredictionFor(4, 4));