tobiasbehr / advent-of-code-19

https://adventofcode.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advent of code 2019

Let’s bring back Santa from the edge of the solar system

Day 1

Part 1

; First we need to calculate the fuel per mass:
(defn fuel-for-mass [mass]
  (- (Math/floor (/ mass 3)) 2))

; Then we need to sum up the fuel for all the modules
(defn day1-1 [input]
  (->> input
       (map fuel-for-mass)
       (reduce +)))

Part 2

; Recursively calculate the additional fuel requirement the fuel
(defn fuel-for-module [mass]
  (let [fuel (fuel-for-mass mass)]
    (if (> fuel 0)
      (+ fuel (fuel-for-module fuel))
      0)))

(defn day1-2 [input]
  (->> input
       (map fuel-for-module)
       (reduce +)))

About

https://adventofcode.com/

License:Eclipse Public License 1.0


Languages

Language:Clojure 100.0%