From 4daf41bd69e01f137be90881ec419b3c045a2ec5 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Sun, 5 Feb 2023 19:09:06 +0100 Subject: Try clojure for day 1 and test transducers --- AoC2022/aocclj/src/aocclj/core.clj | 8 ++++++++ AoC2022/aocclj/src/aocclj/day01.clj | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 AoC2022/aocclj/src/aocclj/core.clj create mode 100644 AoC2022/aocclj/src/aocclj/day01.clj (limited to 'AoC2022/aocclj/src') diff --git a/AoC2022/aocclj/src/aocclj/core.clj b/AoC2022/aocclj/src/aocclj/core.clj new file mode 100644 index 0000000..35a8acb --- /dev/null +++ b/AoC2022/aocclj/src/aocclj/core.clj @@ -0,0 +1,8 @@ +(ns aocclj.core + (:gen-class) + (:require [clojure.string :as str])) + +(defn -main + "I don't do a whole lot ... yet." + [& args] + (println "Hello, World!")) diff --git a/AoC2022/aocclj/src/aocclj/day01.clj b/AoC2022/aocclj/src/aocclj/day01.clj new file mode 100644 index 0000000..8fca2e6 --- /dev/null +++ b/AoC2022/aocclj/src/aocclj/day01.clj @@ -0,0 +1,18 @@ +(ns aocclj.day01 + (:require [clojure.string :as str])) + +(defn preprocess [input] + (transduce + (comp + (map parse-long) + (partition-by nil?) + (take-nth 2) + (map (partial reduce +))) + conj + input)) + +(defn part1 [input] + (apply max (preprocess input))) + +(defn part2 [input] + (->> input preprocess sort (take 3) (apply +))) -- cgit v1.2.3