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