Home > other >  How to make approximate equal division of task between given number of people?
How to make approximate equal division of task between given number of people?

Time:11-30

Let say task is to divide 33 tables between 3 people. If equally divided, then output is [11, 11, 11] and if number of tables is 35 tables, then output should be [12, 12, 11].

When I am trying to divide, I get [11, 11, 11, 1, 1]. I need help to solve this in python. This is part of my main problem statement.

Here is my code:

div2 = count2 // len(ri_ot_curr) # equal division of other tables
rem2 = 0
rem2 = count2 % len(ri_ot_curr) # remaining tables tables unallocated
for i in range(len(ri_ot_curr)):
    c = 0
    for start in range(len(tft)):
        if tft.loc[start, 'Release Date'] == 'Release ' str(release_date) a: #some condition
            tft.loc[start, 'Quant RI - Table'] = ri_ot_curr[i]
            tft.loc[start, 'Date'] = date_tft()
            c = c 1
            if c == div2:
                break

    if rem2 > 0:

         ri_ot_rem = random.sample(ri_ot_curr, rem2)
         for i in range(len(ri_ot_rem)):
             for start in range(len(tft)):
                 if tft.loc[start, 'Release Date'] == 'Release ' str(release_date):#some condition
                     tft.loc[start, 'Quant RI - Table'] = ri_ot_rem[i]
                     tft.loc[start, 'Date'] = date_tft()   
                     break

CodePudding user response:

i hope i understood you correctly, if i did this code will do the trick:

number_of_tables = 35
number_of_people = 3

tables_list = [int(number_of_tables / number_of_people) for _ in range(number_of_people)]

remainder = number_of_tables % number_of_people

for index in range(remainder):
    tables_list[index]  = 1

print(tables_list)
  • Related