mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 11:32:45 -10:00
Compare commits
2 Commits
116bc23a2c
...
66c7ee02d4
| Author | SHA1 | Date | |
|---|---|---|---|
| 66c7ee02d4 | |||
| 0492cb1155 |
3
2015/.gitignore
vendored
Normal file
3
2015/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
input/
|
||||||
|
.lein-repl-history
|
||||||
|
*.iml
|
||||||
13
2015/project.clj
Normal file
13
2015/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"])
|
||||||
27
2015/src/day01.clj
Normal file
27
2015/src/day01.clj
Normal 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
38
2015/src/day02.clj
Normal 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
26
2015/src/day03.clj
Normal 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)))))
|
||||||
|
|
||||||
@ -1,26 +1,24 @@
|
|||||||
(ns day01
|
(ns day01
|
||||||
(:require
|
(:require input-manager))
|
||||||
[input-manager :refer [get-input]]
|
|
||||||
[core :as c]))
|
|
||||||
|
|
||||||
(def input (->> (get-input 1)
|
|
||||||
(map #(first (c/get-match-groups #"(\d+)\s+(\d+)" %)))
|
|
||||||
(map #(mapv parse-long %))
|
|
||||||
(into {})
|
|
||||||
((juxt keys vals))))
|
|
||||||
|
|
||||||
;; part 1
|
;; part 1
|
||||||
|
(defn every-other [coll]
|
||||||
|
(take-nth 2 coll))
|
||||||
|
|
||||||
|
(def input (->> (input-manager/get-input-raw 2024 1)
|
||||||
|
(re-seq #"\d+")
|
||||||
|
(map parse-long)
|
||||||
|
((juxt every-other (comp every-other rest)))))
|
||||||
|
|
||||||
(->> input
|
(->> input
|
||||||
(map sort)
|
(map sort)
|
||||||
(apply zipmap)
|
(apply map (comp abs -))
|
||||||
(map #(abs (apply - %)))
|
(apply +))
|
||||||
(reduce +))
|
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(let [[a b] input
|
(let [[left-col right-col] input
|
||||||
freqs (frequencies b)]
|
freqs (frequencies right-col)]
|
||||||
(->> a
|
(->> left-col
|
||||||
(map #(* (or (freqs %) 0) %))
|
(map #(* (or (freqs %) 0) %))
|
||||||
(reduce +)))
|
(reduce +)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user