Last active
December 3, 2019 16:50
-
-
Save invasionofsmallcubes/2d73ed205ba61f4e07a63a0e708480c7 to your computer and use it in GitHub Desktop.
Advent Of Code - 2019 - DAY 1 - EX 2 #adventOfCode2019
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
;; https://adventofcode.com/2019/day/1 | |
(def massDatabase []) ;; get the input in the link | |
(defn roundDown | |
[num] (int (Math/floor num))) | |
(defn fuelRequired | |
[mass] | |
(- (roundDown (/ mass 3)) 2) | |
) | |
(defn fuelRequiredTR [mass] | |
(let [initialMass (fuelRequired mass)] | |
(loop [cnt initialMass | |
acc 0] | |
(if (<= cnt 0) acc | |
(recur (fuelRequired cnt) (+ cnt acc)))))) | |
(reduce + (map fuelRequiredTR massDatabase)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment