do day3
This commit is contained in:
parent
6306a76b7e
commit
7f4c260855
26
2025/src/day03.clj
Normal file
26
2025/src/day03.clj
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
(ns day03
|
||||||
|
(:require input-manager))
|
||||||
|
|
||||||
|
(def input (input-manager/get-input 2025 3))
|
||||||
|
|
||||||
|
(defn max-joltage [bank num-batteries-to-activate]
|
||||||
|
(let [len (count bank)]
|
||||||
|
(loop [n num-batteries-to-activate
|
||||||
|
acc ""
|
||||||
|
idx-iter 0]
|
||||||
|
(let [search-space (.substring bank idx-iter (- len (dec n)))
|
||||||
|
max-char (apply max (map int search-space))
|
||||||
|
max-char-idx (.indexOf bank max-char idx-iter)]
|
||||||
|
(if (= n 1)
|
||||||
|
(parse-long (str acc (char max-char)))
|
||||||
|
(recur (dec n)
|
||||||
|
(str acc (char max-char))
|
||||||
|
(inc max-char-idx)))))))
|
||||||
|
|
||||||
|
(->> input
|
||||||
|
(map #(max-joltage % 2))
|
||||||
|
(apply +))
|
||||||
|
|
||||||
|
(->> input
|
||||||
|
(map #(max-joltage % 12))
|
||||||
|
(apply +))
|
||||||
Loading…
x
Reference in New Issue
Block a user