There was an error while loading. Please reload this page.
1 parent 678487f commit 34e2dd4Copy full SHA for 34e2dd4
2023/09.clj
@@ -0,0 +1,30 @@
1
+(ns mirage-maintenance
2
+ (:require [clojure.string :as str]))
3
+
4
+(defn differences [xs]
5
+ (->> xs
6
+ (partition 2 1)
7
+ (mapv #(- (second %) (first %)))))
8
9
+(defn pyramidize [xs]
10
+ (->> (iterate differences xs)
11
+ (take-while #(not (= #{0} (set %))))
12
+ (into [])))
13
14
+(defn extrapolate [pyramid] (reduce + (mapv peek pyramid)))
15
16
+(defn parse-line [line] (mapv parse-long (str/split line #"\s")))
17
18
+(->> (slurp "2023/09.in")
19
+ (str/split-lines)
20
+ (mapv parse-line)
21
+ (mapv (comp extrapolate pyramidize))
22
+ (reduce +))
23
24
+;; part 2
25
26
27
28
29
+ (mapv (comp extrapolate pyramidize vec reverse))
30
0 commit comments