Created
December 1, 2019 19:03
-
-
Save activexray/5fdba50c4a8efe72da3d4625fac99391 to your computer and use it in GitHub Desktop.
AoC 2019 - Day 1
This file contains hidden or 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
| (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