I am building a program that selects max elements from a list which sums to a given input value
load_data = [1, 2, 3, 4, 10, 20]
eg user inputs 30
select 20 and 10
or user inputs 35
select 20, 10, 4 and 1
since they are the possible largest elements that sum up to 30
or 35
code
def process(m):
print m
def selection():
aux = range(len(load_data))
global value # <- value is the input
while aux and value > 0:
posit = max(aux) >= value
index = aux[posit]
elem = load_data[index]
value = value - posit # <- subtract max value from input and repeat process
del aux[posit]
process(elem)
output always prints
2
3
1
4
10
20