aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/aocclj/src
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-02-05 19:09:06 +0100
committerOscar Najera <hi@oscarnajera.com>2023-02-05 19:09:06 +0100
commit4daf41bd69e01f137be90881ec419b3c045a2ec5 (patch)
treecc69c4dcc980c304e8e12ce11485533c0011f1f5 /AoC2022/aocclj/src
parent84ec86b63ac38423ce021448e379b87094f7d4ac (diff)
downloadscratch-4daf41bd69e01f137be90881ec419b3c045a2ec5.tar.gz
scratch-4daf41bd69e01f137be90881ec419b3c045a2ec5.tar.bz2
scratch-4daf41bd69e01f137be90881ec419b3c045a2ec5.zip
Try clojure for day 1 and test transducers
Diffstat (limited to 'AoC2022/aocclj/src')
-rw-r--r--AoC2022/aocclj/src/aocclj/core.clj8
-rw-r--r--AoC2022/aocclj/src/aocclj/day01.clj18
2 files changed, 26 insertions, 0 deletions
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 +)))