This commit is contained in:
Daniel Flanagan 2019-12-01 14:52:25 -06:00
parent c103fe2f82
commit f50552707f

View file

@ -1,21 +1,12 @@
-- https://adventofcode.com/2019/day/1
require "common"
input = -> input_for_day(1)\gmatch "%d+"
input = input_for_day 1
-- part 1
nums = -> input\gmatch "%d+"
mass_to_fuel = => -2 + math.floor @ / 3
print "Part 1:", reduce nums!, 0, (n) => @ + mass_to_fuel n
-- part 2
print "Part 1:", reduce input!, 0, (n) => @ + mass_to_fuel n
fuel_for_fuel = =>
f = mass_to_fuel @
print "fff:", f
if f < 1 then return 0 else return f + fuel_for_fuel f
print "Part 2:", reduce nums!, 0, (n) => @ + fuel_for_fuel(n)
print "Part 2:", reduce input!, 0, (n) => @ + fuel_for_fuel n