1 (ns adventofcode2019.lib
2 [:require [clojure.string :as str]
3 [clojure.java.io :as io]
4 [clojure.java.shell :refer [sh]]])
6 (defn get-list-from-file
8 (str/split-lines (str/trim (slurp file-name))))
9 ([file-name split-regex]
10 (str/split (str/trim (slurp file-name)) split-regex)))
13 #(Integer/parseInt %))
15 (defmacro input-file []
16 (let [bottom-ns (last (str/split (str *ns*) #"\."))]
17 (str "resources/" bottom-ns)))
19 (defn manhattan-distance [[ax ay] [bx by]]
20 (+ (Math/abs (- ax bx))
21 (Math/abs (- ay by))))
24 #(println (str "Part 1: " %)))
26 #(println (str "Part 2: " %)))
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
37 ; token (str/trim (slurp (io/resource "token")))
38 ; res-dir (-> (io/resource "token")
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)]
46 ; (do (apply sh cmd) nil))))
48 ; (defmacro input-file []
49 ; (--input-file (str *ns*)))