File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 59
59
; ## Del 2
60
60
61
61
; TODO
62
+
63
+ (defn last-digit [number] (mod number 10 ))
64
+
65
+ (= 9 (last-digit 8685429 ))
66
+
67
+ (= [-3 6 -1 -1 0 2 -2 0 -2 ]
68
+ (->> (iterate next-secret-number 123 )
69
+ (take 10 )
70
+ (map last-digit)
71
+ (partition 2 1 )
72
+ (map #(apply - (reverse %)))))
73
+
74
+ (defn pattern->value [secret-number]
75
+ (let [numbers (->> (iterate next-secret-number secret-number)
76
+ (take 2001 )
77
+ (mapv last-digit))
78
+ patterns (->> (map - (rest numbers) numbers)
79
+ (partitionv 4 1 ))]
80
+ (transduce (map-indexed vector)
81
+ (completing
82
+ (fn add-if-missing [acc [idx v]]
83
+ (update acc v (fn [old-val]
84
+ (if old-val old-val
85
+ (numbers (+ idx 4 )))))))
86
+ {} patterns)))
87
+
88
+ (defn part-2 [input]
89
+ (let [numbers (map parse-long (re-seq #"\d +" input))]
90
+ (->> numbers
91
+ (map pattern->value)
92
+ (apply merge-with +)
93
+ (apply max-key val))))
94
+
95
+ (part-2 " 1 2 3 2024" )
96
+
97
+ (comment
98
+ (time (part-2 (input/get-input 2024 22 ))))
You can’t perform that action at this time.
0 commit comments