Created
December 9, 2020 11:22
-
-
Save peterc/515f260c68c89a7460602fcf0969ecd4 to your computer and use it in GitHub Desktop.
Advent of Code 2020 Day 9 in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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