Jump to content


Recommended Posts

don't konw if something like this exists in ONE function... could be useful!! 


(defun count-repetitions (value-list)

  (let ((seq (append value-list (list 'nil))))
    (loop repeat (1- (length seq))
      with count = 1
      for cnt1 = 0 then (incf cnt1)
      for cnt2 = 1 then (incf cnt2)

      when (equal (nth cnt1 seq) (nth cnt2 seq)) do (incf count)
      when (not (equal (nth cnt1 seq) (nth cnt2 seq))) collect count and do (setq count 1))))

(count-repetitions '(1 1 2 2 2 3 4 4 1))
(count-repetitions '(abc bc a a a a bc))


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