From dcb3af317c49918abeb4ff4a1be58a6fbcae6d16 Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Sun, 1 Dec 2019 23:19:31 -0500 Subject: [PATCH 1/1] Add day 1 and solutions --- day01/fuel.clj | 24 ++++++++++++ day01/input | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 day01/fuel.clj create mode 100644 day01/input diff --git a/day01/fuel.clj b/day01/fuel.clj new file mode 100644 index 0000000..916f45b --- /dev/null +++ b/day01/fuel.clj @@ -0,0 +1,24 @@ +(ns aoc.core + [:require [clojure.string :as str]]) + +(def get-list-from-file + #(str/split-lines (slurp %))) + +(def parse-int + #(Integer/parseInt %)) + +(defn get-fuel-req [mass] + (reduce + (take-while #(> % 0) (drop 1 (iterate #(- (quot % 3) 2) mass))))) + +(defn total-fuel-requirement-naive [input] + (reduce + (map #(- (quot % 3) 2) input))) + +(defn total-fuel-requirement [input] + (reduce + (map get-fuel-req input))) + +(defn -main [] + (let [input (map parse-int (get-list-from-file "input"))] + (println (total-fuel-requirement-naive input)) + (println (total-fuel-requirement input)))) + +(-main) diff --git a/day01/input b/day01/input new file mode 100644 index 0000000..eea337c --- /dev/null +++ b/day01/input @@ -0,0 +1,100 @@ +95065 +129298 +145573 +95743 +59139 +78323 +124445 +69015 +81990 +83254 +139274 +92101 +74245 +104038 +61955 +80642 +110376 +89992 +84392 +117830 +140144 +80076 +111285 +107135 +98741 +103753 +141922 +130503 +60409 +73891 +84781 +118319 +93610 +143228 +99616 +65353 +102388 +123813 +88335 +95459 +133635 +108771 +101999 +73850 +106490 +53396 +110330 +140258 +73958 +60273 +101401 +128995 +61495 +114674 +71955 +107049 +79374 +52359 +107925 +91789 +69174 +133966 +85063 +62856 +96965 +97100 +81638 +104488 +131368 +59015 +149357 +65193 +61489 +126089 +141224 +100596 +93144 +109421 +121988 +135890 +70141 +53531 +59900 +98981 +66796 +113700 +109535 +100721 +87240 +99883 +81637 +80064 +143154 +75778 +64835 +59235 +103907 +121637 +118525 +125730 -- 2.38.5