Skip to content
Create a gist now

Instantly share code, notes, and snippets.

If we assume each weight must be different...
def calculate_combination(num_elements, limit)
combos =
base_array = (1..limit).to_a
base_array.combination(num_elements).each do | group |
combos.add(group.sort) if group.inject(0, :+) == limit
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.