53 lines
1.4 KiB
Clojure
53 lines
1.4 KiB
Clojure
(ns aoc2025
|
|
(:require [clojure.string :as str]))
|
|
|
|
(defn get-input [day] (slurp (str "2025/day" day "-input.txt")))
|
|
|
|
(def day1-input-test
|
|
"L68
|
|
L30
|
|
R48
|
|
L5
|
|
R60
|
|
L55
|
|
L1
|
|
L99
|
|
R14
|
|
L82")
|
|
|
|
(defn day1 [input zero-count-fn]
|
|
(let [sequence (map (fn [line]
|
|
[(if (= "R" (str (first line)))
|
|
#'+
|
|
#'-)
|
|
(parse-long (str/join (rest line)))])
|
|
(str/split-lines 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)
|
|
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))
|
|
(day1-p2 day1-input-test)
|
|
(day1-p2 (get-input 1))
|
|
:-)
|