mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 12:12:44 -10:00
Compare commits
No commits in common. "66c7ee02d4d7d59c41bd5464f444f21e851ea541" and "116bc23a2c24570cd68468cd9edc932d999d4cc3" have entirely different histories.
66c7ee02d4
...
116bc23a2c
3
2015/.gitignore
vendored
3
2015/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
input/
|
|
||||||
.lein-repl-history
|
|
||||||
*.iml
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
(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"])
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
(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))))
|
|
||||||
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
(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 +))
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
(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,24 +1,26 @@
|
|||||||
(ns day01
|
(ns day01
|
||||||
(:require input-manager))
|
(:require
|
||||||
|
[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 map (comp abs -))
|
(apply zipmap)
|
||||||
(apply +))
|
(map #(abs (apply - %)))
|
||||||
|
(reduce +))
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(let [[left-col right-col] input
|
(let [[a b] input
|
||||||
freqs (frequencies right-col)]
|
freqs (frequencies b)]
|
||||||
(->> left-col
|
(->> a
|
||||||
(map #(* (or (freqs %) 0) %))
|
(map #(* (or (freqs %) 0) %))
|
||||||
(reduce +)))
|
(reduce +)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user