5 kyu

Socialist distribution (performance edition)

Description:

This kata is based on the Socialist distribution by GiacomoSorbi. It is advisable to complete it first to grasp the idea, and then move on to this one.


Task

You will be given a list of numbers representing the people's resources, and an integer - the minimum wealth each person must possess. You have to redistribute the resources among the people in such way that everybody would fulfil the minimum-wealth requirement.

The redistribution step consists of 2 operations:

  • taking 1 unit of the resource from the first richest person in the list
  • giving 1 unit of the resource to the first poorest person in the list

This process is repeated until everybody hits the minimum required wealth level.

Note: there's always enough resources for everybody.

Example (step by step)

distribution([4, 7, 2, 8, 8], 5)  ==  [5, 6, 5, 6, 7]

0. [4, 7, 2, 8, 8]
          +  -
1. [4, 7, 3, 7, 8]
          +     -
2. [4, 7, 4, 7, 7]
    +  -
3. [5, 6, 4, 7, 7]
          +  -
4. [5, 6, 5, 6, 7]
Algorithms
Performance

Stats:

CreatedNov 16, 2019
PublishedNov 17, 2019
Warriors Trained372
Total Skips23
Total Code Submissions703
Total Times Completed44
Python Completions44
Total Stars8
% of votes with a positive feedback rating88% of 20
Total "Very Satisfied" Votes16
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes1
Total Rank Assessments4
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • FArekkusu Avatar
  • user9644768 Avatar
Ad