Skip to content

Instantly share code, notes, and snippets.

@bryanwoods
Last active December 2, 2019 03:44
Show Gist options
  • Save bryanwoods/45a76fc3fe814c8c5205745bc1642158 to your computer and use it in GitHub Desktop.
Save bryanwoods/45a76fc3fe814c8c5205745bc1642158 to your computer and use it in GitHub Desktop.
Advent of Code 2019
(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