Note that there are some explanatory texts on larger screens.

plurals
  1. PODistribute prizes for a tournament system
    primarykey
    data
    text
    <p>I'm looking for a way to distribute a number across x units. I don't even know how to put this words so I'll give an example:</p> <p>There's a tournament in which the total prize is $1000. I want that the top 20 winners/entrants will win something out of it.<br>I need a mathematical algorithm/formula which will distibute it across those players, and which gives me the power to control certain other factors of the distribution.</p> <p>A factor for example is that I want the top #1 winner will get $300. The top #2 winner will get smaller percentage of it. The total distribution must give everyone something, until the top #20 winner (the last one) which will get at least X$.<br> X$ is another factor I want to control.</p> <p>Any idea? Does this problem has a name (and what's that name is)? Any code example?</p> <p><strong>Edit #1 - my first proposal</strong>:</p> <pre><code>#include &lt;conio.h&gt; #include &lt;vector&gt; #define TOTAL 100 #define WINNERS 15 #define FIRST_WINNER_PERCENTAGE 0.30 void distribute_1(::std::vector&lt;double&gt; * const prizes) { prizes-&gt;clear(); double total = TOTAL; double winning_percentage = FIRST_WINNER_PERCENTAGE; double slope = 0.5; int winners = WINNERS; double winning = 0; for(int i = 0; i &lt; winners; i++, total -= winning, winning_percentage /= 2) { winning = total * winning_percentage; prizes-&gt;push_back(winning); } } void distribute_2(::std::vector&lt;double&gt; * const prizes) { prizes-&gt;clear(); double total = TOTAL; double winning_percentage = FIRST_WINNER_PERCENTAGE; double slope = 0.5; int winners = WINNERS; double winning = 0; for(int i = 0; i &lt; winners; i++, total -= winning/*, winning_percentage /= 2*/) { winning = total * winning_percentage; prizes-&gt;push_back(winning); } } void distribute_3(::std::vector&lt;double&gt; * const prizes) { prizes-&gt;clear(); double total = TOTAL; double winning_percentage = FIRST_WINNER_PERCENTAGE; double slope = 0.0005; int winners = WINNERS; double winning = 0; for(int i = 0; i &lt; winners; i++, total -= winning, winning_percentage -= slope) { winning = total * winning_percentage; prizes-&gt;push_back(winning); } } void distribute_4(::std::vector&lt;double&gt; * const prizes) { prizes-&gt;clear(); double total = TOTAL; double winning_percentage = FIRST_WINNER_PERCENTAGE; double slope = 1 / WINNERS; int winners = WINNERS; double winning = 0; for(int i = 0; i &lt; winners; i++, total -= winning, winning_percentage -= slope) { winning = total * winning_percentage; prizes-&gt;push_back(winning); } } void main() { ::std::vector&lt;double&gt; prizes; distribute_1(&amp;prizes); distribute_2(&amp;prizes); distribute_3(&amp;prizes); distribute_4(&amp;prizes); double total_granted = 0; for(int i = 0; i &lt; WINNERS; i++) { total_granted += prizes[i]; printf("%lf\n", prizes[i]); } printf("-\n%lf\n", total_granted); _getch(); } </code></pre> <p>This is as far as I could reach. The issue with this one is for example, if that if you set 'WINNERS' to 5 for example, the algorithm doesn't reach the 'TOTAL' amount (100 in this example) or even closer (I get a total of 83).</p> <p><strong>Cristy's solution</strong>:</p> <pre><code>#include &lt;conio.h&gt; #include&lt;iostream&gt; //using arithmetic progression using namespace std; int i; float ratio; float first_prize; float s; int main() { float money=1000; const int total_prizes = 10; float last_prize = 99; float prizes[total_prizes+1]; /**/first_prize=2*money/total_prizes-last_prize; //last member of the progresion ratio=(first_prize-last_prize)/(total_prizes-1); prizes[total_prizes]=last_prize; for(i=total_prizes-1;i&gt;=1;i--){ prizes[i]=prizes[i+1]+ratio; money-=prizes[i]; } for(i=1;i&lt;=total_prizes;i++){ printf("%d) %.2f\n",i,prizes[i]); s+=prizes[i]; } printf("TOTAL SUM:%.2f\n",s); printf("Ratio: %.2f", ratio); _getch(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload