Version control lib.lisp
This commit is contained in:
28
2022/lib.lisp
Normal file
28
2022/lib.lisp
Normal 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)))
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
collect
|
collect
|
||||||
(let ((opponent (subseq strategy 0 1))
|
(let ((opponent (subseq strategy 0 1))
|
||||||
(yours (subseq strategy 2 3)))
|
(yours (subseq strategy 2 3)))
|
||||||
(list (sensible-convert-input opponent) (sensible-convert-input yours))))))
|
(list (sensible-convert-input opponent)
|
||||||
|
(sensible-convert-input yours))))))
|
||||||
|
|
||||||
(loop
|
(loop
|
||||||
for round in rounds
|
for round in rounds
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
(load "lib.lisp")
|
||||||
(defvar input (uiop:read-file-string "3-input"))
|
(defvar input (uiop:read-file-string "3-input"))
|
||||||
|
|
||||||
(defun split-string-in-two (s)
|
(defun split-string-in-two (s)
|
||||||
@@ -10,9 +11,6 @@
|
|||||||
until (null line)
|
until (null line)
|
||||||
collect (split-string-in-two line))))
|
collect (split-string-in-two line))))
|
||||||
|
|
||||||
(defun string-to-clist (str)
|
|
||||||
(loop for char across str collect char))
|
|
||||||
|
|
||||||
(defun common-types (s1 s2)
|
(defun common-types (s1 s2)
|
||||||
(car (intersection
|
(car (intersection
|
||||||
(string-to-clist s1)
|
(string-to-clist s1)
|
||||||
|
|||||||
Reference in New Issue
Block a user