Skip to content

Commit 1ac8a4a

Browse files
committed
2024, day 2
1 parent e18f6cb commit 1ac8a4a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2024/02.clj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)