RosettaCodeData/Task/Knapsack-problem-0-1/Groovy/knapsack-problem-0-1-1.groovy

10 lines
266 B
Groovy
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
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)
}