(ns day10 (:require [mapped-area] [helpers :refer [get-input]])) (def test-map (mapped-area/parse-elements (mapped-area/read-mapped-area "89010123 78121874 87430965 96549874 45678903 32019012 01329801 10456732"))) (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)))))) (reduce + (map (partial walk test-map) (trailheads test-map)))