aboutsummaryrefslogtreecommitdiff
path: root/day01/part2
diff options
context:
space:
mode:
Diffstat (limited to 'day01/part2')
-rwxr-xr-xday01/part215
1 files changed, 15 insertions, 0 deletions
diff --git a/day01/part2 b/day01/part2
new file mode 100755
index 0000000..6f70fe7
--- /dev/null
+++ b/day01/part2
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+def fuel_required(mass)
+ fuel_queue = [mass]
+
+ loop do
+ new_fuel = (fuel_queue.last / 3) - 2
+ return (fuel_queue.sum - mass) if new_fuel <= 0
+ fuel_queue << new_fuel
+ end
+end
+
+input = $stdin.readlines.map(&:strip).map(&:to_i)
+
+puts input.map{ |x| fuel_required(x) }.sum