aoc-cl/src/main.lisp

73 lines
1.9 KiB
Common Lisp
Raw Normal View History

2024-11-17 22:32:08 +01:00
(defpackage aoc
2024-11-18 14:08:48 +01:00
(:use :cl)
(:export
2024-12-01 11:57:25 +01:00
#:split-lines
2024-11-26 00:41:13 +01:00
#:test-input
#:clear-data-cache))
2024-11-18 14:08:48 +01:00
2024-11-17 22:32:08 +01:00
(in-package :aoc)
(defun load-ql-dependencies ()
())
(defvar *aoc-url* "https://adventofcode.com")
(defvar *cookie-jar*
(cl-cookie:make-cookie-jar
:cookies (list
(cl-cookie:make-cookie
:name "session"
:value (uiop:getenv "AOC_SESSION")
:origin-host "adventofcode.com"
:path "/"
:domain ".adventofcode.com"
:secure-p t))))
(setf *cookie-jar*
(cl-cookie:make-cookie-jar
:cookies (list
(cl-cookie:make-cookie
:name "session"
:value (uiop:getenv "AOC_SESSION")
:origin-host "adventofcode.com"
:path "/"
:domain ".adventofcode.com"
:secure-p t))))
2024-11-26 00:41:13 +01:00
(defun split-lines (s)
(cl-ppcre:split "\\n" s))
2024-11-17 22:32:08 +01:00
(defun fetch-input-data (year day)
2024-11-17 22:32:08 +01:00
(let ((url (format nil "~A/~D/day/~D/input" *aoc-url* year day)))
(multiple-value-bind
(body)
(dex:get url :cookie-jar *cookie-jar* :verbose t)
2024-11-26 00:41:13 +01:00
(split-lines body))))
2024-11-17 22:32:08 +01:00
(defvar *input-data-cache* (make-hash-table))
2024-11-26 00:41:13 +01:00
(defun clear-data-cache ()
(setf *input-data-cache* (make-hash-table)))
(defun test-input (year day)
"Return input data for the given challenge. Use a cached value if already fetched"
(let* ((key (+ (* year 100) day))
(val (gethash key *input-data-cache*)))
(if val
val
(setf (gethash key *input-data-cache*) (fetch-input-data year day)))))
(defun print-thread-info ()
(let* ((curr-thread sb-thread:*current-thread*)
(curr-thread-name (sb-thread:thread-name curr-thread))
(all-threads (sb-thread:list-all-threads)))
(format t "Current thread: ~a~%~%" curr-thread)
(format t "Current thread name: ~a~%~%" curr-thread-name)
(format t "All threads:~% ~{~a~%~}~%" all-threads))
nil)