Fix day11pt1 and add correct day11pt2
[adventofcode2019.git] / src / adventofcode2019 / lib.clj
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 (def part1
28 #(println (str "Part 1: " %)))
29 (def part2
30 #(println (str "Part 2: " %)))
31
32 ;; FIXME: this is still broken but i give up for now
33 ; (defn --input-file [for-ns]
34 ; (let [bottom-ns (last (str/split for-ns #"\."))
35 ; input-url "https://adventofcode.com/2019/day/%d/input"
36 ; day-url (->> bottom-ns
37 ; (drop 3)
38 ; (str/join)
39 ; (parse-int)
40 ; (format input-url))
41 ; token (str/trim (slurp (io/resource "token")))
42 ; res-dir (-> (io/resource "token")
43 ; (.getPath)
44 ; (str/replace "token" bottom-ns))
45 ; cmd ["curl" "-s" "-b"
46 ; (format "\"session=%s\"" token)
47 ; day-url ">" res-dir]]
48 ; (if-let [input (io/resource bottom-ns)]
49 ; input
50 ; (do (apply sh cmd) nil))))
51
52 ; (defmacro input-file []
53 ; (--input-file (str *ns*)))