You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.1 KiB
Clojure

3 years ago
(require '[clojure.string :as str])
(defn read-coords []
(let [line (read-line)]
(when (not (empty? line))
(mapv
#(Integer/parseInt %)
(str/split
line
#"[^\d]+"
)
)
)
)
)
(defn read-all-coords []
(loop [cds [] c (read-coords)]
(if (empty? c)
cds
(recur
(conj cds c)
(read-coords)
3 years ago
)
)
)
)
(defn mark-coord [cmap x y]
(update cmap y #(update % x inc))
)
3 years ago
(defn mark-coords [cmap x1 y1 x2 y2]
(cond
(= y1 y2)
(reduce
#(mark-coord %1 %2 y1)
cmap
(range (min x1 x2) (inc (max x1 x2)))
3 years ago
)
(= x1 x2)
(reduce
#(mark-coord %1 x1 %2)
cmap
(range (min y1 y2) (inc (max y1 y2)))
3 years ago
)
:else
cmap
)
)
(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)
3 years ago
)
)
(->> finished-map
(flatten)
(map dec)
(filter pos?)
(count)
(println)
)