Skip to content

Instantly share code, notes, and snippets.

@invasionofsmallcubes
Last active December 3, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invasionofsmallcubes/2d73ed205ba61f4e07a63a0e708480c7 to your computer and use it in GitHub Desktop.
Save invasionofsmallcubes/2d73ed205ba61f4e07a63a0e708480c7 to your computer and use it in GitHub Desktop.
Advent Of Code - 2019 - DAY 1 - EX 2 #adventOfCode2019
;; 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