Created
April 9, 2012 17:30
-
-
Save danreedy/2344889 to your computer and use it in GitHub Desktop.
all combinations of four integers adding up to 100
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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