clojure

Advent of Code Day 1

Here is my solution to Advent of Code, Day 1: (def input (slurp "day1.txt")) (def elf-totals (->> (clojure.string/split input #"\n\n") (map (fn [elf-row] (clojure.string/split elf-row #"\n"))) (map (fn [elf-row] (map (fn [calorie-value] (Integer/parseInt calorie-value)) elf-row))) (into []) (map (fn [elf-row] (reduce + elf-row))) (sort (fn [x y] (> x y))) (take 3))) (def answer (list (reduce + elf-totals) (first elf-totals))) It is an overuse of maps and reduces, but let’s go through it step-by-step.