mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 13:03:19 -09:00
26 lines
761 B
Clojure
26 lines
761 B
Clojure
(ns core
|
|
(:require [clj-http.client :as client]
|
|
[clojure.string :as string]))
|
|
|
|
(def input-cache (atom {}))
|
|
(def cookie (str "session=" (slurp "session")))
|
|
|
|
(defn get-puzzle-input [day]
|
|
(or (@input-cache day)
|
|
(swap! input-cache assoc day
|
|
(-> (str "https://adventofcode.com/2023/day/" day "/input")
|
|
(client/get {:throw-entire-message? true
|
|
:headers {"Cookie" cookie}})
|
|
:body
|
|
string/split-lines))))
|
|
|
|
(defn re-seq-pos [pattern string]
|
|
(let [m (re-matcher pattern string)]
|
|
((fn step []
|
|
(when (. m find)
|
|
(cons {:start (. m start) :end (. m end) :group (. m group)}
|
|
(lazy-seq (step))))))))
|
|
|
|
(comment
|
|
input-cache)
|