AM Posted July 30, 2016 Share Posted July 30, 2016 don't konw if something like this exists in ONE function... could be useful!! andré (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)) Quote Link to comment Share on other sites More sharing options...
opmo Posted July 30, 2016 Share Posted July 30, 2016 You may like this: (encode-consecutive '(a a a a b c c a a d e e e e)) => ((4 a) (1 b) (2 c) (2 a) (1 d) (4 e)) (group-consecutive '(a a a a b c c a a d e e e e)) => ((a a a a) (b) (c c) (a a) (d) (e e e e)) AM and Stephane Boussuge 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.