Skip to content

Instantly share code, notes, and snippets.

@cowlibob
Created December 1, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowlibob/d6c651efc1be4335672f41b9ad679231 to your computer and use it in GitHub Desktop.
Save cowlibob/d6c651efc1be4335672f41b9ad679231 to your computer and use it in GitHub Desktop.
require 'pathname'
values1 = Pathname.new('/users/james/advent_of_code_input_1.txt').readlines("\n").map{|l| l.chomp.to_i}.permutation(2).select{|a,b| a + b == 2020}.map{|a, b| {product: a * b, values: [a, b]}}
puts "Part 1"
puts "Output = #{values1.first[:product]}"
values2 = Pathname.new('/users/james/advent_of_code_input_1.txt').readlines("\n").map{|l| l.chomp.to_i}.permutation(3).select{|a,b,c| a + b + c == 2020}.map{|a, b, c| {product: a * b * c, values: [a, b, c]}}
puts "Part 2"
puts "Output = #{values2.first[:product]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment