-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.clj
29 lines (24 loc) · 985 Bytes
/
2.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
(:require 'leiningen.exec)
(require '[clojure.string :as str])
(require '[clojure.java.io :as io])
(def gift-paper (atom ()))
(def ribbon (atom ()))
(defn gift-wrap-area [dimensions]
(let [l (Integer/parseInt (first dimensions))
w (Integer/parseInt (nth dimensions 1))
h (Integer/parseInt (last dimensions))]
(swap! gift-paper conj (+ (* 2 l w) (* 2 w h) (* 2 h l) (apply * (take 2 (sort [l w h])))))))
(defn ribbon-wrap-area [dimensions]
(let [l (Integer/parseInt (first dimensions))
w (Integer/parseInt (nth dimensions 1))
h (Integer/parseInt (last dimensions))]
(swap! ribbon conj (+ (apply + (map #(* % 2) (take 2 (sort [l w h]))))
(* l w h)))))
(defn part1 []
(with-open [rdr (io/reader "2.txt")]
(doseq [line (line-seq rdr)]
(gift-wrap-area (str/split (str line) #"x"))
(ribbon-wrap-area (str/split (str line) #"x")))))
(part1)
(println (apply + @gift-paper))
(println (apply + @ribbon))