Skip to content

Instantly share code, notes, and snippets.

@peterc
Created December 9, 2020 11:22
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 peterc/515f260c68c89a7460602fcf0969ecd4 to your computer and use it in GitHub Desktop.
Save peterc/515f260c68c89a7460602fcf0969ecd4 to your computer and use it in GitHub Desktop.
Advent of Code 2020 Day 9 in Ruby
nums = $<.readlines.map(&:to_i)
w = 25
w.upto(nums.length - 1) do |i|
p nums[i] if nums[i-w, w].combination(2)
.map(&:sum)
.all? { |x| x != nums[i] }
end
w.times do |cw|
nums.each_cons(cw + 1)
.detect { |x| x.size > 1 && x.sum == 57195069 }
.tap { |x| puts x.min + x.max if x }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment