advent-of-code/2019/1.moon

14 lines
359 B
Plaintext
Raw Permalink Normal View History

2019-12-01 14:49:58 -06:00
-- https://adventofcode.com/2019/day/1
require "common"
2019-12-01 14:55:48 -06:00
2019-12-01 14:52:25 -06:00
input = -> input_for_day(1)\gmatch "%d+"
2019-12-01 14:49:58 -06:00
mass_to_fuel = => -2 + math.floor @ / 3
2019-12-01 14:52:25 -06:00
print "Part 1:", reduce input!, 0, (n) => @ + mass_to_fuel n
2019-12-01 14:49:58 -06:00
fuel_for_fuel = =>
f = mass_to_fuel @
if f < 1 then return 0 else return f + fuel_for_fuel f
2019-12-01 14:52:25 -06:00
print "Part 2:", reduce input!, 0, (n) => @ + fuel_for_fuel n