Last active
December 2, 2019 03:44
-
-
Save bryanwoods/45a76fc3fe814c8c5205745bc1642158 to your computer and use it in GitHub Desktop.
Advent of Code 2019
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.string :as str]) | |
(def masses | |
(map #(Integer/parseInt %) | |
(str/split (slurp "input") #"\n"))) | |
(defn elf-fuel [mass] | |
(int (- (Math/floor (/ mass 3)) 2))) | |
(defn cumulative-elf-fuel [mass] | |
(if (pos? (elf-fuel mass)) | |
(+ (elf-fuel mass) (cumulative-elf-fuel (elf-fuel mass))) | |
0)) | |
(defn- applied-sum [f vals] | |
(reduce + (map f vals))) | |
(defn part-one [] | |
(applied-sum elf-fuel masses)) | |
(defn part-two [] | |
(applied-sum cumulative-elf-fuel masses)) | |
(defn solve [] | |
(println (part-one)) | |
(println (part-two))) | |
(solve) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment