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