Skip to content

Instantly share code, notes, and snippets.

@MarshalW
Created July 3, 2013 06:18
Show Gist options
  • Save MarshalW/5915811 to your computer and use it in GitHub Desktop.
Save MarshalW/5915811 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
packageCounts='600,500,300,100'.split(',')
packageSum=0
temp=[]
subPackageCounts=[]
for i in range(len(packageCounts)):
currentCount=int(packageCounts[i])
print currentCount
if(packageSum+currentCount<1000):
packageSum+=currentCount
temp.append(currentCount)
else:
subPackageCounts.append(temp);
temp=[]
temp.append(currentCount)
packageSum=currentCount
if(len(temp)>0):
subPackageCounts.append(temp)
temp=[]
packageSum=0
print subPackageCounts
for i in range(len(subPackageCounts)):
countList=subPackageCounts[i]
result=''
count=0
for j in range(len(countList)):
result+=str(countList[j])+' '
count+=countList[j]
print 'write to file: '+result+', sum: '+str(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment