aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-17 20:41:54 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-17 20:41:54 +0100
commitf32f774eaec01d604f1a48055296716a49ebb678 (patch)
tree35f4a4e1af0e31d29ed24fb10cabd4bb4210c7c8
parentdb2ef41d1980d6402d40b13c29880467223290dc (diff)
downloadadvent-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.lisp14
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)))))