init 2015

This commit is contained in:
Adam Jeniski 2025-11-26 12:18:22 -10:00
parent 116bc23a2c
commit 0492cb1155
5 changed files with 107 additions and 0 deletions

3
2015/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
input/
.lein-repl-history
*.iml

13
2015/project.clj Normal file
View 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"])

27
2015/src/day01.clj Normal file
View File

@ -0,0 +1,27 @@
(ns day01
(:require input-manager))
(def input (input-manager/get-input-raw 2015 01))
(def up? #{\(})
(def down? #{\)})
;; part 1
(-
(count (filter up? input))
(count (filter down? input)))
;; part 2
(loop [i 0
floor 0]
(cond
(< floor 0) i
(up? (.charAt input i))
(recur (inc i)
(inc floor))
:else
(recur (inc i)
(dec floor))))

38
2015/src/day02.clj Normal file
View File

@ -0,0 +1,38 @@
(ns day02
(:require [input-manager]))
(defn parse-line
"s is a string in the form of lxwxh, whee l, w, and h are integral patterns"
[s]
(map parse-long (re-seq #"\d+" s)))
(def input (->> (input-manager/get-input 2015 2)
(map parse-line)))
(defn smallest-side [[l w h]]
(min (* l w)
(* h w)
(* l h)))
(defn paper-needed [[l w h :as args]]
(+ (* 2 (+ (* l w) (* w h) (* h l)))
(smallest-side args)))
;; part 1
(->> input
(map paper-needed)
(apply +))
(defn smallest-perimeter [[l w h]]
(* 2 (min (+ l w)
(+ h w)
(+ l h))))
(defn volume [[l w h]]
(* l w h))
;; part 2
(->> input
(map (juxt smallest-perimeter volume))
(map #(apply + %))
(apply +))

26
2015/src/day03.clj Normal file
View File

@ -0,0 +1,26 @@
(ns day03
(:require [input-manager]
[clojure.set]))
(def input (input-manager/get-input-raw 2015 3))
(defn get-houses [input]
(->> input
(reduce (fn [[[x y] visited]
el]
(let [pos' (condp = el
\> [(inc x) y]
\< [(dec x) y]
\^ [x (inc y)]
\v [x (dec y)])]
[pos' (conj visited pos')]))
[[0 0] #{}])
second))
;; part 1
(count (get-houses input))
;; part 2
(count (clojure.set/union (get-houses (take-nth 2 input))
(get-houses (take-nth 2 (rest input)))))