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