diff --git a/2015/.gitignore b/2015/.gitignore new file mode 100644 index 0000000..faa2c58 --- /dev/null +++ b/2015/.gitignore @@ -0,0 +1,3 @@ +input/ +.lein-repl-history +*.iml \ No newline at end of file diff --git a/2015/project.clj b/2015/project.clj new file mode 100644 index 0000000..2f76275 --- /dev/null +++ b/2015/project.clj @@ -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"]) diff --git a/2015/src/day01.clj b/2015/src/day01.clj new file mode 100644 index 0000000..88a69cd --- /dev/null +++ b/2015/src/day01.clj @@ -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)))) + diff --git a/2015/src/day02.clj b/2015/src/day02.clj new file mode 100644 index 0000000..50916d3 --- /dev/null +++ b/2015/src/day02.clj @@ -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 +)) diff --git a/2015/src/day03.clj b/2015/src/day03.clj new file mode 100644 index 0000000..4098366 --- /dev/null +++ b/2015/src/day03.clj @@ -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))))) +