# How to calculate percentage distribution after changing the set

My first language is not English so I apologize if I use incorrect terminology.

EDIT: There is a better example with pictures at the end of the post

For the sake of argument: I have a table of 10 whole numbers 1..10. I need to assign each row a value (a, b, c, d) with the following distribution.

All rows must have assigned value - so the distribution must be 100%

+-------+--------------+
| value | distribution |
+-------+--------------+
| a     | 35%          |
| b     | 25%          |
| c     | 30%          |
| d     | 10%          |
+-------+--------------+


Because I have a whole number, I use Largest Remainder Method to calculate how many rows are affected

+-------+--------------+----------+
| value | distribution | rowCount |
+-------+--------------+----------+
| a     | 35%          |        4 |
| b     | 25%          |        2 |
| c     | 30%          |        3 |
| d     | 10%          |        1 |
+-------+--------------+----------+


Now, this is the actual question: Suppose some of the values have been preassigned.

I have to calculate new percentage distribution on the subset (initial set minus preassigned) and this new percentage distribution must match the initial distribution. Like this:

+-------+------------------+-----------+-------------+----------------------+-----------------+
| value |   distribution   | rowCount  | preAssigned | remainingAssignments | NewDistribution |
+-------+------------------+-----------+-------------+----------------------+-----------------+
|       | initial set = 10 | using LRM |             | new subset = 6       |                 |
| a     | 35%              | 4         | 2           | 4-2 = 2              | 33.33%          |
| b     | 25%              | 2         | 1           | 2-1 = 1              | 16.66%          |
| c     | 30%              | 3         | 1           | 3-1 = 2              | 33.33%          |
| d     | 10%              | 1         | 0           | 1-0 = 1              | 16.66%          |
|       | total 100%       | total=10  | total = 4   | total = 6            | total = 99.98%  |
+-------+------------------+-----------+-------------+----------------------+-----------------+


Is there a function how to calculate the column NewDistribution having this information:

• initial distribution
• initial set size
• new subset size
• preassigned count per each value

I'm asking for a function, because I want to apply it to the whole set, not calculate new percentage row by row.

The solution must work for any row size and any number of values (provided the distribution is still 100%).

Bonus question:

How would I go if the preAssigned was larger than the rowCount for some of the values. (e.g.: preAssigned for a = 6)

I could never reach the optimal percentage, but still would like to come close to it - and all rows need to be assigned.

Example with pictures Adam, Bert, Cecil and Dan should get each a portion of the pie, according to their size. But because the boys were impatient, some of them ate a portion of their pie. What is the new percentage each of them should recieve of the remaining pie?

Bonus question: Adam ate more than half of the pie. How should the remaining pie be split, so the portions are as fair (and as close) to the original ratio.