RosettaCodeData/Task/Knapsack-problem-0-1/Groovy/knapsack-problem-0-1-1.groovy
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07: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)
}