aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-12-03 16:39:58 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-12-03 16:39:58 +0000
commit88351633d250638b02ad499123ec44bb39edf3ef (patch)
tree077a4dda113a6b6befc9f8790d381cad042dbc6e
parent1ddc695cb9e0c0d8dfe87ade4981142155cd91bf (diff)
downloadadvent-of-code-88351633d250638b02ad499123ec44bb39edf3ef.tar.gz
advent-of-code-88351633d250638b02ad499123ec44bb39edf3ef.tar.bz2
advent-of-code-88351633d250638b02ad499123ec44bb39edf3ef.zip
Add search-all function to util.lisp for 2024
-rw-r--r--2024/util.lisp17
1 files 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)))