day5: part2 build map rather than 2d vec

master
Clyne 3 years ago
parent 68c02872a8
commit 5d1bf4161a

@ -27,7 +27,11 @@
) )
(defn mark-coord [cmap x y] (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 mark-coords [cmap x1 y1 x2 y2]
@ -62,25 +66,16 @@
) )
) )
(defn empty-map []
(vec
(repeat 1000
(vec (repeat 1000 0))
)
)
)
(def finished-map (def finished-map
(reduce (reduce
#(apply (partial mark-coords %1) %2) #(apply (partial mark-coords %1) %2)
(empty-map) {}
(read-all-coords) (read-all-coords)
) )
) )
(->> finished-map (->> finished-map
(flatten) (vals)
(map dec)
(filter pos?) (filter pos?)
(count) (count)
(println) (println)

Loading…
Cancel
Save