solved part 1

master
Jeff Yates 2020-12-09 11:29:07 -05:00
parent 21e651af44
commit 1cd2b62ba0
1 changed files with 18 additions and 0 deletions

18
day09/solution1.rb Executable file
View File

@ -0,0 +1,18 @@
#!/bin/env ruby
def valid_nums (nums)
nums.map { |num| nums
.map { |sub| sub + num if sub != num }}.flatten.uniq.compact
end
numbers = File.readlines('./input').to_ary.map(&:strip!).map(&:to_i)
preamble = 25
numbers.each.with_index do |number, i|
next if i < preamble
if !valid_nums(numbers[(i-preamble)..(i-1)]).include?(number)
puts number
break
end
end