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
d5e9f85dc8
commit
1bd800472d
@ -22,14 +22,15 @@
|
|||||||
(println x)
|
(println x)
|
||||||
x)
|
x)
|
||||||
|
|
||||||
(defn get-coords
|
(defn get-coords [list-of-lists]
|
||||||
"returns a lazy seq representing list of list x, y tuples"
|
(for [row (range (count list-of-lists))
|
||||||
[list-of-lists]
|
col (range (count (get list-of-lists row)))]
|
||||||
(->> list-of-lists count range
|
[row col]))
|
||||||
(map #(->> % (get list-of-lists) count range))
|
|
||||||
(map-indexed (fn [row cols]
|
(defn insert-vec [v idx el]
|
||||||
(map #(list row %) cols)))
|
(into [] (concat (take idx v)
|
||||||
(mapcat identity)))
|
(list el)
|
||||||
|
(drop idx v))))
|
||||||
|
|
||||||
(defn bool->binary [condition]
|
(defn bool->binary [condition]
|
||||||
(if condition 1 0))
|
(if condition 1 0))
|
||||||
|
@ -18,29 +18,22 @@
|
|||||||
(get v (int (/ (count v) 2))))
|
(get v (int (/ (count v) 2))))
|
||||||
|
|
||||||
(defn ordered? [coll]
|
(defn ordered? [coll]
|
||||||
(reduce (fn [acc p]
|
(reduce (fn [acc el]
|
||||||
(if p
|
(if
|
||||||
(if (some acc (orderings p))
|
(some acc (orderings el)) (reduced false)
|
||||||
(reduced false)
|
(conj acc el)))
|
||||||
(conj acc p))
|
|
||||||
(reduced true)))
|
|
||||||
#{}
|
#{}
|
||||||
coll))
|
coll))
|
||||||
|
|
||||||
(defn order [coll]
|
(defn order [coll]
|
||||||
(reduce (fn [acc p]
|
(reduce (fn [acc p]
|
||||||
(if p
|
(if-let [idxs (->> (orderings p)
|
||||||
(if-let [idxs (->> (orderings p)
|
(filter #(contains? (set acc) %))
|
||||||
(filter #(contains? (set acc) %))
|
(map #(.indexOf acc %))
|
||||||
(map #(.indexOf acc %))
|
(filter #(not= % -1))
|
||||||
(filter #(not= % -1))
|
not-empty)]
|
||||||
not-empty)]
|
(c/insert-vec acc (apply min idxs) p)
|
||||||
(let [m (apply min idxs)]
|
(conj acc p)))
|
||||||
(into [] (concat (take m acc)
|
|
||||||
(list p)
|
|
||||||
(drop m acc))))
|
|
||||||
(conj acc p))
|
|
||||||
(reduced acc)))
|
|
||||||
[]
|
[]
|
||||||
coll))
|
coll))
|
||||||
|
|
||||||
@ -53,8 +46,6 @@
|
|||||||
;; part 2
|
;; part 2
|
||||||
(->> pages
|
(->> pages
|
||||||
(filter #(not (ordered? %)))
|
(filter #(not (ordered? %)))
|
||||||
(map order)
|
(map (comp get-middle order))
|
||||||
(map get-middle)
|
|
||||||
(reduce +))
|
(reduce +))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user