aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/aocclj/src
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-02-06 00:01:53 +0100
committerOscar Najera <hi@oscarnajera.com>2023-02-06 00:01:53 +0100
commit99bcf55e2df61cef89cb88213e6feddd88294d47 (patch)
tree4aba0a910a4b0f1f8819346f7fc9b9da06dc5999 /AoC2022/aocclj/src
parent57e563bf8f4fae7364118619318b338f16792473 (diff)
downloadscratch-99bcf55e2df61cef89cb88213e6feddd88294d47.tar.gz
scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.tar.bz2
scratch-99bcf55e2df61cef89cb88213e6feddd88294d47.zip
day 3 review
Diffstat (limited to 'AoC2022/aocclj/src')
-rw-r--r--AoC2022/aocclj/src/aocclj/day03.clj29
1 files changed, 29 insertions, 0 deletions
diff --git a/AoC2022/aocclj/src/aocclj/day03.clj b/AoC2022/aocclj/src/aocclj/day03.clj
new file mode 100644
index 0000000..dd3fb8d
--- /dev/null
+++ b/AoC2022/aocclj/src/aocclj/day03.clj
@@ -0,0 +1,29 @@
+(ns aocclj.day03
+ (:require [clojure.string :as str]
+ [clojure.set :as set]))
+
+(defn priority [c]
+ (->>
+ (if (Character/isLowerCase c)
+ (dec (int \a))
+ (- (int \A) 27))
+ (- (int c))))
+
+(defn seq-halver [s]
+ (split-at (/ (count s) 2) s))
+
+(defn block-priority [block]
+ ((comp priority first (partial apply set/intersection) (partial map set)) block))
+
+(defn solver [group-transducer input]
+ (transduce
+ (comp
+ group-transducer
+ (map block-priority))
+ + input))
+
+(defn part1 [input]
+ (solver (map seq-halver) input))
+
+(defn part2 [input]
+ (solver (partition-all 3) input))