aoc/2020/01/01.rb
2020-12-10 17:11:17 -06:00

13 lines
413 B
Ruby

def find_product_of(n)
puts File
.readlines("input.txt") # read input lines as array entries
.map(&:to_i) # convert each array entry to integer
.permutation(n) # create Enumerable with all permutations of n entries
.find { |array| array.sum == 2020} # find a permutation that sums to 2020
.inject(:*) # get the product of that array
end
puts "Part 1: "
find_product_of(2)
puts "Part 2: "
find_product_of(3)