happy holidays 2025

This commit is contained in:
2025-12-01 11:06:15 -10:00
parent de3c367d1c
commit 4d525dd3a7
5 changed files with 4713 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
(ns day01
(:require input-manager
#_[clojure.string :as str]))
(defn parse-line [line]
[(.charAt line 0)
(parse-long (.substring line 1))])
(def input (->> (input-manager/get-input 2025 01)
(map parse-line)))
(def op {\R +, \L -})
(defn normalize [n]
(mod n 100))
;; part 1
(->> input
(reductions (fn [acc [dir turn-cnt]]
(normalize ((op dir) acc turn-cnt)))
50)
(filter (partial = 0))
count)
;; part 2
(->> input
(reduce (fn [[acc dial] [dir turn-cnt]]
(let [next-dial ((op dir) dial turn-cnt)]
[(+ acc (cond (> next-dial 99) (int (/ next-dial 100))
(< next-dial 0) (+ (abs (int (/ next-dial 100)))
(if (= dial 0)
0
1))
(= next-dial 0) 1
:else 0))
(normalize next-dial)]))
[0 50])
first)