Author Topic: Auditing a list of numerical string atoms  (Read 5243 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Auditing a list of numerical string atoms
« Reply #15 on: April 01, 2017, 08:50:26 AM »
Nice job Lee  8)

Thanks Alan - you too  :-)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Auditing a list of numerical string atoms
« Reply #16 on: April 01, 2017, 11:14:22 AM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun AuditList (lst / doneLst dubLst i invLst misLst)
  2.   (foreach itm lst
  3.     (cond
  4.       ((wcmatch itm "*[~0-9]*")
  5.         (if (not (member itm invLst)) (setq invLst (cons itm invLst)))
  6.       )
  7.       ((member (setq itm (atoi itm)) doneLst)
  8.         (if (not (member itm dubLst)) (setq dubLst (cons itm dubLst)))
  9.       )
  10.       (T
  11.         (setq doneLst (cons itm doneLst))
  12.       )
  13.     )
  14.   )
  15.   (repeat (- (apply 'max doneLst) (setq i (apply 'min doneLst)) 1)
  16.     (if (not (member (setq i (1+ i)) doneLst))
  17.       (setq misLst (cons i misLst))
  18.     )
  19.   )
  20.   (list
  21.     invLst ; Invalid.
  22.     dubLst ; Duplicate.
  23.     misLst ; Missing.
  24.   )
  25. )
« Last Edit: April 01, 2017, 11:23:53 AM by roy_043 »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Auditing a list of numerical string atoms
« Reply #17 on: April 01, 2017, 02:01:55 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun qs ( l )
  2.     (   (lambda ( f ) (if l (f (car l) (cdr l))))
  3.         (lambda ( x l / a b )
  4.             (foreach y l
  5.                 (if (< y x)
  6.                     (setq a (cons y a))
  7.                     (setq b (cons y b))
  8.                 )
  9.             )
  10.             (append (qs a) (cons x (qs b)))
  11.         )
  12.     )
  13. )

The idea of this is to function as acad_strlsort ?
Just asking because the foreach and the recursion part confuses me.  :thinking:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Auditing a list of numerical string atoms
« Reply #18 on: April 01, 2017, 02:16:34 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun qs ( l )
  2.     (   (lambda ( f ) (if l (f (car l) (cdr l))))
  3.         (lambda ( x l / a b )
  4.             (foreach y l
  5.                 (if (< y x)
  6.                     (setq a (cons y a))
  7.                     (setq b (cons y b))
  8.                 )
  9.             )
  10.             (append (qs a) (cons x (qs b)))
  11.         )
  12.     )
  13. )

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]
  1. (defun qs ( l c )
  2.     (   (lambda ( f ) (if l (f c (car l) (cdr l))))
  3.         (lambda ( c x l / a b )
  4.             (foreach y l
  5.                 (if (apply c (list y x))
  6.                     (setq a (cons y a))
  7.                     (setq b (cons y b))
  8.                 )
  9.             )
  10.             (append (qs a c) (cons x (qs b c)))
  11.         )
  12.     )
  13. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (qs '(5 6 2 4 1 7 3 8) '<)
  2. (1 2 3 4 5 6 7 8)
  3. _$ (qs '(5 6 2 4 1 7 3 8) '>)
  4. (8 7 6 5 4 3 2 1)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Auditing a list of numerical string atoms
« Reply #19 on: April 01, 2017, 02:32:33 PM »
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]
  1. _$ (qs '(5 6 2 4 1 7 3 8) '<)
  2. (1 2 3 4 5 6 7 8)
  3. _$ (qs '(5 6 2 4 1 7 3 8) '>)
  4. (8 7 6 5 4 3 2 1)

Very impressive function, especially when you must deal only with vanilla lisp!
Would be very handy for David, if he defuns it as vl-sort. :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Auditing a list of numerical string atoms
« Reply #20 on: April 01, 2017, 02:37:50 PM »
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]
  1. _$ (qs '(5 6 2 4 1 7 3 8) '<)
  2. (1 2 3 4 5 6 7 8)
  3. _$ (qs '(5 6 2 4 1 7 3 8) '>)
  4. (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:-)

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Auditing a list of numerical string atoms
« Reply #21 on: April 01, 2017, 03:16:03 PM »
Thanks - though of course, Quicksort is only one possible sorting algorithm - you might be interested in this thread:-)

Thanks Lee, I've seen that thread before - but nothing similair like the function you wrote here.
Although the algorithm might be the same, for me it looks completely different (atleast comparing to the Gile's quicksort).

:)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Auditing a list of numerical string atoms
« Reply #22 on: April 01, 2017, 04:40:55 PM »
What I really like about this kind of problems is that it makes one think :idiot2:


Without a sorting or recursive

Code - Text: [Select]
  1. (defun db:anum (nl / il minn maxn i ml dl bl gl fl)
  2. ;;;GOOD AND BAD LISTS
  3.   (foreach a nl
  4.      (if (wcmatch a "*[~0-9]*")
  5.          (setq bl (cons a bl))
  6.          (setq gl (cons a gl))))
  7.  
  8.   (setq il (mapcar 'atoi gl)
  9.       minn (apply 'min il)
  10.       maxn (apply 'max il)
  11.          i minn)
  12.  
  13.   (repeat (1+ (- maxn minn))
  14.       (setq fl (cons (list i 0) fl))
  15.       (setq i (1+ i)))
  16.  
  17.   (foreach n il
  18.     (if (assoc n fl)
  19.         (setq fl (subst (list n (1+ (cadr (assoc n fl))))
  20.                         (assoc n fl) fl))))
  21.  
  22.   (foreach n fl
  23.     (cond ((= 1 (cadr n)))
  24.           ((= 0 (cadr n)) (setq ml (cons (car n) ml)))
  25.           ((< 1 (cadr n)) (setq dl (cons (car n) dl)))))
  26.  
  27.   (princ "\nFull List : \t")(prin1 fl)
  28.   (princ "\nDuplicate : \t")(prin1 dl)
  29.   (princ "\n  Missing : \t")(prin1 ml)
  30.   (princ "\n      Bad : \t")(prin1 bl)
  31.   (prin1))
  32.  

I'll have to noddle on the rest of variations.  Thanks to all !  -David
R12 Dos - A2K