]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
day5: part2 build map rather than 2d vec
authorClyne Sullivan <clyne@bitgloo.com>
Mon, 6 Dec 2021 00:22:38 +0000 (19:22 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Mon, 6 Dec 2021 00:22:38 +0000 (19:22 -0500)
day5/part2.clj

index c374716f0d6da065b46c8458b05b4170a3fc0702..d3246184999efb89f1339b13e367d5cde9b56b11 100644 (file)
   )
 
 (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]
     )
   )
 
-(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)
+     )