Suppose I have an array of n numbers. The rules for the array is as below:
- All the numbers must add up to 1000
- If a number changes (positive or negative), all the other numbers in the array must be adjusted so that the sum of the array is still 1000
- The hard part - all numbers must be greater than or equal to 0.
Number 1 and 2 can be easily done by getting the delta of change, and spreading the delta among the other numbers. The trick is condition 3.
There's a question asking for its application. The numbers are percentages to be fed into pie chart; the user can adjust each pie segment with a slider. As it is a pie chart using percentages, all the sliders must add up to 100% - meaning if the user drag the slider to reduce the size of one pie slice, all the other pie slices should increase. No slice of the pie should be less than 0 or more than 100.