Skip to content

Instantly share code, notes, and snippets.

@danreedy
Created April 9, 2012 17:30
Show Gist options
  • Save danreedy/2344889 to your computer and use it in GitHub Desktop.
Save danreedy/2344889 to your computer and use it in GitHub Desktop.
all combinations of four integers adding up to 100
haystack = []
0.upto(100) do |i|
0.upto(100) do |j|
0.upto(100) do |k|
0.upto(100) do |l|
test = [i,j,k,l].sort
unless haystack.include? test
puts "#{test.join(', ')}\n" if test.inject(&:+) == 100
haystack << test
end
end
end
end
end
puts "========"
puts haystack.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment