-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_02.clj
43 lines (36 loc) · 883 Bytes
/
day_02.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(ns advent-of-code-2015.day-02
(:gen-class))
(defn- parse-gift
[gift-str]
(->> (clojure.string/split gift-str #"x")
(map #(Integer. %))))
(defn- gift-area
[[w l h]]
(+ (* 2 w l)
(* 2 w h)
(* 2 l h)))
(defn- slack
[dims]
(reduce * (take 2 (sort dims))))
(defn- ribbon-length
[dims]
(+ (* 2 (reduce + (take 2 (sort dims))))
(reduce * dims)))
(defn- part-1
[input]
(->> (clojure.string/split-lines input)
(map parse-gift)
(map #(+ (gift-area %) (slack %)))
(reduce +)))
(defn- part-2
[input]
(->> (clojure.string/split-lines input)
(map parse-gift)
(map ribbon-length)
(reduce +)))
(defn day-02
[input-file]
(let [input (slurp input-file)]
(println "Day 2")
(println "Sq. feet of wrapping paper: " (part-1 input))
(println "Total feet of ribbon needed: " (part-2 input))))