Groovy web console

subscribe to the feed Subscribe
to this
site

Cedric's Balance Challenge

Published 9 years ago by Jim White
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
weights = [1..10, 1..20, 1..20, 1..40].combinations().grep { it.sum() == 40 }.collect { it.sort() }.unique()
println (weights.grep { it.inject([0], { a, v -> a + a*.plus(v) + a*.plus(-v) }).containsAll ( 1..40 )})