Deviding N(1,2,3,..,N) part from numeric list as summation of each values(don't sorted) has highest as possible.

Emile van Sebille emile at fenx.com
Mon Oct 10 12:48:15 EDT 2016


On 10/10/2016 09:25 AM, Nuen9 wrote:
>> Hi!
>>
>> Could it be, "Nuen9", that you would like to find a split where the
>> split sums are close to each other? In other words, you define the
>> number of splits (in your example: 3) and the algortihm should test all
>> possible combinations and select the split where the sum differences are
>> smallest.
>>
>> Best,
>> Kimmo
>
> Yes it is, I want example python code for finding my answers but I don't code my answers. please help me.
>

Here's one way:

n=3
land = [10,20,30,40,110,50,18,32,5]
lsum = sum(land)
lavg = lsum/n
close = lavg/n
idx = 0
lnsums = [0]*n
ln=0
while idx < len(land) and ln<n:
   lnsums[ln]+= land[idx]
   idx += 1
   if lnsums[ln] > lavg-close:
     ln+=1

print lnsums


--

Emile





More information about the Python-list mailing list