Skip to content

Instantly share code, notes, and snippets.

@k4zy
Created December 4, 2013 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4zy/7786823 to your computer and use it in GitHub Desktop.
Save k4zy/7786823 to your computer and use it in GitHub Desktop.
import math
import string
class BinPacking:
def minBins(self, tuple_items):
items = list(tuple_items)
bin_count = 0
while 100 in items and 200 in items:
items.remove(100)
items.remove(200)
bin_count +=1
while items.count(100) >=3:
for i in range(3):
items.remove(100)
bin_count +=1
items.sort()
while len(items) >0:
if len(items) == 1:
bin_count +=1
return bin_count
if sum(items[:2]) > 300:
bin_count += len(items)
return bin_count
target_item = items.pop(0)
best_index = 0
for index in range(len(items)):
if ( items[index] + target_item ) <= 300 and items[index] > items[best_index] :
best_index = index
items.pop(best_index)
bin_count+=1
return bin_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment