diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 20:07:19 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 20:07:19 +0100 |
commit | ceaaad427c52c33d7d0b208ac22f97d1ab24a4d5 (patch) | |
tree | 98139103d9eee05012edc56968fa2df250c25efc /2022 | |
parent | f11415c365f1252403d2473e2a47a86afad81463 (diff) | |
download | advent-of-code-ceaaad427c52c33d7d0b208ac22f97d1ab24a4d5.tar.gz advent-of-code-ceaaad427c52c33d7d0b208ac22f97d1ab24a4d5.tar.bz2 advent-of-code-ceaaad427c52c33d7d0b208ac22f97d1ab24a4d5.zip |
split-by->split-by-first, split-completely->split-by-completely
Diffstat (limited to '2022')
-rw-r--r-- | 2022/lib.lisp | 8 | ||||
-rw-r--r-- | 2022/puzzle-7.lisp | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/2022/lib.lisp b/2022/lib.lisp index b6fa70f..7499e72 100644 --- a/2022/lib.lisp +++ b/2022/lib.lisp @@ -6,19 +6,19 @@ (string clist) (coerce clist 'string))) -(defun split-by (lst delim) +(defun split-by-first (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) +(defun split-by-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))) + (destructuring-bind (first rest) (split-by-first lst delim) + (cons first (split-by-completely rest delim))) (list lst)))) (defun get-lines (input-string) diff --git a/2022/puzzle-7.lisp b/2022/puzzle-7.lisp index 76879e9..08dd08d 100644 --- a/2022/puzzle-7.lisp +++ b/2022/puzzle-7.lisp @@ -6,7 +6,7 @@ "Split each LINE in LINES by space" (mapcar (lambda (line) (mapcar #'clist-to-string - (split-completely (string-to-clist line) #\Space))) + (split-by-completely (string-to-clist line) #\Space))) lines)) (defun is-token-cmd? (token) |