mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 07:03:19 -09:00
golf
This commit is contained in:
parent
b25e12b3a2
commit
3c65d19b8d
@ -28,7 +28,8 @@
|
|||||||
(->> list-of-lists count range
|
(->> list-of-lists count range
|
||||||
(map #(->> % (get list-of-lists) count range))
|
(map #(->> % (get list-of-lists) count range))
|
||||||
(map-indexed (fn [row cols]
|
(map-indexed (fn [row cols]
|
||||||
(map #(list row %) cols)))))
|
(map #(list row %) cols)))
|
||||||
|
(mapcat identity)))
|
||||||
|
|
||||||
(defn bool->binary [condition]
|
(defn bool->binary [condition]
|
||||||
(if condition 1 0))
|
(if condition 1 0))
|
||||||
|
@ -11,37 +11,35 @@
|
|||||||
;; part 1
|
;; part 1
|
||||||
(->> input
|
(->> input
|
||||||
c/get-coords
|
c/get-coords
|
||||||
(map (partial reduce (fn [acc [row col]]
|
(reduce (fn [acc [row col]]
|
||||||
(+ acc
|
(+ acc
|
||||||
(->> (for [offset (range 4)]
|
(->> (for [offset (range 4)]
|
||||||
(map #(apply get-char %)
|
(map #(apply get-char %)
|
||||||
[[row (+ col offset)]
|
[[row (+ col offset)]
|
||||||
[row (- col offset)]
|
[row (- col offset)]
|
||||||
[(+ row offset) col]
|
[(+ row offset) col]
|
||||||
[(- row offset) col]
|
[(- row offset) col]
|
||||||
[(- row offset) (- col offset)]
|
[(- row offset) (- col offset)]
|
||||||
[(- row offset) (+ col offset)]
|
[(- row offset) (+ col offset)]
|
||||||
[(+ row offset) (- col offset)]
|
[(+ row offset) (- col offset)]
|
||||||
[(+ row offset) (+ col offset)]]))
|
[(+ row offset) (+ col offset)]]))
|
||||||
(apply map vector)
|
(apply map vector)
|
||||||
(filter #(= % (seq "XMAS")))
|
(filter #(= % (seq "XMAS")))
|
||||||
count)))
|
count)))
|
||||||
0))
|
0))
|
||||||
(reduce +))
|
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(->> input
|
(->> input
|
||||||
c/get-coords
|
c/get-coords
|
||||||
(map (partial reduce (fn [acc [row col]]
|
(reduce (fn [acc [row col]]
|
||||||
(+ acc
|
(+ acc
|
||||||
(if (= (get-char row col) \A)
|
(if (= (get-char row col) \A)
|
||||||
(->> [[[(dec row) (dec col)] [(inc row) (inc col)]]
|
(->> [[[(dec row) (dec col)] [(inc row) (inc col)]]
|
||||||
[[(inc row) (dec col)] [(dec row) (inc col)]]]
|
[[(inc row) (dec col)] [(dec row) (inc col)]]]
|
||||||
(map (partial map #(apply get-char %)))
|
(map (partial map #(apply get-char %)))
|
||||||
(map set)
|
(map set)
|
||||||
(apply = #{\M \S})
|
(apply = #{\M \S})
|
||||||
c/bool->binary)
|
c/bool->binary)
|
||||||
0)))
|
0)))
|
||||||
0))
|
0))
|
||||||
(reduce +))
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user