;; Verschachtelte Listen: ; compare-lists (defun compare-lists-1 (list-1 list-2) (cond ( (and (null list-1) (null list-2)) T ) ( (and (listp (first list-1)) (listp (first list-2))) (and (compare-lists-1 (first list-1) (first list-2)) (compare-lists-1 (rest list-1) (rest list-2))) ) ( (or (listp (first list-1)) (listp (first list-2))) nil ) ( T (and (= (first list-1) (first list-2)) (compare-lists-1 (rest list-1) (rest list-2))) ))) (defun compare-lists-2 (list-1 list-2) (cond ( (and (listp list-1) (listp list-2)) (notany #'null (mapcar #'compare-lists-2 list-1 list-2)) ) ( (or (listp list-1) (listp list-2)) nil ) ( T (= list-1 list-2) ))) ; flatten (defun flatten-1 (l) (cond ( (null l) l ) ( (listp (first l)) (append (flatten-1 (first l)) (flatten-1 (rest l))) ) ( T (cons (first l) (flatten-1 (rest l))) ))) (defun flatten-2 (ls) (cond ( (listp ls) (apply #'append (mapcar #'flatten-2 ls)) ) ( T (list ls)))) ; max-list (defun max-list-1 (ls) (apply #'max (flatten-1 ls))) (defun max-list-2 (l &optional (maximum nil)) (cond ( (null l) maximum ) ( (listp (first l)) (max (max-list-2 (first l) maximum) (max-list-2 (rest l) maximum)) ) ( T (max-list-2 (rest l) (max (first l) (if maximum maximum 0))) ))) ; max-depth (defun max-depth-1 (l) (cond ( (listp l) (1+ (reduce #'max (mapcar #'max-depth-1 l))) ) ( T 0 ))) (defun max-depth-2 (ls) (cond ( (listp ls) (1+ (apply #'max (mapcar #'max-depth-2 ls))) ) ( T 0 ))) ;; Kapselung mit let (let ( (stack ()) ) (defun empty-stack () (null stack)) (defun push-elt (element) (push element stack)) (defun top-elt () (first stack)) (defun pop-stack () (setf stack (rest stack)))) (let ( (random-state (make-random-state T)) ) (defun random-list (count &key (range 1000)) (cond ( (= count 0) () ) ( T (cons (random range random-state) (random-list (1- count) :range range)) ))))