aoc/01/01.rb

13 lines
413 B
Ruby
Raw Normal View History

2020-12-02 13:11:58 +00:00
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)