Why isn’t the for loop iterating through 1?
We will have a much easier time with this question if you post raw code, not just a picture.
def full_bin(list_in, max): count = -1 left = list_in bin_f =  for x in list_in: print x ind_x = list_in.index(x) stop = 0 for y in list_in[ind_x + 1:]: print "(%d)" % (y) if stop == 1: pass elif x + y == max: bin_f.append() count += 1 bin_f[count].append(left.pop(left.index(x))) bin_f[count].append(left.pop(left.index(y))) stop = 1 return bin_f print full_bin([3, 2, 1, 5, 4], 5)
what it prints out:
What is the objective of the program? To return a list of addends that sum to max?
Its the full bin packing algorithm. Its where you have list of objects of different sizes and you have to fit it into different bins with a max size.
So you want output like,
[[3,2], [1,4], ]
This part of the code is pairing up two numbers in the list that have a total sum equal to the maximum size.
yeah. The lists within the lists represent the different bins
here’s another failed attempt that kind of worked.
The part where it stops working is because some numbers are not iterated through the for loop.
Btw the first function is a different algorithm that does the same thing but does not lead to the best solution. It has to be used for this algorithm to be completed.
Can we assume that there are no values in the list greater than max?
If so, then,
>>> def full_bin(x, max): bin_f =  temp = sorted(x) while len(temp) > 0: if temp + temp[-1] == max: bin_f.append([temp.pop(0), temp.pop(-1)]) elif temp[-1] == max: bin_f.append([temp.pop(-1)]) return bin_f >>> n = [3,2,1,5,4] >>> print (full_bin(n,5)) [, [1, 4], [2, 3]] >>>
Thanks for taking the time to help me out. Really appreciate it.