2022 Day 1 Clojure

This commit is contained in:
Luke Hubmayer-Werner 2022-12-01 20:49:20 +10:30
parent 6c152a6aae
commit bcef26b1e1
1 changed files with 7 additions and 0 deletions

7
2022/day1.clj Normal file
View File

@ -0,0 +1,7 @@
(require '[clojure.string :as str])
(def filename "day1-input")
(def elves-rations (map #(map read-string %) (map str/split-lines (str/split (slurp filename) #"\n\n"))))
(def elves-totals (map #(reduce + %) elves-rations))
(def sorted-totals (sort elves-totals))
(println (last sorted-totals)) ; Part 1
(println (reduce + (take-last 3 sorted-totals))) ; Part 2