m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/09/b.rb
diff options
context:
space:
mode:
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