Rework day14pt1
[adventofcode2019.git] / src / adventofcode2019 / lib.clj
CommitLineData
cca08f5d
JK
1(ns adventofcode2019.lib
2 [:require [clojure.string :as str]
92053791 3 [clojure.edn :as edn]
d0f13cd2
JK
4 [clojure.java.io :as io]
5 [clojure.java.shell :refer [sh]]])
cca08f5d
JK
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
92053791
JK
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!")))))
d0f13cd2 18
cca08f5d
JK
19(defmacro input-file []
20 (let [bottom-ns (last (str/split (str *ns*) #"\."))]
21 (str "resources/" bottom-ns)))
22
f1a195aa
JK
23(defn manhattan-distance [[ax ay] [bx by]]
24 (+ (Math/abs (- ax bx))
25 (Math/abs (- ay by))))
26
49dee54b
JK
27(defn mmap [f m]
28 (reduce-kv #(assoc %1 %2 (f %3)) {} m))
29
0503903a
JK
30(def part1
31 #(println (str "Part 1: " %)))
32(def part2
33 #(println (str "Part 2: " %)))
d0f13cd2
JK
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*)))