m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/09/b.rb
blob: c95c1c97a5bc35544edd582fc7335ddaa5131e67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sum = 400480901
lines = File.readlines('input.txt').map {|l| l.to_i}

current_list = []
current_sum = 0

lines.each do |n|
  current_sum += n
  current_list.push n

  while current_sum > sum && current_list.size > 1
    current_sum -= current_list.first
    current_list.shift
  end

  if current_sum == sum && current_list.size > 1
    puts current_list.min + current_list.max
  end
end