-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday08.clj
36 lines (30 loc) · 1.14 KB
/
day08.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns day08
(:require [input :refer [f->lines lines]]))
(defn parse [it]
(->> it
(reduce
(fn [i s]
(let [d (mapv parse-long (re-seq #"\d+" s))]
(conj i [(re-find #"row|col|rec" s) d]))) [])))
(defn solve [it X Y]
(let [g (vec (for [_ (range Y)] (vec (repeat X 0))))
tr #(apply mapv vector %)
shift #(->> %1 cycle (drop (- %3 %2)) (take %3) vec)
put (fn [g [x y]] (reduce #(assoc-in %1 %2 1) g (for [x* (range x) y* (range y)] [y* x*])))]
(reduce
(fn [g [i [idx by :as rect]]]
(case i "row" (update g idx shift by X), "col" (tr (update (tr g) idx shift by Y)), (put g rect)))
g it)))
(defn display [g] (let [g (map #(map {1 "█" 0 " "} %) g)] (doseq [r g] (prn (apply str r)))) g)
(defn -main [day]
(let [input (->> day f->lines parse), g (display (solve input 50 6))]
{:part1 (->> g flatten (apply +)) :part2 "ZFHFSFOGPO"}))
(comment
(let [test-input (lines "rect 3x2
rotate column x=1 by 1
rotate row y=0 by 4
rotate column x=1 by 1")
input (parse test-input)]
(= [[0 1 0 0 1 0 1] [1 0 1 0 0 0 0] [0 1 0 0 0 0 0]]
(display (solve input 7 3))))
)