diff --git a/2024/src/core.clj b/2024/src/core.clj index 06fa48f..6a13f39 100644 --- a/2024/src/core.clj +++ b/2024/src/core.clj @@ -1,25 +1,4 @@ -(ns core - (:require - [babashka.fs :as fs] - [babashka.http-client :as http] - [clojure.string :as str])) - -(def session (first (fs/read-all-lines "input/.session"))) - -(defn input-file-loc [day] - (str "input/" day ".txt")) - -(defn download-input [day] - (->> {:headers {:cookie (str "session=" session)}} - (http/get (str "https://adventofcode.com/2024/day/" day "/input")) - :body - (str/split-lines) - (fs/write-lines (input-file-loc day)))) - -(defn get-input [day] - (try - (fs/read-all-lines (input-file-loc day)) - (catch java.nio.file.NoSuchFileException _e - (download-input day) - (get-input day)))) +(ns core) +(defn compose [& fs] + (apply comp (reverse fs))) diff --git a/2024/src/day01.clj b/2024/src/day01.clj index 21ffc6b..cb22db1 100644 --- a/2024/src/day01.clj +++ b/2024/src/day01.clj @@ -1,11 +1,12 @@ (ns day01 (:require - [core :refer [get-input]])) + [input-manager :refer [get-input]] + [core :refer :all])) (def input (->> (get-input 1) - (map #(re-seq #"(\d+)\s+(\d+)" %)) - (map (comp rest first)) - (map (partial mapv parse-long)) + (map (compose #(re-seq #"(\d+)\s+(\d+)" %) + first rest ; only get match groups + #(mapv parse-long %))) (into {}) ((juxt keys vals)))) diff --git a/2024/src/input_manager.clj b/2024/src/input_manager.clj new file mode 100644 index 0000000..ce246dc --- /dev/null +++ b/2024/src/input_manager.clj @@ -0,0 +1,25 @@ +(ns input-manager + (:require + [babashka.fs :as fs] + [babashka.http-client :as http] + [clojure.string :as str])) + +(def session (first (fs/read-all-lines "input/.session"))) + +(defn input-file-loc [day] + (str "input/" day ".txt")) + +(defn download-input [day] + (->> {:headers {:cookie (str "session=" session)}} + (http/get (str "https://adventofcode.com/2024/day/" day "/input")) + :body + (str/split-lines) + (fs/write-lines (input-file-loc day)))) + +(defn get-input [day] + (try + (fs/read-all-lines (input-file-loc day)) + (catch java.nio.file.NoSuchFileException _e + (download-input day) + (get-input day)))) +