Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
If we assume each weight must be different...
def calculate_combination(num_elements, limit)
combos = SortedSet.new
base_array = (1..limit).to_a
base_array.combination(num_elements).each do | group |
combos.add(group.sort) if group.inject(0, :+) == limit
end
combos
end
combos = calculate_combination(4, 40)
combos.each { |weight_combo|
weight_combo.each { |val| print "#{val} " }
print "\n"
}
puts combos.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.