diff options
author | Nat Lasseter <user@4574.co.uk> | 2019-12-01 11:15:09 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2019-12-01 11:15:09 +0000 |
commit | b1692f98b614e731cd42fc770dff77e2f3c136ff (patch) | |
tree | 5066dfa5a78db90279ceaec6b5a87049f06973c8 /day01/part2 | |
parent | 04dbc1e0b9c56198168190d45fa096c605cafd7f (diff) |
Day 1 complete
Diffstat (limited to 'day01/part2')
-rwxr-xr-x | day01/part2 | 15 |
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 |