There is a game where you need to gather money from people participating to it and when you have the total you need to divide it in order to put a "reasonable amount" for each of the n prizes they will be able to win.
E.g. in general we usually make the calcution approximately, so in case you have a total of 8$ (t = 8) and 5 prizes (n = 5) we could divide the total into:
- prize 1:
0.8$ - prize 2:
1.2$ - prize 3:
1.5$ - prize 4:
1.9$ - prize 5:
2.6$
As you can see it would be important to have prize n to be "more important" than prize 1, in general.
I would like to find a rule to obtain those prize values dynamically according to:
t = total amount of moneyn = number of prizesy = a variable factor to provide in order to abtain different combinations of prize values, in a way that a lower 'y' value means being more "fair" in giving values to prizes, on the contrary a higher 'y' value means increasing the difference between prize 1 and prize 'n'
E.g. in case I want to be more "fair" a possibility would be:
- prize 1:
1.2$ - prize 2:
1.4$ - prize 3:
1.6$ - prize 4:
1.8$ - prize 5:
2.0$
or
- prize 1:
1.1$ - prize 2:
1.2$ - prize 3:
1.5$ - prize 4:
2.0$ - prize 5:
2.2$
but I really have no idea about what formula or algorithm I could use to make that calculation by simply having as input (y, n and t) and how to be able to provide a y factor to use in order to vary the resulting prize values.
Any idea about it?
Thanks
var prizes = 5; var factor = 0.2; var prizeValues = []; var money = 0; for (var k = 1; k <= prizes; k++) { var calc = (prizes * ((1 + factor) ^ (k - 1))) * (factor / (((1 + factor) ^ prizes) - 1)); prizeValues.push(calc); money += calc; } console.warn(prizeValues); console.warn(money);but the result is:
– Frank Dec 31 '18 at 14:27[0.3333333333333333, 0, 1, 0.6666666666666666, 1.6666666666666667]and total money is3.666666666666667. What if I want to avoidoas value for ak?8as total amount of money and5as total number of prizes how do I rewrite the formulate that @JohnHughes provided? – Frank Dec 31 '18 at 17:00var calc = (totalMoney * ((1 + factor) ^ (k - 1))) * (factor / (((1 + factor) ^ prizes) - 1));withvar totalMoney = 8;. Still, when I run it I get[ 0.5333333333333333, 0, 1.6, 1.0666666666666667, 2.6666666666666665 ]and5.866666666666667so I have a0that I would not want and the totalmoneyis5.866666666666667but I expected it to be8at the end no? What am I doing wrong? – Frank Dec 31 '18 at 17:11