Python Forum
Dividing list into subsets
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dividing list into subsets
#6
DPaul,I wrote a piece of code only for 4 sticks. And here it is. It becomes apparent,that as the number of tourists grows the number of inner loops grows as well. So there I can’t yet adapt this code to random values(((As for sums,I assume,we could put them in the list? But as for loops,we should put some code in the function and then call it every time?...
d = list(map(int,input().split()))
sum1 = d[0]
sum2 = d[1]
sum3 = sum(int(d[m]) for m in range(2, int(len(d))))
i=2
k=2
max = 0
for j in range(1,len(d)-1): #(1)we are increasing the distance between the second and the first room
while sum3 != d[len(d)-1]:#(2)(we are increasing the distance between the second and the third room)
sum2+= d[i]
sum3-=d[i]
i+=1
a = min(sum1,sum2,sum3)
if max < a:
max=min(sum1,sum2,sum3)
sum1+=d[j]
i = k+1
sum2=d[i-1]
sum3 = sum(int(d[m]) for m in range(i, int(len(d))))
k += 1
print(max)

Unfortunately,the list is not always sorted
Reply


Messages In This Thread
Dividing list into subsets - by Michael11 - Oct-01-2020, 12:26 PM
RE: Dividing list into subsets - by deanhystad - Oct-01-2020, 09:08 PM
RE: Dividing list into subsets - by Michael11 - Oct-02-2020, 06:43 AM
RE: Dividing list into subsets - by deanhystad - Oct-02-2020, 10:34 PM
RE: Dividing list into subsets - by DPaul - Oct-04-2020, 09:47 AM
RE: Dividing list into subsets - by Michael11 - Oct-04-2020, 10:23 AM
RE: Dividing list into subsets - by DPaul - Oct-04-2020, 05:13 PM
RE: Dividing list into subsets - by Katenn - Oct-04-2020, 06:13 PM
RE: Dividing list into subsets - by DPaul - Oct-05-2020, 06:34 AM
RE: Dividing list into subsets - by deanhystad - Dec-11-2020, 09:51 PM
RE: Dividing list into subsets - by deanhystad - Dec-12-2020, 06:18 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020