diff --git a/2024/src/core.clj b/2024/src/core.clj index 160e5f8..a2a709a 100644 --- a/2024/src/core.clj +++ b/2024/src/core.clj @@ -27,10 +27,15 @@ col (range (count (get list-of-lists row)))] [row col])) -(defn insert-vec [v idx el] - (into [] (concat (take idx v) - (list el) - (drop idx v)))) +(defn insert-at-idx [coll idx el] + (concat (take idx coll) + (list el) + (drop idx coll))) (defn bool->binary [condition] (if condition 1 0)) + +(defn mmap + "map map" + [f coll] + (map (partial map f) coll)) diff --git a/2024/src/day04.clj b/2024/src/day04.clj index f4db5d4..5edac19 100644 --- a/2024/src/day04.clj +++ b/2024/src/day04.clj @@ -20,7 +20,7 @@ [(- row offset) (+ col offset)] [(+ row offset) (- col offset)] [(+ row offset) (+ col offset)]]) - (map (partial map get-char)) + (c/mmap get-char) (apply map vector) (filter #(= % (seq "XMAS"))) count))) @@ -32,7 +32,7 @@ (filter (fn [[row col]] (->> [[[(dec row) (dec col)] [(inc row) (inc col)]] [[(inc row) (dec col)] [(dec row) (inc col)]]] - (map (partial map get-char)) + (c/mmap get-char) (map set) (apply = #{\M \S})))) count) diff --git a/2024/src/day05.clj b/2024/src/day05.clj index f2cf2cc..d6d81b8 100644 --- a/2024/src/day05.clj +++ b/2024/src/day05.clj @@ -31,7 +31,7 @@ (map #(.indexOf acc %)) (filter #(not= % -1)) not-empty)] - (c/insert-vec acc (apply min idxs) el) + (into [] (c/insert-at-idx acc (apply min idxs) el)) (conj acc el))) [] coll))