4 ms·
I just had to take a shot at it... (defun counter (numbers) (reverse (reduce #'(lambda (acc element) (cond ((null acc) (list elem
by Xurinos 16y ago
I just had to take a shot at it...
(defun counter (numbers)
(reverse
(reduce #'(lambda (acc element)
(cond ((null acc) (list element 1))
((= (first acc) element)
(cons element (cons (1+ (second acc)) (cddr acc))))
(t (cons element (cons 1 acc)))))
numbers
:initial-value nil)))
(counter '(4 4 5 5 5 3 3))