]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
day9: clean up
authorClyne Sullivan <clyne@bitgloo.com>
Fri, 10 Dec 2021 13:15:02 +0000 (08:15 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Fri, 10 Dec 2021 13:15:02 +0000 (08:15 -0500)
day10/part1.clj
day10/part2.clj

index 2bef6964fb520e558e8345482f5caee21aef9f2f..1424fd8a230669d0eeb3c74a32c4895d1c60c60d 100644 (file)
@@ -2,7 +2,7 @@
 (def to-score {\) 3 \] 57 \} 1197 \> 25137})
 
 (defn check-line [input]
-  (loop [open [] in input]
+  (loop [in input open '()]
     (cond
       (empty? in)
       nil
       (first in)
       :else
       (recur
-        (if (contains? #{\{ \( \[ \<} (first in))
-          (concat [(first in)] open)
-          (rest open))
         (rest in)
-        ))))
+        (if (contains? #{\{ \( \[ \<} (first in))
+          (conj open (first in))
+          (rest open)
+          )))))
 
 (->> (slurp "./in")
      (clojure.string/split-lines)
-     (mapv vec)
-     (mapv check-line)
+     (map (comp to-score check-line vec))
      (filter some?)
-     (mapv to-score)
      (apply +)
      (println))
 
index 6cd27afba9d5c44806f89b6f9b5b0a8b4b641d04..49c913604ba6038ca339fe29fe3135aefecb6973 100644 (file)
@@ -2,7 +2,7 @@
 (def to-score {\) 1 \] 2 \} 3 \> 4})
 
 (defn check-line [input]
-  (loop [open [] in input]
+  (loop [in input open '()]
     (cond
       (empty? in)
       (map to-closing open)
       nil
       :else
       (recur
-        (if (contains? #{\{ \( \[ \<} (first in))
-          (concat [(first in)] open)
-          (rest open))
         (rest in)
-        ))))
+        (if (contains? #{\{ \( \[ \<} (first in))
+          (conj open (first in))
+          (rest open)
+          )))))
 
 (->> (slurp "./in")
      (clojure.string/split-lines)
-     (mapv vec)
-     (mapv check-line)
+     (map (comp check-line vec))
      (filter some?)
-     (mapv (partial reduce #(+ (* 5 %1) (to-score %2)) 0))
+     (map (partial reduce #(+ (* 5 %1) (to-score %2)) 0))
      (sort)
-     (#(get (vec %) (quot (count %) 2)))
-     (println)
-     )
+     (#(nth % (quot (count %) 2)))
+     (println))