(def collect-dups (lst)
(rev (rem [< len._ 2]
(reduce
(fn (accum e)
(if (or (is accum '(())) (is caar.accum e))
(push e car.accum)
(push list.e accum))
accum)
(cons '(()) lst)))))
(def collect-dups- (lst)
(rev (rem [< len._ 2]
(reduce
(fn (accum e)
(if (in caar.accum e nil)
(push e car.accum)
(push list.e accum))
accum)
(cons '(()) lst)))))
(prn (collect-dups '(2 3 3 4 4 4 4 5 6 6 6 7)))
(prn (collect-dups '(2 3 3 4 4 4 4 5 6 6 6 7)))
(prn (collect-dups- '(2 3 3 4 4 4 4 5 6 6 6 7)))
(prn (collect-dups- '(2 3 3 4 4 4 4 5 6 6 6 7)))
Output: ((3 3) (4 4 4 4) (6 6 6))
((3 3) (4 4 4 4) (6 6 6))
((3 3) (4 4 4 4) (6 6 6))
((2 2) (3 3) (4 4 4 4) (6 6 6))
The (2 2) in the last line is wrong. |