Skip to content

Instantly share code, notes, and snippets.

@activexray
Created December 1, 2019 19:03
Show Gist options
  • Select an option

  • Save activexray/5fdba50c4a8efe72da3d4625fac99391 to your computer and use it in GitHub Desktop.

Select an option

Save activexray/5fdba50c4a8efe72da3d4625fac99391 to your computer and use it in GitHub Desktop.
AoC 2019 - Day 1
(ns aoc2019.core)
;; Part 1
(defn fuel [mass]
(- (int (Math/floor (/ mass 3))) 2))
;; Read File
(def input
(->> (slurp "1.txt")
clojure.string/split-lines
(map #(Integer/parseInt %))))
;; Apply fuel calculations - Part 1
(reduce + (map #(fuel %) input))
;; Part 2
(defn fuel_rec [mass]
(let [requirement (fuel mass)]
(if (<= requirement 0) 0 (+ requirement (fuel_rec requirement)))))
;; Apply fuel calculations - Part 2
(reduce + (map #(fuel_rec %) input))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment