diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 14:12:46 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 14:14:38 +0100 |
commit | d3ed2f503e58c604bb85dc3487fda3d1191313b4 (patch) | |
tree | b38ceedc940e8cbd1ab8bddfa6bc7a059ed553eb /2022/lib.lisp | |
parent | 14f428b3a38d0fb1a04de13055e08fc2a4536397 (diff) | |
download | advent-of-code-d3ed2f503e58c604bb85dc3487fda3d1191313b4.tar.gz advent-of-code-d3ed2f503e58c604bb85dc3487fda3d1191313b4.tar.bz2 advent-of-code-d3ed2f503e58c604bb85dc3487fda3d1191313b4.zip |
Version control lib.lisp
Diffstat (limited to '2022/lib.lisp')
-rw-r--r-- | 2022/lib.lisp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/2022/lib.lisp b/2022/lib.lisp new file mode 100644 index 0000000..b6fa70f --- /dev/null +++ b/2022/lib.lisp @@ -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))) |