master
1(require '[clojure.string :as str])
2
3(def e1i (slurp "../input/01-e1i.txt"))
4(def p1i (slurp "../input/01-p1i.txt"))
5(def e2i (slurp "../input/01-e2i.txt"))
6(def p2i (slurp "../input/01-p2i.txt"))
7
8
9(defn p1s
10 ([input]
11 (->> input
12 str/split-lines ; newline split
13 (map parse-long) ; each item an int (empty line = nil)
14 (partition-by nil?) ; into sub lists where nil is deliminator
15 (filter #(not-any? nil? %)) ; get rid of the nil sub-lists
16 (map #(apply + %)) ; sum
17 (apply max)))) ; max
18
19(defn p2s
20 ([input]
21 (->> input
22 str/split-lines ; newline split
23 (map parse-long) ; each item an int (empty line = nil)
24 (partition-by nil?) ; into sub lists where nil is deliminator
25 (filter #(not-any? nil? %)) ; get rid of the nil sub-lists
26 (map #(apply + %)) ; sum
27 (sort) ; sort assending
28 (take-last 3) ; top 3
29 (apply +)))) ; sum top 3
30
31(println "e1s" (p1s e1i))
32(println "p1s" (p1s p1i))
33(println "e2s" (p2s e2i))
34(println "p2s" (p2s p2i))