Jump to content

born

Members
  • Posts

    82
  • Joined

  • Last visited

Posts posted by born

  1. Something like this:

     

    (defparameter durations '(15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 1/32 5/32 1/32 13/16 17/32 3/2 9/16 7/16))
    
    (defun length-to-rnd-rest (numb dur-lst)
      (let* ((llst (- (length dur-lst) 1))
             (minnumb (min numb llst))
             (posns (sort-asc (rnd-unique minnumb (gen-integer 0 llst)))))
        (loop for i in dur-lst
              for j from 0
              collect (if (member j posns)
                          (* -1 i) i ))))
    
    (length-to-rnd-rest 5 durations)

     

    I get only 4 rests in this example:

    (defparameter durations '(15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 1/32 5/32 1/32 13/16 17/32 3/2 9/16 7/16))
    
    (length-invert durations :section (rnd-sample 5 (gen-integer 0 (1- (length durations))) :norep t :seed 4))
    
    ;; => (15/16 15/32 1/32 1/32 1/32 61/32 1/32 1/2 -5/32 -13/16 1/32 -9/16 17/32 3/2 -1/32 7/16)

     

  2. 17 hours ago, opmo said:

    This is not an error. The documents (pdf) are not really for text copy/past. You never know how pdf behaves. 

    And if you copy you need to take some care of the code.

    I think, they should be usable for copy & paste. Its probably a common use to copy extracts from the documentation for further coding, don't you think?

    Achim

  3. Hi,

    attached is a function I wrote for a piece.

    Does anybody have an idea how to extend this with a seed functionality. I have tried a few things but so far without any real success ...

    The other thing: It can take quite a while until a possible solution ist found. Does anybody have an idea to improve the calculation speed?

    Thanks and best,

    Achim

    fill-space.opmo

  4. I use this to select different unique modules for Live-Electronics.

    Here ist my adapted function:

     

    (defun comb-to-sum (n &key (reps t))
      (let* ((nums (gen-integer 1 n))
             (x 0)
             (result
              (find-unique
               (sort-asc
                (flatten-sublist
                 (loop repeat n
                   for i = (combination2 (incf x) nums)
                   collect (loop for c in i
                             if (= (sum c) n)
                             collect c)))))))
        (if reps
          result
          (loop for i in result
            when (equal (sum (remove-duplicates i)) n)
            collect i))))
    
    (comb-to-sum 5 :reps nil) ; => ((5) (1 4) (2 3))

     

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy