Jump to content

Featured Replies

Posted

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

  • born changed the title to function for choosing numbers in nested lists

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)

  • Author

Say thanks to Claude from me 😀. I will have a look at that. Achim

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy