Osama Rasheed - 4 months ago 48

Python Question

There is a X sum and I have to find out share of Nth person according to their ranks. For example:

`There are 5 persons (N) and amount is said to be 100 (X).`

Now the first person gets the most and last person gets the least, and other gets according to their rank wise in order. Like this:

1st -> 30

2nd -> 25

3rd -> 20

4th -> 15

5th -> 10

There could be other possible combination of dividing this share rank wise, but that won't be much fair division either first rank would be getting most and others less, so I am seeking a formula which make it sure division is fair enough to be rank wise.

This is need to be done in Python. Any ideas?

Answer

If the division is to be such that the difference is constant, you know that the middle person (`N/2`

) will get `X / N`

. The person at `N/2-1`

will get `X / N + difference`

, `N/2-2`

will get `X / N + 2*difference`

, etc.