~ihabunek/aoc2021

c6e7f431ace8f43844c517604ce4ba43119ae324 — Ivan Habunek 2 years ago ecec0f1 day20
wip
1 files changed, 19 insertions(+), 10 deletions(-)

M src/aoc2021/day20.clj
M src/aoc2021/day20.clj => src/aoc2021/day20.clj +19 -10
@@ 11,8 11,8 @@
(def light \#)
(def dark \.)

; (def input-file (-> "day20.in" io/resource io/file))
(def input-file (-> "day20.example.in" io/resource io/file))
(def input-file (-> "day20.in" io/resource io/file))
; (def input-file (-> "day20.example.in" io/resource io/file))

(defn parse-image[image background]
  (into #{}


@@ 93,25 93,34 @@
      (for [pos (expand-to-neighbours inverted)
            :let [next (next-val algo image pos)]
            :when (not= next background)]
        [x y]))))
        pos))))

(defn step-background [algo [background inverted]]
  (if (= background light)
    (first algo)
    (last algo)))
    (last algo)
    (first algo)))

(defn step [algo image]
  (let [next-background (step-background algo image)
        next-inverted (step-inverted algo image next-background)]
    [next-background next-inverted]))

(defn count-light [[background inverted]]
  (assert (= dark background))
  (count inverted))

(defn main []
  (let [background dark
        [algo inverted] (get-input background)
        image [background inverted]]
    (print-image image)))
    ; (pprint (step algo image))))
    ; (println (neighbours [5 10]))
    ; (println (count (step algo (step algo image))))))
        image [background inverted]
        step' (partial step algo)
        image' (step' image)
        image'' (step' image')]
    (print-image image)
    (print-image image')
    (print-image image'')
    (println (count-light image''))))

; 5426 - too high
; 5031 - too low
; 5376 - too high