diff --git a/2025.clj b/2025.clj index 5afa14d..4ecd4aa 100644 --- a/2025.clj +++ b/2025.clj @@ -15,27 +15,13 @@ L99 R14 L82") -(defn day1-get-sequence [input] - (map (fn [line] - [(if (= "R" (str (first line))) - #'+ - #'-) - (Integer/parseInt (str/join (rest line)))]) - (str/split-lines input))) - -(defn day1-p1 [input] - (let [sequence (day1-get-sequence input)] - (loop [s sequence - curr 50 - zero-count 0] - (if (not (seq s)) - zero-count - (let [[f amount] (first s) - new-dial-pos (mod (f curr amount) 100)] - (recur (rest s) new-dial-pos (if (zero? new-dial-pos) (inc zero-count) zero-count))))))) - -(defn day1-p2 [input] - (let [sequence (day1-get-sequence input)] +(defn day1 [input zero-count-fn] + (let [sequence (map (fn [line] + [(if (= "R" (str (first line))) + #'+ + #'-) + (Integer/parseInt (str/join (rest line)))]) + (str/split-lines input))] (loop [s sequence curr 50 zero-count 0] @@ -43,12 +29,21 @@ L82") zero-count (let [[f amount] (first s) new-dial-pos (mod (f curr amount) 100) - spins (if (and (neg? (f amount)) - (not (zero? curr))) - (quot (+ (- 100 curr) amount) 100) - (quot (+ curr amount) 100))] + spins (zero-count-fn curr (f amount) new-dial-pos)] + (println curr new-dial-pos amount spins) (recur (rest s) new-dial-pos (+ zero-count spins))))))) +(defn day1-p1 [input] + (day1 input (fn [_ _ new-dial-pos] (if (zero? new-dial-pos) 1 0)))) + +(defn day1-p2 [input] + (day1 input (fn [curr rotation _] + (let [amount (abs rotation)] + (if (and (neg? rotation) + (not (zero? curr))) + (quot (+ (- 100 curr) (abs amount)) 100) + (quot (+ curr amount) 100)))))) + (comment (day1-p1 day1-input-test) (day1-p1 (get-input 1))