Jump to content

gen-symmetrical (with rnd-unique)


Recommended Posts

;;; alternative function for GEN-SYMMETRICAL: in combination 
;;; with FIND-UNIQUE => symmetries with unique items (except 
;;; what is generated by symmetry)


(defun gen-symmetrical* (n list)
  (let ((list (rnd-order list))
        (newlist (rest list))
        (center (car list)))   

    (if (> n (* 2 (length list)))
      'list-has-too-few-items
      (if (evenp n)
        (progn
          (setf list (rnd-unique (/ n 2) newlist))
          (append list (reverse list)))
        (progn 
          (setf list (rnd-unique (/ (1- n) 2) (rest newlist)))
          (append list (list center) (reverse list)))))))
  

(gen-symmetrical* 5 '(1 2 3 4 5 6 7 8))
(gen-symmetrical* 9 '(1 2 3 4 5 6 7 8))

(gen-symmetrical* 30 '(1 2 3 4 5 6 7 8))
=> list-has-too-few-items ; error-message

 

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