From c103fe2f82d847aeea6646abbf47298699846b45 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Sun, 1 Dec 2019 14:49:58 -0600 Subject: [PATCH] Day 1 complete --- 2019/1.moon | 21 ++++++++++ 2019/common.moon | 16 ++++++++ 2019/input/1.txt | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 2019/1.moon create mode 100644 2019/common.moon create mode 100644 2019/input/1.txt diff --git a/2019/1.moon b/2019/1.moon new file mode 100644 index 0000000..3813185 --- /dev/null +++ b/2019/1.moon @@ -0,0 +1,21 @@ +-- https://adventofcode.com/2019/day/1 + +require "common" + +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 + +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) diff --git a/2019/common.moon b/2019/common.moon new file mode 100644 index 0000000..53fee49 --- /dev/null +++ b/2019/common.moon @@ -0,0 +1,16 @@ +export input_for_day, reduce + +read_whole_file = => + f = assert io.open @, "rb" + content = f\read "*all" + f\close() + content + +input_for_day = => + read_whole_file "input/#{@}.txt" + +reduce = (iterable, initial, f) -> + acc = initial + for e in iterable + acc = f acc, e + acc diff --git a/2019/input/1.txt b/2019/input/1.txt new file mode 100644 index 0000000..4cc0a1e --- /dev/null +++ b/2019/input/1.txt @@ -0,0 +1,100 @@ +130762 +108691 +131618 +138163 +59967 +130453 +117515 +115776 +134083 +86966 +128075 +55569 +112843 +97878 +92330 +70917 +143903 +81171 +148506 +141379 +131161 +88719 +69654 +82141 +55265 +75623 +97408 +105269 +147378 +126054 +133962 +60304 +130503 +138350 +93164 +69661 +69271 +100054 +138295 +142865 +64142 +123466 +80101 +149696 +102510 +129988 +87742 +106785 +133039 +59192 +86544 +124950 +64242 +80128 +109287 +129634 +140335 +118220 +106819 +97296 +111003 +103222 +54192 +103548 +63861 +140571 +50476 +100570 +114065 +110279 +64720 +91941 +62312 +80834 +132969 +51973 +115887 +68662 +138266 +107234 +75795 +81409 +78610 +112587 +92384 +111804 +138861 +79393 +81285 +131307 +68815 +54976 +127529 +103359 +138537 +79663 +128097 +56085 +96504 +119501