There was an error while loading. Please reload this page.
1 parent e18f6cb commit 1ac8a4aCopy full SHA for 1ac8a4a
2024/02.clj
@@ -0,0 +1,22 @@
1
+(require '[clojure.string :as str])
2
+
3
+(defn valid-report? [xs]
4
+ (and (or (apply < xs) (apply > xs))
5
+ (every? (fn [[x y]] (<= 1 (abs (- x y)) 3))
6
+ (partition 2 1 xs))))
7
8
+(defn dampen-problems
9
+ ([xs]
10
+ (cons xs (dampen-problems [] xs)))
11
+ ([before [head & tail]]
12
+ (if (seq tail)
13
+ (lazy-seq (cons (into before tail)
14
+ (dampen-problems (conj before head) tail)))
15
+ [before])))
16
17
+(let [reports
18
+ (->> (slurp "2024/02.in")
19
+ (str/split-lines)
20
+ (map (fn [line] (map parse-long (re-seq #"\d+" line)))))]
21
+ [(count (filter valid-report? reports))
22
+ (count (filter #(some valid-report? (dampen-problems %)) reports))])
0 commit comments