AoC2020/day01/solution2.rb

17 lines
494 B
Ruby
Raw Normal View History

2020-12-02 15:47:05 +00:00
#!/bin/env ruby
#Find the three entries that sum to 2020; what do you get if you multiply them together?
numbers = File.readlines('./input')
numbers.map! { |s| s.to_i}
numbers.each do |num1|
numbers.each do |num2|
numbers.each do |num3|
sum = num1 + num2 + num3
puts num1.to_s + '+' + num2.to_s + '+' + num3.to_s + '=' + sum.to_s
if sum == 2020
puts num1 * num2 * num3
exit
end
2020-12-02 16:19:54 +00:00
end
2020-12-02 15:47:05 +00:00
end
end