From 88351633d250638b02ad499123ec44bb39edf3ef Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 3 Dec 2024 16:39:58 +0000 Subject: Add search-all function to util.lisp for 2024 --- 2024/util.lisp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/2024/util.lisp b/2024/util.lisp index f9b1d86..11ec230 100644 --- a/2024/util.lisp +++ b/2024/util.lisp @@ -5,7 +5,16 @@ appending `((_ ,f))) _))) -(defun zip (a b) - (loop for i in a - for j in b - collect (cons i j))) +(defun search-all (substr str &optional acc len) + (let ((x (search substr str)) + (len (or len 0))) + (if (null x) + (reverse acc) + (search-all substr (subseq str (1+ x)) + (cons (+ x len) acc) + (+ len x 1))))) + + (defun zip (a b) + (loop for i in a + for j in b + collect (cons i j))) -- cgit v1.2.3-13-gbd6f