67 lines
1.3 KiB
Clojure

(ns day10
(:require [mapped-area]
[helpers :refer [get-input]]))
(def test-map
"89010123
78121874
87430965
96549874
45678903
32019012
01329801
10456732")
;(def test-map
;"0123
;1234
;8765
;9876")
(def input
(->
test-map
mapped-area/read-mapped-area
mapped-area/parse-elements))
(defn trailheads [a]
(reduce
(fn [coll [coord value]]
(if (= value 0)
(conj coll coord)
coll))
[]
(mapped-area/mapped-area-indexed-seq a)))
(defn step [a [x y]]
(let [c (get-in a [x y])
even-gradual-uphill?
(fn [[x' y']]
(let [c' (get-in a [x' y'])]
(= 1 (- c' c))))]
(->>
[[(inc x) y] [(dec x) y]
[x (inc y)] [x (dec y)]]
(filter (partial mapped-area/mapped? a))
(filter even-gradual-uphill?))))
(defn walk [a trailhead]
(loop [positions [trailhead]]
(println positions)
(if (== 9 (get-in a (first positions)))
(count positions)
(recur (mapcat (partial step a) (set positions))))))
(loop [i 0 positions (trailheads input)]
(println "iteration" i)
(doall
(map #(println % "-" (get-in input %)) positions))
(if (== i 9)
positions
(recur (inc i)
(mapcat (partial step input) positions))))
(trailheads input)
(mapcat (partial step input) (trailheads input))