Version control lib.lisp

This commit is contained in:
2023-10-17 14:12:46 +01:00
parent 14f428b3a3
commit d3ed2f503e
3 changed files with 31 additions and 4 deletions

28
2022/lib.lisp Normal file
View File

@@ -0,0 +1,28 @@
(defun string-to-clist (str)
(coerce str 'list))
(defun clist-to-string (clist)
(if (atom clist)
(string clist)
(coerce clist 'string)))
(defun split-by (lst delim)
"Splits LST by the first instance of DELIM"
(let ((pos (position delim lst)))
(if pos
(cons (subseq lst 0 pos) (list (subseq lst (+ pos 1))))
(error (format nil "No instance of ~a was found in ~a" delim lst)))))
(defun split-completely (lst delim)
(if (or (null lst) (not (cdr lst)))
(cons (list (car lst)) nil)
(if (member delim lst)
(destructuring-bind (first rest) (split-by lst delim)
(cons first (split-completely rest delim)))
(list lst))))
(defun get-lines (input-string)
(with-input-from-string (s input-string)
(loop for line = (read-line s nil)
while line
collect line)))

View File

@@ -16,7 +16,8 @@
collect
(let ((opponent (subseq strategy 0 1))
(yours (subseq strategy 2 3)))
(list (sensible-convert-input opponent) (sensible-convert-input yours))))))
(list (sensible-convert-input opponent)
(sensible-convert-input yours))))))
(loop
for round in rounds

View File

@@ -1,3 +1,4 @@
(load "lib.lisp")
(defvar input (uiop:read-file-string "3-input"))
(defun split-string-in-two (s)
@@ -10,9 +11,6 @@
until (null line)
collect (split-string-in-two line))))
(defun string-to-clist (str)
(loop for char across str collect char))
(defun common-types (s1 s2)
(car (intersection
(string-to-clist s1)