aboutsummaryrefslogtreecommitdiffstats
path: root/day9/part1.clj
diff options
context:
space:
mode:
Diffstat (limited to 'day9/part1.clj')
-rw-r--r--day9/part1.clj40
1 files changed, 12 insertions, 28 deletions
diff --git a/day9/part1.clj b/day9/part1.clj
index 813d5a6..7bd8e23 100644
--- a/day9/part1.clj
+++ b/day9/part1.clj
@@ -5,33 +5,17 @@
(mapv (partial mapv #(- (int %) 48)))
))
-(defn compare-heights [a b]
- (if (or (nil? a) (nil? b) (< a b)) 1 0))
+(defn get-adj [y x]
+ (map (partial get-in input-map)
+ [[(dec y) x] [(inc y) x] [y (dec x)] [y (inc x)]]))
-(println
- (apply +
- (for [y (range 0 (count input-map))
- x (range 0 (count (first input-map)))]
- (let [height (get-in input-map [y x])]
- (if
- (= 4
- (apply +
- (map
- (partial compare-heights height)
- [
- (get-in input-map [(dec y) x])
- (get-in input-map [(inc y) x])
- (get-in input-map [y (dec x)])
- (get-in input-map [y (inc x)])
- ]
- )
- )
- )
- (inc height)
- 0
- )
- )
- )
- )
- )
+(->> (for [y (range 0 (count input-map))
+ x (range 0 (count (first input-map)))
+ :let [height (get-in input-map [y x])]
+ :when (every? #(or (nil? %) (< height %))
+ (get-adj y x))]
+ (inc height))
+ (apply +)
+ (println)
+ )