(setq nl '("12" "13" "14" "1" "3" "4" "6" "7" "2" "8" "9" "10" "16" "17" "18" "22" "24" "26" "27" "20" "21" "19" "23" "15" "29" "34" "35" "36" "37" "29" "31" "32" "33" "30" "38" "39" "40" "41" "42" "43" "49" "44" "45" "46" "47" "48" "50" "50" "48" "5" "25" "28"))
'("A" "B" "C" "D" "D" "A") -> '(("A" . 2) ("B" . 1) ("C" . 1) ("D" . 2))
And by that way the duplicates can be found.
(wcmatch str "~*[~0-9]*")
(defun anum (lst / lastitm neg missing)
(foreach itm (vl-sort (mapcar 'atoi lst) '>)
(cond
((minusp itm) (setq neg (cons itm neg)))
((null lastitm) (setq lastitm itm))
(t (if (/= (1- lastitm) itm)
(progn (while (/= (1- lastitm) itm)
(setq missing (cons (1- lastitm) missing)
lastitm (1- lastitm)))(setq lastitm (1- lastitm)))
(setq lastitm itm)
)
)
)
)
(list neg missing)
)
A different approach, return numbers though
..You don't need to worry about performance then .. go for your own readability :)
The list is normally less than 100 atoms so I guess (member) testing is not all that bad.
..
Code: [Select](defun qs ( l )
( (lambda ( f ) (if l (f (car l) (cdr l))))
(lambda ( x l / a b )
(foreach y l
(if (< y x)
(setq a (cons y a))
(setq b (cons y b))
)
)
(append (qs a) (cons x (qs b)))
)
)
)
Nice job Lee 8)
Code - Auto/Visual Lisp: [Select]
Code - Auto/Visual Lisp: [Select]
The idea of this is to function as acad_strlsort ?
Just asking because the foreach and the recursion part confuses me. :thinking:
It's an implementation of the Quicksort algorithm (i.e. a Vanilla equivalent to vl-sort), with the first item of the list selected as the pivot.
The function may be easily modified to accept an arbitrary comparison function, e.g.:Code - Auto/Visual Lisp: [Select]
_$ (qs '(5 6 2 4 1 7 3 8) '<) (1 2 3 4 5 6 7 8) _$ (qs '(5 6 2 4 1 7 3 8) '>) (8 7 6 5 4 3 2 1)
It's an implementation of the Quicksort algorithm (i.e. a Vanilla equivalent to vl-sort), with the first item of the list selected as the pivot.
The function may be easily modified to accept an arbitrary comparison function, e.g.:Code - Auto/Visual Lisp: [Select]
_$ (qs '(5 6 2 4 1 7 3 8) '<) (1 2 3 4 5 6 7 8) _$ (qs '(5 6 2 4 1 7 3 8) '>) (8 7 6 5 4 3 2 1)
Very impressive function, especially when you must deal only with vanilla lisp!
Thanks - though of course, Quicksort is only one possible sorting algorithm - you might be interested in this thread (https://www.theswamp.org/index.php?topic=38292.0). :-)