Rebalancing table with average value

Viewed 18

Looking for algorithm which will resolve my problem, i.e.

  1. Having a table with values: [6, 2, 3, 1]
  2. Get an average value per slice: 12/4 = 3
  3. Re-balance values in slice, i.e. I should get formulas something like: 1) 0, 2) 6-1, 3) 0, 4) 5-2. I.e. from highest value deduct amount need's for average. As result I will need to get slice [3, 3, 3, 3]

Thanks

0 Answers
Related