X-Git-Url: http://git.jkinsey.net/?a=blobdiff_plain;f=src%2Fadventofcode2019%2Flib.clj;h=e81b3062011eb7d0149008ad82c4ab0cabb12535;hb=ab32e54381280135a0df771d293438c195259dc2;hp=e84621639e655f385ba0158994ec687a60fdb613;hpb=cca08f5d8b235974166ebf040bf8426bf1ad786e;p=adventofcode2019.git diff --git a/src/adventofcode2019/lib.clj b/src/adventofcode2019/lib.clj index e846216..e81b306 100644 --- a/src/adventofcode2019/lib.clj +++ b/src/adventofcode2019/lib.clj @@ -1,16 +1,56 @@ (ns adventofcode2019.lib - [:require [clojure.string :as str] - [clojure.java.io :as io]]) + [:require [clojure.string :as str] + [clojure.edn :as edn] + [clojure.java.io :as io] + [clojure.java.shell :refer [sh]]]) (defn get-list-from-file ([file-name] - (str/split-lines (str/trim (slurp file-name)))) + (str/split-lines (str/trim (slurp file-name)))) ([file-name split-regex] - (str/split (str/trim (slurp file-name)) split-regex))) + (str/split (str/trim (slurp file-name)) split-regex))) + +(defn parse-int [n] + (let [n-val (edn/read-string n)] + (if (number? n-val) + n-val + (throw (Exception. "Not a number!"))))) (defmacro input-file [] (let [bottom-ns (last (str/split (str *ns*) #"\."))] (str "resources/" bottom-ns))) -(def parse-int - #(Integer/parseInt %)) +(defn manhattan-distance [[ax ay] [bx by]] + (+ (Math/abs (- ax bx)) + (Math/abs (- ay by)))) + +(defn mmap [f m] + (zipmap (keys m) (map f (vals m)))) + +(def part1 + #(println (str "Part 1: " %))) +(def part2 + #(println (str "Part 2: " %))) + +;; FIXME: this is still broken but i give up for now +; (defn --input-file [for-ns] +; (let [bottom-ns (last (str/split for-ns #"\.")) +; input-url "https://adventofcode.com/2019/day/%d/input" +; day-url (->> bottom-ns +; (drop 3) +; (str/join) +; (parse-int) +; (format input-url)) +; token (str/trim (slurp (io/resource "token"))) +; res-dir (-> (io/resource "token") +; (.getPath) +; (str/replace "token" bottom-ns)) +; cmd ["curl" "-s" "-b" +; (format "\"session=%s\"" token) +; day-url ">" res-dir]] +; (if-let [input (io/resource bottom-ns)] +; input +; (do (apply sh cmd) nil)))) + +; (defmacro input-file [] +; (--input-file (str *ns*)))