| 1 | (ns adventofcode2019.lib |
| 2 | [:require [clojure.string :as str] |
| 3 | [clojure.edn :as edn] |
| 4 | [clojure.java.io :as io] |
| 5 | [clojure.java.shell :refer [sh]]]) |
| 6 | |
| 7 | (defn get-list-from-file |
| 8 | ([file-name] |
| 9 | (str/split-lines (str/trim (slurp file-name)))) |
| 10 | ([file-name split-regex] |
| 11 | (str/split (str/trim (slurp file-name)) split-regex))) |
| 12 | |
| 13 | (defn parse-int [n] |
| 14 | (let [n-val (edn/read-string n)] |
| 15 | (if (number? n-val) |
| 16 | n-val |
| 17 | (throw (Exception. "Not a number!"))))) |
| 18 | |
| 19 | (defmacro input-file [] |
| 20 | (let [bottom-ns (last (str/split (str *ns*) #"\."))] |
| 21 | (str "resources/" bottom-ns))) |
| 22 | |
| 23 | (defn manhattan-distance [[ax ay] [bx by]] |
| 24 | (+ (Math/abs (- ax bx)) |
| 25 | (Math/abs (- ay by)))) |
| 26 | |
| 27 | (defn mmap [f m] |
| 28 | (zipmap (keys m) (map f (vals m)))) |
| 29 | |
| 30 | (def part1 |
| 31 | #(println (str "Part 1: " %))) |
| 32 | (def part2 |
| 33 | #(println (str "Part 2: " %))) |
| 34 | |
| 35 | ;; FIXME: this is still broken but i give up for now |
| 36 | ; (defn --input-file [for-ns] |
| 37 | ; (let [bottom-ns (last (str/split for-ns #"\.")) |
| 38 | ; input-url "https://adventofcode.com/2019/day/%d/input" |
| 39 | ; day-url (->> bottom-ns |
| 40 | ; (drop 3) |
| 41 | ; (str/join) |
| 42 | ; (parse-int) |
| 43 | ; (format input-url)) |
| 44 | ; token (str/trim (slurp (io/resource "token"))) |
| 45 | ; res-dir (-> (io/resource "token") |
| 46 | ; (.getPath) |
| 47 | ; (str/replace "token" bottom-ns)) |
| 48 | ; cmd ["curl" "-s" "-b" |
| 49 | ; (format "\"session=%s\"" token) |
| 50 | ; day-url ">" res-dir]] |
| 51 | ; (if-let [input (io/resource bottom-ns)] |
| 52 | ; input |
| 53 | ; (do (apply sh cmd) nil)))) |
| 54 | |
| 55 | ; (defmacro input-file [] |
| 56 | ; (--input-file (str *ns*))) |