Author Topic: Find The Atom With The Most Occurrences In A List  (Read 3958 times)

0 Members and 1 Guest are viewing this topic.

ur_naz

  • Newt
  • Posts: 68
  • Made in Ukraine
Re: Find The Atom With The Most Occurrences In A List
« Reply #15 on: August 31, 2013, 09:39:42 AM »
This is my simple version. Just for test
Code - Auto/Visual Lisp: [Select]
  1. (defun foo (lst)
  2.   (if lst
  3.     (cons (vl-remove-if-not '(lambda (x) (= x (car lst))) lst)
  4.           (foo (vl-remove (car lst) lst))
  5.     )
  6.   )
  7. )
  8.  
  9. (defun test (lst / mln)
  10.   (setq lst (foo lst)
  11.         mln (apply 'max (mapcar 'length lst))
  12.   )
  13.   (mapcar 'car
  14.           (vl-remove-if '(lambda (x) (> mln (length x))) lst)
  15.   )
  16. )
_$ (test '(4 3 2 1 4 3 2 4 3 4 5 5 5 5))
(4 5)