]> localhost Git - adventofcode2019.git/blame - src/adventofcode2019/lib.clj
Add broken day16pt2
[adventofcode2019.git] / src / adventofcode2019 / lib.clj
CommitLineData
cca08f5d 1(ns adventofcode2019.lib
7a710645
JK
2 [:require [clojure.string :as str]
3 [clojure.edn :as edn]
4 [clojure.java.io :as io]
5 [clojure.java.shell :refer [sh]]])
cca08f5d
JK
6
7(defn get-list-from-file
8 ([file-name]
7a710645 9 (str/split-lines (str/trim (slurp file-name))))
cca08f5d 10 ([file-name split-regex]
7a710645 11 (str/split (str/trim (slurp file-name)) split-regex)))
cca08f5d 12
92053791
JK
13(defn parse-int [n]
14 (let [n-val (edn/read-string n)]
15 (if (number? n-val)
7a710645
JK
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
7a710645 23(defn manhattan-distance [[ax ay] [bx by]]
f1a195aa
JK
24 (+ (Math/abs (- ax bx))
25 (Math/abs (- ay by))))
26
49dee54b 27(defn mmap [f m]
7a710645 28 (zipmap (keys m) (map f (vals m))))
49dee54b 29
7a710645 30(def part1
0503903a 31 #(println (str "Part 1: " %)))
7a710645 32(def part2
0503903a 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*)))