18 lines
399 B
Ruby
18 lines
399 B
Ruby
|
#!/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
|