Jump to content

rnd-symmetrical-position-swap


Recommended Posts

;;; SWAPS THE POSITIONS SYMMETRICALLY AND RANDOMIZED 
;;; n => number of generations, output: last gen or all gens...
;;; new-version works also for symmetrical-sequences! (special cas)

(defun rnd-symmetrical-position-swap (n liste &key (out 'all))
  (let ((n1) (n2))
    (progn
      (setf liste (loop repeat n
                    do (setf n1 (random (1- (list-length-divide liste)))
                             n2 (random (1- (list-length-divide liste))))
                    collect (progn 
                              (setf liste (position-swap
                                           (list (list n1 n2) 
                                                 (list 
                                                  (- (1- (length liste)) n1)
                                                  (- (1- (length liste)) n2)))
                                           
                                           liste)))))
      (cond ((equal out 'last)
             (car (last liste)))
            ((equal out 'all)
             (append liste))))))


(rnd-symmetrical-position-swap 2 '(1 2 3 4 3 2 1) :out 'last)
(rnd-symmetrical-position-swap 5 '(1 2 3 4 5 6) :out 'last)
(rnd-symmetrical-position-swap 2 '(a b c d e f g h) :out 'all)

 

Edited by AM
edited
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy