Divide x into y parts by decreasing value

346 Views Asked by At

If I had $1000(variable) and I want to split that amount up and give it to 20(variable) people, but rather than give it evenly to each person, I want to give more to the 1st person, and the 2nd person, etc.

So the 20th person gets the least, and the 5th person gets the 5th most.

How would I achieve that?

Thanks

2

There are 2 best solutions below

2
On

There are a lot of ways to do this.

Say you have $x$ amount of things to distribute amongst $n$ people. One way to do it would be to let $k=\frac{2x}{n(n-1)}$. Then give the first person $nk$, the second person $(n-1)k$, and in general, the $i$th person $(n-i+1)k$. note that this means that the total amount given out is $nk+(n-1)k+\ldots+k=\frac{n(n-1)}{2}k=x$.

0
On

Here are some simple ways to do it:

If there are $y$ people, you can start by giving $1$ to the $y$th (last) person, $2$ to the $(y-1)$st person (the one before the last), $3$ to the $(y-2)$nd person, and so forth. By continuing in this way you eventually will give $(y-1)$ to the second person and $y$ to the first.

If you are allowed to divide the amount $x$ in such a way that the last person gets nothing, then instead of the amounts in the previous paragraph you can give everyone $1$ less: $0$ to the $y$th person, $1$ to the $(y-1)$st person, and so forth, so that you give $(y-1)$ to the first person.

When you have done all this, you will have given a total of $\frac{y(y+1)}2$ if the last person got $1,$ or $\frac{y(y-1)}2$ if the last person got $0.$ If the amount you have already given is greater than the total amount you started with, $x,$ and your job is to give a different integer amount to each of the $y$ people, and you have already given the last person the minimum amount you can ($0$ or $1$ depending on the rules for the distribution), then unfortunately the job is impossible and you must declare failure.

If after giving the amounts already mentioned, there is some amount of the prize remaining, then you just have to give the remaining prize in such a way that you don't give more to the $(k+1)st$ person than you give to the $k$th person.

One way to do this is to just give all the remaining prize to the first person. There are other methods you can use, of course. But that choice comes down to any other constraints you have, and when you have satisfied those constraints (if there are any) then it comes down to personal preference.

If you are allowed to give non-integer amounts then as far as the mathematics is concerned, you will always be able to divide the prize as required. Just "scale down" the amounts you give each person so the total does not exceed $x.$ In this case, if you are doing this in software then you should not use "integer" variables in any of your calculations or "cast" any of the variables to integers, because in some cases that will prevent you from getting non-integer results when you need them (for example when $y = 20$ and $x = 100$).