Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Most Efficient Cutting by zhang9820110
import itertools
def most_efficient_cutting(bom):
tmax = sum(bom) % 6000
w = 0
while len(bom) > 0:
rs = []
st = False
for i in range(len(bom)):
for x,y in [(sum((bom[j] for j in c)),c) for c in itertools.combinations(range(len(bom)),i+1)]:
if x == 6000 or x == tmax:
rs = [(x ,y)]
st = True
break
elif x < 6000:
rs.append((x, y))
if st:
st = False
break
ml = max((x[0] for x in rs))
w += 6000 - ml
for x ,y in rs:
if x == ml:
bom = [bom[i] for i in range(len(bom)) if i not in y]
break
return w
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert(most_efficient_cutting([3000, 2200, 2000, 1800, 1600, 1300]) == 100)
assert (most_efficient_cutting([4000, 4000, 4000]) == 6000), "wasted: 3x2000"
assert(most_efficient_cutting([1]) == 5999), "5999"
assert(most_efficient_cutting([3001, 3001]) == 5998), "2x2999"
assert(most_efficient_cutting([3000, 2200, 1900, 1800, 1600, 1300]) == 200), "2x5900"
assert(most_efficient_cutting([3000]) == 3000)
assert(most_efficient_cutting([3000, 2200, 2000, 1800, 1600, 1400]) == 0)
print('"Run" is good. How is "Check"?')
Nov. 19, 2017
Comments: