mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:23:17 -09:00
golf
This commit is contained in:
parent
22ac0db085
commit
b25e12b3a2
@ -17,3 +17,18 @@
|
|||||||
(if (.find m)
|
(if (.find m)
|
||||||
(recur m (assoc res (.start m) (.group m)))
|
(recur m (assoc res (.start m) (.group m)))
|
||||||
res)))
|
res)))
|
||||||
|
|
||||||
|
(defn dbg [x]
|
||||||
|
(println x)
|
||||||
|
x)
|
||||||
|
|
||||||
|
(defn get-coords
|
||||||
|
"returns a lazy seq representing list of list x, y tuples"
|
||||||
|
[list-of-lists]
|
||||||
|
(->> list-of-lists count range
|
||||||
|
(map #(->> % (get list-of-lists) count range))
|
||||||
|
(map-indexed (fn [row cols]
|
||||||
|
(map #(list row %) cols)))))
|
||||||
|
|
||||||
|
(defn bool->binary [condition]
|
||||||
|
(if condition 1 0))
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
(ns day04
|
(ns day04
|
||||||
(:require [input-manager :refer [get-input]]))
|
(:require [input-manager :refer [get-input]]
|
||||||
|
[core :as c]
|
||||||
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(def input (get-input 4))
|
(def input (get-input 4))
|
||||||
|
|
||||||
@ -8,51 +10,38 @@
|
|||||||
|
|
||||||
;; part 1
|
;; part 1
|
||||||
(->> input
|
(->> input
|
||||||
(map (partial map-indexed vector))
|
c/get-coords
|
||||||
(map-indexed vector)
|
(map (partial reduce (fn [acc [row col]]
|
||||||
(reduce (fn [acc [row s]]
|
(+ acc
|
||||||
(reduce (fn [acc2 [col _c]]
|
(->> (for [offset (range 4)]
|
||||||
(+ acc2 (->> (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))
|
||||||
acc
|
(reduce +))
|
||||||
s))
|
|
||||||
0))
|
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(->> input
|
(->> input
|
||||||
(map reverse)
|
c/get-coords
|
||||||
(map (partial map-indexed vector))
|
(map (partial reduce (fn [acc [row col]]
|
||||||
(map-indexed vector)
|
(+ acc
|
||||||
(reduce (fn [acc [row s]]
|
(if (= (get-char row col) \A)
|
||||||
(reduce (fn [acc2 [col _c]]
|
(->> [[[(dec row) (dec col)] [(inc row) (inc col)]]
|
||||||
(+ acc2 (if (= (get-char row col) \A)
|
[[(inc row) (dec col)] [(dec row) (inc col)]]]
|
||||||
(let [corners [[(dec row) (dec col)]
|
(map (partial map #(apply get-char %)))
|
||||||
[(inc row) (dec col)]
|
(map set)
|
||||||
[(dec row) (inc col)]
|
(apply = #{\M \S})
|
||||||
[(inc row) (inc col)]]
|
c/bool->binary)
|
||||||
chars (mapv #(apply get-char %) corners)]
|
0)))
|
||||||
(if (and (= 2
|
0))
|
||||||
(count (filter #(= % \S) chars))
|
(reduce +))
|
||||||
(count (filter #(= % \M) chars)))
|
|
||||||
(not= (get chars 0)
|
|
||||||
(get chars 3)))
|
|
||||||
1
|
|
||||||
0))
|
|
||||||
0)))
|
|
||||||
acc
|
|
||||||
s))
|
|
||||||
0)
|
|
||||||
;
|
|
||||||
)
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user