happy holidays 2025
This commit is contained in:
parent
de3c367d1c
commit
4d525dd3a7
3
2025/.gitignore
vendored
Normal file
3
2025/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
input/
|
||||||
|
.lein-repl-history
|
||||||
|
*.iml
|
||||||
0
2025/.lein-repl-history
Normal file
0
2025/.lein-repl-history
Normal file
4659
2025/input/2025-1.txt
Normal file
4659
2025/input/2025-1.txt
Normal file
File diff suppressed because it is too large
Load Diff
13
2025/project.clj
Normal file
13
2025/project.clj
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
(defproject org.ajet/advent-of-code "0.0.0-SNAPSHOT"
|
||||||
|
:description "my 2024 advent of code solutions in clojure"
|
||||||
|
:url "http://github.com/ajetski/advent-of-code"
|
||||||
|
:min-lein-version "2.0.0"
|
||||||
|
:jvm-opts ["-Xmx16g"]
|
||||||
|
:plugins [[cider/cider-nrepl "0.57.0"]]
|
||||||
|
:dependencies [[org.clojure/clojure "1.12.0"]
|
||||||
|
[org.clojure/data.priority-map "1.2.0"]
|
||||||
|
[org.clojure/math.combinatorics "0.3.0"]
|
||||||
|
[babashka/fs "0.5.23"]
|
||||||
|
[org.babashka/http-client "0.4.22"]
|
||||||
|
[org.clojure/core.match "1.1.0"]]
|
||||||
|
:source-paths ["src" "../shared/clj/src"])
|
||||||
38
2025/src/day01.clj
Normal file
38
2025/src/day01.clj
Normal 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)
|
||||||
Loading…
x
Reference in New Issue
Block a user