m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/09/b.rb
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:25:06 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:25:06 +0100
commit15c6d8d79d9ec00a7abb14f90bd65547893c76f2 (patch)
treed710511f35e0da2ade30e35c21a844adb1de8734 /09/b.rb
parent1362f76e60c32a7bf0e7240b01524d16734f8dd4 (diff)
Add day 9
Diffstat (limited to '09/b.rb')
-rw-r--r--09/b.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/09/b.rb b/09/b.rb
new file mode 100644
index 0000000..c95c1c9
--- /dev/null
+++ b/09/b.rb
@@ -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