Posted June 9Jun 9 Dear all,I would like to make a function for the following purpose:I have a list of 4 lists. I would like to start from any of the numbers in the first list and choose the corresponding next or after next (could be random) higher numbers in the subsequent lists.Here an example:((2 8 9 14 20 21 26) (1 2 3 7 13 14 19 25 26) (0 6 7 12 18 19 24) (0 5 11 12 17 23 24))or((2 8 9 14 20 21 26) (1 2 3 7 13 14 19 25 26) (0 6 7 12 18 19 24) (0 5 11 12 17 23 24))or((2 8 9 14 20 21 26) (1 2 3 7 13 14 19 25 26) (0 6 7 12 18 19 24) (0 5 11 12 17 23 24))Has anyone an idea how to implement this?Thanks for help.Achim
June 10Jun 10 Hi, Out of curiosity I asked the AI-promt Claude (https://claude.ai) and the code it spits out seem to work. Maybe it is useful as a starting point..? best(defun select-path (lists &optional start-num) (let ((current (if start-num start-num (nth (random (length (first lists))) (first lists)))) (result nil)) (push current result) (dolist (lst (rest lists)) (let* ((higher (remove-if (lambda (x) (<= x current)) lst)) (next (when higher (if (and (> (length higher) 1) (zerop (random 2))) (second higher) ; next-next higher (first higher))))) ; next higher (when next (setf current next) (push current result)))) (reverse result))) (select-path '((2 8 9 14 20 21 26) (1 2 3 7 13 14 19 25 26) (0 6 7 12 18 19 24) (0 5 11 12 17 23 24)) 8)
Create an account or sign in to comment