diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 20:41:54 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 20:41:54 +0100 |
commit | f32f774eaec01d604f1a48055296716a49ebb678 (patch) | |
tree | 35f4a4e1af0e31d29ed24fb10cabd4bb4210c7c8 | |
parent | db2ef41d1980d6402d40b13c29880467223290dc (diff) | |
download | advent-of-code-f32f774eaec01d604f1a48055296716a49ebb678.tar.gz advent-of-code-f32f774eaec01d604f1a48055296716a49ebb678.tar.bz2 advent-of-code-f32f774eaec01d604f1a48055296716a49ebb678.zip |
Added all and remove-nth
Does what they say, all is the logical inverse to some.
-rw-r--r-- | 2022/lib.lisp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/2022/lib.lisp b/2022/lib.lisp index 7499e72..2441481 100644 --- a/2022/lib.lisp +++ b/2022/lib.lisp @@ -26,3 +26,17 @@ (loop for line = (read-line s nil) while line collect line))) + +(defun all (pred lst) + (if (not (cdr lst)) + (funcall pred (car lst)) + (and (funcall pred (car lst)) + (all pred (cdr lst))))) + +(defun remove-nth (n lst) + (if (or (null lst) (= n 0)) + (cdr lst) + (cons (car lst) + (remove-nth + (- n 1) + (cdr lst))))) |