From: Clyne Sullivan Date: Mon, 6 Dec 2021 00:22:38 +0000 (-0500) Subject: day5: part2 build map rather than 2d vec X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=5d1bf4161a21ac1819202174eeab08c9ed742645;p=clyne%2Fadvent-of-code.git day5: part2 build map rather than 2d vec --- diff --git a/day5/part2.clj b/day5/part2.clj index c374716..d324618 100644 --- a/day5/part2.clj +++ b/day5/part2.clj @@ -27,7 +27,11 @@ ) (defn mark-coord [cmap x y] - (update cmap y #(update % x inc)) + (update + cmap + [x y] + #(if (nil? %) 0 (inc %)) + ) ) (defn mark-coords [cmap x1 y1 x2 y2] @@ -62,27 +66,18 @@ ) ) -(defn empty-map [] - (vec - (repeat 1000 - (vec (repeat 1000 0)) - ) - ) - ) - (def finished-map (reduce #(apply (partial mark-coords %1) %2) - (empty-map) + {} (read-all-coords) ) ) (->> finished-map - (flatten) - (map dec) - (filter pos?) - (count) - (println) - ) + (vals) + (filter pos?) + (count) + (println) + )