Skip to content

Instantly share code, notes, and snippets.

@stormbrew
Created January 9, 2012 23:05
Show Gist options
  • Save stormbrew/1585510 to your computer and use it in GitHub Desktop.
Save stormbrew/1585510 to your computer and use it in GitHub Desktop.
a = 10
l = ARGV.collect {|x| x.to_i }
c = 0
i = 0
while i < (l.size - 2)
j = i + 1
while j < (l.size - 1)
k = j + 1
while k < (l.size)
puts "#{l[i]} + #{l[j]} + #{l[k]} == #{l[i] + l[j] + l[k]}"
c += 1
if (l[i] + l[j] + l[k] == a)
puts "found@#{i},#{j},#{k}: #{l[i]}+#{l[j]}+#{l[k]} == #{a} (#{c} cases)"
exit
end
k += 1
end
j += 1
end
i += 1
end
puts "Not found (#{c} cases)"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment