Jump to content


Recommended Posts

;;;;;PERMUTE-SYMMETRCIAL -> seq of any lengths;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; SUB

(defun divide-seq-length (seq)
  (if (evenp (length seq))
    (/ (length seq) 2)
    (/ (1- (length seq)) 2)))

;;; MAIN

(defun permute-symmetrical (row &key (chance 0.5))
  (let ((1st (loop repeat (divide-seq-length row)
               for cnt = 0 then (incf cnt)
               collect (nth cnt row)))
        (2nd (loop repeat (divide-seq-length row)
                   for cnt = (- (length row) 1) then (decf cnt)
                   collect (nth cnt row))))

      for i in 1st
      for j in 2nd

      when (prob? chance)
      collect j into 1st-bag and collect i into 2nd-bag
      else collect i into 1st-bag and collect j into 2nd-bag

      when (= (length 1st-bag) (divide-seq-length row))
      do (return (if (evenp (length row))
                   (append 1st-bag (reverse 2nd-bag))
                   (append 1st-bag (list (nth (length 1st) row)) (reverse 2nd-bag)))))))


 (permute-symmetrical '(a4 bb4 ab4 b4 g4 c5 fs4 cs4 f4 d4 e4 eb4) ;zimmermann-row
                      :chance 0.3))



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.

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