-
Notifications
You must be signed in to change notification settings - Fork 0
/
day01.clj
39 lines (33 loc) · 854 Bytes
/
day01.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
(ns aoc.2022.day01
(:require [aoc.core :refer [read-input map-all reduce-all]]
[medley.core :as m]
[clojure.string :as str]))
(defn part-1 [fname]
(let [in1 (->
(read-input fname)
(str/split #"\n\n"))]
(->> in1
(map str/split-lines)
(map-all #(Integer/parseInt %))
(reduce-all + 0)
(apply max))))
(part-1 "2022/day01-sample.txt")
;; => 24000
(part-1 "2022/day01.txt")
;; => 67622
(defn part-2 [fname]
(let [in1 (->
(read-input fname)
(str/split #"\n\n"))]
(->> in1
(map str/split-lines)
(map-all #(Integer/parseInt %))
(reduce-all + 0)
(sort)
(reverse)
(take 3)
(apply +))))
(part-2 "2022/day01-sample.txt")
;; => 45000
(part-2 "2022/day01.txt")
;; => 201491