Skip to content

Instantly share code, notes, and snippets.

@oleksiilevzhynskyi
Created June 18, 2012 17:26
Show Gist options
  • Save oleksiilevzhynskyi/2949524 to your computer and use it in GitHub Desktop.
Save oleksiilevzhynskyi/2949524 to your computer and use it in GitHub Desktop.
the sum of two
t1 = Time.now
file = File.new(ARGV[0] || "input.txt", "r")
numbers = file.readlines.map!(&:to_i)
p Time.now - t1
[231552, 234756, 596873, 648219, 726312, 981237, 988331,1277361,1283379].each do |x|
tmp = Array.new(numbers.size)
time = Time.now
res = numbers.detect { |el| tmp[el] || ((x - el) > 0 && (tmp[x - el] = true) && false) } ? 'yes' : 'no '
p "#{'%7.0f' % x} - #{res} - #{Time.now - time}"
end
file = File.new(ARGV[0] || "input.txt", "r")
numbers = file.readlines.map!(&:to_i)
[231552, 234756, 596873, 648219, 726312, 981237, 988331,1277361,1283379].each do |x|
hsh = {}
time = Time.now
res = numbers.detect { |el| hsh[el] || ((x - el) > 0 && (hsh[x - el] = true) && false) } ? 'yes' : 'no '
p "#{'%7.0f' % x} - #{res} - #{Time.now - time}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment