aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/aocclj
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-02-11 20:15:04 +0100
committerOscar Najera <hi@oscarnajera.com>2023-02-11 20:15:04 +0100
commitbcea1e3977f629ed955c9ab886f484bad938c81a (patch)
tree53f9cea132508feedb89095942b15c73291121e8 /AoC2022/aocclj
parentefcc7c32228d87f9f41cd5963491e9d11ee30dfb (diff)
downloadscratch-bcea1e3977f629ed955c9ab886f484bad938c81a.tar.gz
scratch-bcea1e3977f629ed955c9ab886f484bad938c81a.tar.bz2
scratch-bcea1e3977f629ed955c9ab886f484bad938c81a.zip
day06
Diffstat (limited to 'AoC2022/aocclj')
-rw-r--r--AoC2022/aocclj/src/aocclj/day06.clj9
-rw-r--r--AoC2022/aocclj/test/aocclj/core_test.clj7
2 files changed, 16 insertions, 0 deletions
diff --git a/AoC2022/aocclj/src/aocclj/day06.clj b/AoC2022/aocclj/src/aocclj/day06.clj
new file mode 100644
index 0000000..c333cad
--- /dev/null
+++ b/AoC2022/aocclj/src/aocclj/day06.clj
@@ -0,0 +1,9 @@
+(ns aocclj.day06)
+
+(defn solver [window input]
+ (first
+ (keep-indexed
+ (fn [idx item]
+ (when ((comp #(= window %) count set) item) (+ window idx)))
+ (partition-all window 1 input))))
+
diff --git a/AoC2022/aocclj/test/aocclj/core_test.clj b/AoC2022/aocclj/test/aocclj/core_test.clj
index 38e4f72..f372d29 100644
--- a/AoC2022/aocclj/test/aocclj/core_test.clj
+++ b/AoC2022/aocclj/test/aocclj/core_test.clj
@@ -5,6 +5,7 @@
[aocclj.day03 :as day03]
[aocclj.day04 :as day04]
[aocclj.day05 :as day05]
+ [aocclj.day06 :as day06]
[aocclj.core :refer :all]
[clojure.string :as str]))
@@ -37,3 +38,9 @@
(are [expected single] (= expected (day05/solver single input))
"TPGVQPFDH" true
"DMRDFRHHH" false)))
+
+(deftest day06
+ (let [input (slurp "../06/input")]
+ (are [expected window] (= expected (day06/solver window input))
+ 1655 4
+ 2665 14)))