diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-12-25 15:25:06 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-12-25 15:25:06 +0100 |
commit | 15c6d8d79d9ec00a7abb14f90bd65547893c76f2 (patch) | |
tree | d710511f35e0da2ade30e35c21a844adb1de8734 /09/b.rb | |
parent | 1362f76e60c32a7bf0e7240b01524d16734f8dd4 (diff) |
Add day 9
Diffstat (limited to '09/b.rb')
-rw-r--r-- | 09/b.rb | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -0,0 +1,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 |