RosettaCodeData/Task/Knapsack-problem-0-1/Groovy/knapsack-problem-0-1-1.groovy
2023-07-01 13:44:08 -04:00

9 lines
266 B
Groovy

def totalWeight = { list -> list*.weight.sum() }
def totalValue = { list -> list*.value.sum() }
def knapsack01bf = { possibleItems ->
possibleItems.subsequences().findAll{ ss ->
def w = totalWeight(ss)
350 < w && w < 401
}.max(totalValue)
}