Author Topic: ( Challenge ) Shortest & Longest line  (Read 12215 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
( Challenge ) Shortest & Longest line
« on: January 30, 2013, 12:31:06 PM »
EXPERIENCED CODERS PLEASE WAIT AT LEAST 24 HOURS BEFORE POSTING YOUR CODE. THANKS

Ok, here is the challenge. The attached file has thousands of lines in it. Your challenge is to write a program that will return the shortest and longest lines in the attached file and erase the others. Bonus points for the fastest program and breaking it down by layers.

Have fun! :)

Thanks to Lee Mac for providing the code that created the file. :)
TheSwamp.org  (serving the CAD community since 2003)

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: ( Challenge ) Shortest & Longest line
« Reply #1 on: January 30, 2013, 01:05:42 PM »
Hi .

I am not experienced coder yet , so I am more than happy to be the first one to give a try on it .  :-)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ ss i e sn lst sh lo j)
  2.   ;;; Tharwat 30. Jan. 2013 ;;;
  3.   (if (setq ss (ssget "_x" '((0 . "LINE"))))
  4.     (progn
  5.       (repeat (setq i (sslength ss))
  6.         (setq e (entget (setq sn (ssname ss (setq i (1- i))))))
  7.         (setq lst
  8.                (vl-list*
  9.                  (list (distance (cdr (assoc 10 e)) (cdr (assoc 11 e))) sn)
  10.                  lst
  11.                )
  12.         )
  13.       )
  14.       (setq lst (vl-sort lst '(lambda (a b) (< (car a) (car b)))))
  15.       (setq sh (cadr lst)
  16.             lo (cadr (last lst))
  17.             j  0
  18.       )
  19.       (repeat (- (length lst) 2)
  20.         (entdel (cadr (nth (setq j (1+ j)) lst)))
  21.       )
  22.     )
  23.   )
  24.   (princ)
  25. )
  26.  
  27.  

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: ( Challenge ) Shortest & Longest line
« Reply #2 on: January 30, 2013, 01:19:57 PM »
Nice job Tharwat!
TheSwamp.org  (serving the CAD community since 2003)

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: ( Challenge ) Shortest & Longest line
« Reply #3 on: January 30, 2013, 01:27:16 PM »
Nice job Tharwat!

Thank you Mark .  :-)

I have two extra variables ( sh , lo) that should be removed since There is no need of them .

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #4 on: January 30, 2013, 03:38:57 PM »
Here is a short & simple timing function so that we may compare challenge entries  :-)

Code: [Select]
(defun time-it ( expr / et st )
    (setq st (getvar 'millisecs))
    (eval expr)
    (setq et (getvar 'millisecs))
    (princ (strcat "\nProgram running time: " (itoa (- et st)) " msecs."))
    (princ)
)

Call with quoted expression:
Code: [Select]
(time-it '(c:test))
Thanks for the nod Mark :-)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: ( Challenge ) Shortest & Longest line
« Reply #5 on: January 30, 2013, 03:41:42 PM »
Here is a short & simple timing function so that we may compare challenge entries  :-)
Thanks Lee. I was just going to ask ... :)
TheSwamp.org  (serving the CAD community since 2003)

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ( Challenge ) Shortest & Longest line
« Reply #6 on: January 30, 2013, 03:42:43 PM »
I think I'd be too arrogant to cosider myself an experienced coder, so here is my code:
Code - Auto/Visual Lisp: [Select]
  1. (defun C:MinMaxLine ( / d ss i l e m n tm)
  2.   (defun d (e / en)
  3.     (distance
  4.       (cdr (assoc 10 (setq en (entget e))))
  5.       (cdr (assoc 11 en)))
  6.     )
  7. ;;;  (setq tm (getvar 'millisecs))
  8.   (if
  9.     (setq ss (ssget "_X" '((0 . "LINE"))))
  10.     (progn
  11.       (setq e (ssname ss 0)
  12.             m (list (d e) e)
  13.             n m
  14.             )
  15.       (repeat (setq i (sslength ss))
  16.         (setq e (ssname ss (setq i (1- i)))
  17.               l (d e)
  18.               )
  19.         (if (< l (car m)) (setq m (list l e)))
  20.         (if (> l (car n)) (setq n (list l e)))
  21.         (entdel e)
  22.         )
  23.       (entdel (cadr m))
  24.       (entdel (cadr n))
  25.       (print (list (car m) (car n)))
  26.       )
  27.     )
  28. ;;;  (print (- (getvar 'millisecs) tm))
  29.   (princ)
  30.   )

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #7 on: January 30, 2013, 03:47:23 PM »
I think I'd be too arrogant to cosider myself an experienced coder

I think you give yourself too little credit  :-)
Very good solution using an 'unerase'

LE3

  • Guest
Re: ( Challenge ) Shortest & Longest line
« Reply #8 on: January 30, 2013, 03:59:35 PM »
... something simple in c#:
Code: [Select]
[CommandMethod("SHOLON")]
public void cmd_shortestLongestLines()
{
    var e = AcadApp.DocumentManager.MdiActiveDocument.Editor;
    TypedValue[] tv = { new TypedValue((int)DxfCode.Start, "LINE") };
    var filter = new SelectionFilter(tv);
    var options = new PromptSelectionOptions
    {
        MessageForAdding = "\nAdd lines to selection",
        MessageForRemoval = "\nRemove lines from selection",
        AllowDuplicates = false,
        RejectObjectsFromNonCurrentSpace = true
    };
    var psr = e.GetSelection(options, filter);
    if (psr.Status != PromptStatus.OK) return;
    var sw = new Stopwatch();
    var pairs = new SortedList<double, ObjectId>();
    using (var tr = e.Document.Database.TransactionManager.StartTransaction())
    {
        sw.Start();
        foreach (var id in psr.Value.GetObjectIds())
        {
            var line = tr.GetObject(id, OpenMode.ForRead) as Line;
            if (line != null)
            {
                pairs.Add(line.Length, id);
            }
        }
        pairs.RemoveAt(0);
        pairs.RemoveAt(pairs.Count - 1);
        foreach (var pair in pairs)
        {
            tr.GetObject(pair.Value, OpenMode.ForWrite).Erase();
        }
        sw.Stop();
        tr.Commit();
    }
    e.WriteMessage("\nElapsed.TotalMilliseconds={0} \n", sw.Elapsed.TotalMilliseconds);
}
Elapsed.TotalMilliseconds=1320.1172
« Last Edit: February 06, 2013, 03:47:13 PM by LE »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ( Challenge ) Shortest & Longest line
« Reply #9 on: January 30, 2013, 04:59:15 PM »
I think I'd be too arrogant to cosider myself an experienced coder

...
Very good solution using an 'unerase'

Beat me to it .. that was in my solution too  :-(  ... when can I play?  :lmao:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

kruuger

  • Swamp Rat
  • Posts: 635
Re: ( Challenge ) Shortest & Longest line
« Reply #10 on: January 30, 2013, 07:23:55 PM »
vla approach:
Code: [Select]
(defun c:KRU (/ res)
  (ssget "_x" '((0 . "LINE")))
  (vlax-for %
    (vla-get-activeselectionset
      (vla-get-activedocument
        (vlax-get-acad-object)
      )
    )
    (setq res (cons (list (vla-get-length %) %) res))
    (if (> (length res) 2)
      (progn
        (setq res
          (vl-sort res
            (function
              (lambda (%1 %2)
                (< (car %1) (car %2))
              )
            )
          )
        )
        (vla-delete (cadadr res))
        (setq res (list (car res) (last res)))
      )
    )
  )
  (list
    (cons (caar res) (vla-get-layer (cadar res)))
    (cons (caadr res) (vla-get-layer (cadadr res)))
  )
)

EDIT: revised to return
Code: [Select]
((19.6269 . "CYAN") (1528.89 . "GREEN"))
« Last Edit: January 31, 2013, 04:45:05 AM by kruuger »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Shortest & Longest line
« Reply #11 on: January 30, 2013, 11:57:46 PM »
Great challenge Mark.
Thanks for the timer Lee.

Code: [Select]
TIME-IT
((BLUE 20.1582 1442.59 <Entity name: 7d3ad5e8>) (CYAN 19.6269 1468.04 <Entity name: 7d3b2240>) (GREEN 20.9117 1528.89 <Entity name: 7d3a07b0>) (RED 20.5474 1504.13 <Entity name: 7d3a5ba8>))
Program running time: 702 msecs.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ( Challenge ) Shortest & Longest line
« Reply #12 on: January 31, 2013, 01:22:24 AM »
Great challenge Mark.
Thanks for the timer Lee.

Code: [Select]
TIME-IT
((BLUE 20.1582 1442.59 <Entity name: 7d3ad5e8>) (CYAN 19.6269 1468.04 <Entity name: 7d3b2240>) (GREEN 20.9117 1528.89 <Entity name: 7d3a07b0>) (RED 20.5474 1504.13 <Entity name: 7d3a5ba8>))
Program running time: 702 msecs.


wow .. really? maybe I just have a slow computer ... mine runs about 3600 msecs
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #13 on: January 31, 2013, 03:35:28 AM »
My version:
Code - Auto/Visual Lisp: [Select]
  1. (defun C:ShortLongest ( / SelSet Countr EntSht EntLng LenVal MaxLen MinLen)
  2.   (defun Dxf (DxfCod EntDat)  (cdr (assoc DxfCod EntDat)))
  3.   (if (setq SelSet (ssget "_X" '((0 . "LINE"))))
  4.     (progn
  5.       (setvar "HIGHLIGHT" 0)
  6.       (setq
  7.         Countr 0
  8.         EntSht (ssname SelSet 0)
  9.         EntLng EntSht
  10.         EntDat (entget EntSht)
  11.         MaxLen (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  12.         MinLen  MaxLen
  13.       )
  14.       (repeat (sslength SelSet)
  15.         (setq
  16.           EntNam (ssname SelSet Countr) EntDat (entget EntNam)
  17.           LenVal (distance (Dxf 10 EntDat) (Dxf 10 EntDat))
  18.           Countr (1+ Countr)
  19.         )
  20.         (cond
  21.           ( (> LenVal MaxLen) (setq MaxLen LenVal  EntLng EntNam) )
  22.           ( (< LenVal MinLen) (setq MinLen LenVal  EntSht EntNam) )
  23.         )
  24.       )
  25.       (command "_.ERASE" SelSet "_R" (ssadd EntSht (ssadd EntLng)) "")
  26. ;      (princ (strcat "\n" (itoa Countr) " erased entity(es). Use Oops to restore. "))
  27.       (setvar "HIGHLIGHT" 1)
  28.     )
  29.     (alert "No lines to erase.")
  30.   )
  31. )

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: ( Challenge ) Shortest & Longest line
« Reply #14 on: January 31, 2013, 04:24:47 AM »
This is off-topic, but if I run TEST-TIMES twice, I get 2 different results... Can someone explain :

Code: [Select]
(defun time-it ( expr msg / et st )
    (setq st (getvar 'millisecs))
    (eval expr)
    (setq et (getvar 'millisecs))
    (princ (strcat msg (itoa (- et st)) " msecs."))
    (princ)
)

(defun dst (p1 p2 / v)
    (setq v (mapcar '- p2 p1))
    (sqrt (+ (expt (car v) 2) (expt (cadr v) 2) (expt (caddr v) 2)))
)

(defun makelst ( / k l1 l2 )
    (setq k 0.0)
    (repeat 20000
        (setq l1 (append l1 (setq l1 (list (1+ k)))))
    )
    (setq l2 (reverse l1))
    (setq ptlst (mapcar '(lambda (a b c) (list a b c)) l1 l1 l2))
)

(defun testdst ( ptlst )
    (mapcar '(lambda (a b) (dst a b)) ptlst (cdr ptlst))
)

(defun testdistance ( ptlst )
    (mapcar '(lambda (a b) (distance a b)) ptlst (cdr ptlst))
)

(defun c:test-times ( / ptlst )
    (makelst)
    (time-it '(testdst ptlst) "\n\"Dst\" function running time: ")
    (time-it '(testdistance ptlst) "\n\"Distance\" LISP function running time: ")
    (textscr)
    (princ)
)

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ( Challenge ) Shortest & Longest line
« Reply #15 on: January 31, 2013, 04:36:12 AM »
I have two more functions for all lines and one that consider layers.
Here is the test function:
Code: [Select]
(defun C:TEST ( / acDoc cm)
  (setq cm (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (foreach fun '((ph:byLayer) (ph:all1) (ph:all2))
    (vla-StartUndoMark acDoc)
    (gc)
    (time-it fun)
    (vla-EndUndoMark acDoc)
    (command "U")
    )
  (setvar 'cmdecho cm)
  (textscr)
  (princ)
  )

(defun time-it ( expr / et st )
    (setq st (getvar 'millisecs))
    (eval expr)
    (setq et (getvar 'millisecs))
    (princ (strcat "\nProgram running time: " (vl-princ-to-string expr) " - " (itoa (- et st)) " msecs."))
    (princ)
)
And results
Code: [Select]
Command:  TEST
("CYAN" 19.6269 1468.04)
("RED" 20.5474 1504.13)
("BLUE" 20.1582 1442.59)
("GREEN" 20.9117 1528.89)
Program running time: (PH:BYLAYER) - 765 msecs.
(19.6269 1528.89)
Program running time: (PH:ALL1) - 625 msecs.
(19.6269 1528.89)
Program running time: (PH:ALL2) - 672 msecs.

Command:  TEST
("CYAN" 19.6269 1468.04)
("RED" 20.5474 1504.13)
("BLUE" 20.1582 1442.59)
("GREEN" 20.9117 1528.89)
Program running time: (PH:BYLAYER) - 875 msecs.
(19.6269 1528.89)
Program running time: (PH:ALL1) - 547 msecs.
(19.6269 1528.89)
Program running time: (PH:ALL2) - 563 msecs.

Command:  TEST
("CYAN" 19.6269 1468.04)
("RED" 20.5474 1504.13)
("BLUE" 20.1582 1442.59)
("GREEN" 20.9117 1528.89)
Program running time: (PH:BYLAYER) - 875 msecs.
(19.6269 1528.89)
Program running time: (PH:ALL1) - 531 msecs.
(19.6269 1528.89)
Program running time: (PH:ALL2) - 562 msecs.
I've run the test several times with contradictory results. For example, for the first function the running time was in range 703... 1265 ms.
The results above are the most homogenous 3 consecutive tests.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #16 on: January 31, 2013, 06:00:53 AM »
With layers...
Code - Auto/Visual Lisp: [Select]
  1. (defun C:ShortLongestByLyr ( / TblDat)
  2.   (defun Dxf (DxfCod EntDat)  (cdr (assoc DxfCod EntDat)))
  3.   (defun ShortLongestLyr (LyrNam / SelSet  Countr EntSht EntLng EntDat EntNam LenVal MaxLen MinLen)
  4.     (if (setq SelSet (ssget "_X" (list '(0 . "LINE") (cons 8 LyrNam))))
  5.       (progn
  6.         (setq
  7.           Countr 0
  8.           EntSht (ssname SelSet 0)
  9.           EntLng EntSht
  10.           EntDat (entget EntSht)
  11.           MaxLen (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  12.           MinLen  MaxLen
  13.         )
  14.         (repeat (sslength SelSet)
  15.           (setq
  16.             EntNam (ssname SelSet Countr) EntDat (entget EntNam)
  17.             LenVal (distance (Dxf 10 EntDat) (Dxf 10 EntDat))
  18.             Countr (1+ Countr)
  19.           )
  20.           (cond
  21.             ( (> LenVal MaxLen) (setq MaxLen LenVal  EntLng EntNam) )
  22.             ( (< LenVal MinLen) (setq MinLen LenVal  EntSht EntNam) )
  23.           )
  24.         )
  25.         (command "_.ERASE" SelSet "_R" (ssadd EntSht (ssadd EntLng)) "")
  26. ;       (princ (strcat "\nLayer: " LyrNam " > " (itoa Countr) " erased entity(es). "))
  27.       )
  28. ;     (alert "No lines to erase.")
  29.     )
  30.   )
  31.   (setvar "HIGHLIGHT" 0)
  32.   (while (setq TblDat (tblnext "LAYER" (null TblDat)))
  33.     (ShortLongestLyr (cdr (assoc 2 TblDat)))
  34.   )
  35.   (setvar "HIGHLIGHT" 1)
  36. )

pBe

  • Bull Frog
  • Posts: 402
Re: ( Challenge ) Shortest & Longest line
« Reply #17 on: January 31, 2013, 06:09:40 AM »
Very good solution using an 'unerase'
x2  :)
 

David Bethel

  • Swamp Rat
  • Posts: 656
Re: ( Challenge ) Shortest & Longest line
« Reply #18 on: January 31, 2013, 07:44:16 AM »
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #19 on: January 31, 2013, 07:46:27 AM »
This was my original version:

Code: [Select]
(defun LM:shortlong ( / _max _min d e i l r s )
    (if (setq s (ssget "_X" '((0 . "LINE"))))
        (progn
            (setq _min 1e308
                  _max 0.0
            )
            (repeat (setq i (sslength s))
                (setq e (ssname s (setq i (1- i)))
                      l (entget e)
                      d (distance (cdr (assoc 10 l)) (cdr (assoc 11 l)))
                )
                (if (< _min d _max)
                    (entdel e)
                    (progn
                        (if (< d _min) (setq _min d))
                        (if (< _max d) (setq _max d))
                        (setq r (cons (list d e) r))
                    )
                )
            )
            (foreach x r
                (or (equal  (car  x) _min 1e-8)
                    (equal  (car  x) _max 1e-8)
                    (entdel (cadr x))
                )
            )
        )
    )
    (list _min _max)
)

But using Stefan's 'unerase' trick, I would change it to:

Code: [Select]
(defun LM:shortlong2 ( / _max _min d e i l m n r s )
    (if (setq s (ssget "_X" '((0 . "LINE"))))
        (progn
            (setq _min 1e308
                  _max 0.0
            )
            (repeat (setq i (sslength s))
                (setq e (ssname s (setq i (1- i)))
                      l (entget e)
                      d (distance (cdr (assoc 10 l)) (cdr (assoc 11 l)))
                )
                (if (< d _min) (setq _min d m e))
                (if (< _max d) (setq _max d n e))
                (entdel e)
            )
            (entdel m)
            (entdel n)
        )
    )
    (list _min _max)
)

Regarding the times, I must have a slow computer - I don't get much below 1800ms...
« Last Edit: January 31, 2013, 07:58:46 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #20 on: January 31, 2013, 07:58:35 AM »
Here are my times for the programs posted so far, comparing those returning overall shortest/longest lines:

Code: [Select]
(LM:SHORTLONG2) running time:  1732 msecs.
(LM:SHORTLONG)  running time:  1779 msecs.
(PH:MINMAXLINE) running time:  1857 msecs.
(C:KRU)         running time:  8487 msecs.
(THARWAT:TEST)  running time: 11061 msecs.

c:shortlongest by Marc'Antonio Alessi didn't return the correct result, so I didn't compare it.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: ( Challenge ) Shortest & Longest line
« Reply #21 on: January 31, 2013, 08:02:09 AM »
OMG , mine is the slowest !  :-(

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ( Challenge ) Shortest & Longest line
« Reply #22 on: January 31, 2013, 08:11:12 AM »
My second version
Code - Auto/Visual Lisp: [Select]
  1. (defun ph:all1 (/ ss i l e e1 e2 m n)
  2.   (if
  3.     (setq ss (ssget "_X" '((0 . "LINE"))))
  4.      (progn
  5.        (setq e (ssname ss 0)
  6.              e1 e e2 e
  7.              m (vlax-curve-GetEndParam e)
  8.              n m
  9.              )
  10.        (repeat (setq i (sslength ss))
  11.          (setq l (vlax-curve-GetEndParam (setq e (ssname ss (setq i (1- i))))))
  12.          (if (< l m) (setq m l e1 e))
  13.          (if (> l n) (setq n l e2 e))
  14.          )
  15.        (command "ERASE" ss "")
  16.        (entdel e1)
  17.        (entdel e2)
  18.        (list m n)
  19.        )
  20.      )
  21.   )

David Bethel

  • Swamp Rat
  • Posts: 656
Re: ( Challenge ) Shortest & Longest line
« Reply #23 on: January 31, 2013, 08:13:15 AM »
A more basic approach:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:lines (/ var rst td ln mn mx el es ss i en ed d1)
  2.  
  3.  (setq var '(("CMDECHO"   . 0) ("MENUECHO"   . 0)
  4.              ("MENUCTL"   . 0) ("MACROTRACE" . 0)
  5.              ("OSMODE"    . 0) ("SORTENTS"   . 0)
  6.              ("BLIPMODE"  . 0) ("SNAPMODE"   . 0)
  7.              ("HIGHLIGHT" . 0) ("MODEMACRO" . ".")))
  8.  
  9.  (foreach v var
  10.    (and (getvar (car v))
  11.         (setq rst (cons (cons (car v) (getvar (car v))) rst))
  12.         (setvar (car v) (cdr v))))
  13.  
  14.  (while (setq td (tblnext "LAYER" (not td)))
  15.         (setq ln (cdr (assoc 2 td))
  16.               mn nil)
  17.         (if (setq ss (ssget "X" (list (cons 0 "LINE")(cons 8 ln))))
  18.             (progn
  19.                (princ (strcat "\nProcessing " ln))
  20.                (setq i -1)
  21.                (while (setq en (ssname ss (setq i (1+ i))))
  22.                       (setq ed (entget en)
  23.                             d1 (distance (cdr (assoc 10 ed))
  24.                                          (cdr (assoc 11 ed))))
  25.                       (cond ((not mn)
  26.                              (setq mn d1 mx d1 el en es en))
  27.                             ((> d1 mx)
  28.                              (setq mx d1 el en))
  29.                             ((< d1 mn)
  30.                              (setq mn d1 es en))))
  31.                (setq ss (ssdel el ss)
  32.                      ss (ssdel es ss))
  33.                (command "_.ERASE" ss ""))))
  34.  
  35.  (foreach v rst (setvar (car v) (cdr v)))
  36.  (redraw)
  37.  (prin1))
-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #24 on: January 31, 2013, 08:34:55 AM »
New times, including ph:all1 (I have not included David Bethel's code, since it processes layer-by-layer and hence would not be comparing apples with apples):

Code: [Select]
(PH:ALL1)       running time:  702 msecs.
(LM:SHORTLONG)  running time: 1809 msecs.
(LM:SHORTLONG2) running time: 1872 msecs.
(PH:MINMAXLINE) running time: 1950 msecs.
(C:KRU)         running time: 8767 msecs.
(THARWAT:TEST)  running time: 9999 msecs.

Bravo Stefan!  :-)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #25 on: January 31, 2013, 08:36:03 AM »
c:shortlongest by Marc'Antonio Alessi didn't return the correct result, so I didn't compare it.

Yes, was a typo:  (Dxf 10 EntDat) (Dxf 11 EntDat))

Code - Auto/Visual Lisp: [Select]
  1. (defun C:ShortLongest ( / SelSet Countr EntSht EntLng LenVal MaxLen MinLen)
  2.  (defun Dxf (DxfCod EntDat)  (cdr (assoc DxfCod EntDat)))
  3.  (if (setq SelSet (ssget "_X" '((0 . "LINE"))))
  4.    (progn
  5.      (if (= 1 (logand 1 (getvar "UNDOCTL"))) (command "_.UNDO" "_C" "_N"))
  6.      (setvar "HIGHLIGHT" 0)
  7.      (setq
  8.        Countr 0
  9.        EntSht (ssname SelSet 0)
  10.        EntLng EntSht
  11.        EntDat (entget EntSht)
  12.        MaxLen (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  13.        MinLen  MaxLen
  14.      )
  15.      (repeat (sslength SelSet)
  16.        (setq
  17.          EntNam (ssname SelSet Countr) EntDat (entget EntNam)
  18.          LenVal (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  19.          Countr (1+ Countr)
  20.        )
  21.        (cond
  22.          ( (> LenVal MaxLen) (setq MaxLen LenVal  EntLng EntNam) )
  23.          ( (< LenVal MinLen) (setq MinLen LenVal  EntSht EntNam) )
  24.        )
  25.      )
  26.      (command "_.ERASE" SelSet "_R" (ssadd EntSht (ssadd EntLng)) "")
  27. ;      (princ (strcat "\n" (itoa Countr) " erased entity(es). Use Oops to restore. "))
  28.      (setvar "HIGHLIGHT" 1)
  29.    )
  30.    (alert "No lines to erase.")
  31.  )
  32. )
  33. (defun C:ShortLongestByLyr ( / TblDat)
  34.   (defun Dxf (DxfCod EntDat)  (cdr (assoc DxfCod EntDat)))
  35.   (defun ShortLongestLyr (LyrNam / SelSet  Countr EntSht EntLng EntDat EntNam LenVal MaxLen MinLen)
  36.     (if (setq SelSet (ssget "_X" (list '(0 . "LINE") (cons 8 LyrNam))))
  37.       (progn
  38.         (setq
  39.           Countr 0
  40.           EntSht (ssname SelSet 0)
  41.           EntLng EntSht
  42.           EntDat (entget EntSht)
  43.           MaxLen (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  44.           MinLen  MaxLen
  45.         )
  46.         (repeat (sslength SelSet)
  47.           (setq
  48.             EntNam (ssname SelSet Countr) EntDat (entget EntNam)
  49.             LenVal (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  50.             Countr (1+ Countr)
  51.           )
  52.           (cond
  53.             ( (> LenVal MaxLen) (setq MaxLen LenVal  EntLng EntNam) )
  54.             ( (< LenVal MinLen) (setq MinLen LenVal  EntSht EntNam) )
  55.           )
  56.         )
  57.         (command "_.ERASE" SelSet "_R" (ssadd EntSht (ssadd EntLng)) "")
  58. ;       (princ (strcat "\nLayer: " LyrNam " > " (itoa Countr) " erased entity(es). "))
  59.       )
  60. ;     (alert "No lines to erase.")
  61.     )
  62.   )
  63.   (if (= 1 (logand 1 (getvar "UNDOCTL"))) (command "_.UNDO" "_C" "_N"))
  64.   (setvar "HIGHLIGHT" 0)
  65.   (while (setq TblDat (tblnext "LAYER" (null TblDat)))
  66.     (ShortLongestLyr (cdr (assoc 2 TblDat)))
  67.   )
  68.   (setvar "HIGHLIGHT" 1)
  69. )

(time-it '(c:ShortLongest)) > Program running time: 3354 msecs.
(time-it '(c:ShortLongest)) > Program running time: 2964 msecs.

(time-it '(LM:shortlong2))  > Program running time: 6677 msecs.
(time-it '(LM:shortlong2))  > Program running time: 6755 msecs.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #26 on: January 31, 2013, 08:41:47 AM »
(time-it '(c:ShortLongest)) > Program running time: 3369 msecs.
(time-it '(ph:all1))              > Program running time: 5460 msecs.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #27 on: January 31, 2013, 08:47:03 AM »
With undo turned off, I get:
Code: [Select]
(PH:ALL1)        running time:  686 msecs.
(C:SHORTLONGEST) running time: 1311 msecs.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ( Challenge ) Shortest & Longest line
« Reply #28 on: January 31, 2013, 08:52:09 AM »
Here is mine:

Quote
(C:TEST3) Program running time: 2140 msecs.

(("RED" <Entity name: 7f62825c520> <Entity name: 7f628264750>)
  ("GREEN" <Entity name: 7f6292e9210> <Entity name: 7f628207f60>)
  ("CYAN" <Entity name: 7f62eaf6480> <Entity name: 7f62eade230>)
  ("BLUE" <Entity name: 7f62770cbd0> <Entity name: 7f62b641330>)
)


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Shortest & Longest line
« Reply #29 on: January 31, 2013, 08:57:38 AM »
Wow you'll have busy this morning.  :-)
My offering.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:CABtest(/ ss i ent elst lst len lay)
  2.   (and (setq ss (ssget "_X" '((0 . "LINE"))))
  3.        (setq i -1)
  4.        (while (setq ent (ssname ss (setq i (1+ i))))
  5.          (setq elst (entget ent)
  6.                len (distance (cdr (assoc 10 elst))(cdr (assoc 11 elst)))
  7.                lay (cdr (assoc 8 elst)))
  8.          (cond
  9.            ((null lst)(setq lst (list(list lay len len ent ent))))
  10.            ((setq itm (assoc lay lst))
  11.             (if (or (if (< len (cadr itm)) (setq itm (list lay len (caddr itm) ent (last itm))))
  12.                     (if (> len (caddr itm)) (setq itm (list lay (cadr itm) len (cadddr itm) ent))))
  13.               (setq lst (subst itm (assoc lay lst) lst))))
  14.            ((setq lst (cons (list lay len len ent ent) lst)))
  15.          )
  16.        )
  17.    )
  18.   (mapcar(function(lambda(x) (ssdel (last x) ss))) lst)
  19.   (and lst (command "_.erase" ss ""))
  20.   (print)(princ lst)(princ)
  21. )
« Last Edit: January 31, 2013, 10:36:34 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #30 on: January 31, 2013, 09:15:04 AM »
With undo turned off, I get:
Code: [Select]
(PH:ALL1)        running time:  686 msecs.
(C:SHORTLONGEST) running time: 1311 msecs.

weird, I also tried the newly opened dwg...

Comando: _U
Comando A disattivato. Utilizzare il comando ANNULLA per attivarlo

Comando: (time-it '(ph:all1)) Program running time: 4181 msecs.

Comando: (time-it '(c:ShortLongest))Program running time: 2745 msecs.



Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ( Challenge ) Shortest & Longest line
« Reply #31 on: January 31, 2013, 09:19:00 AM »
I found during my tests that if I did many tests in quick succession, they became increasingly slower, what once took a mere 1800ms was taking over 60000ms and it got progressively 30-50% slower with each run .. until I closed the drawing and reopened it.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #32 on: January 31, 2013, 09:32:32 AM »
I found during my tests that if I did many tests in quick succession, they became increasingly slower, what once took a mere 1800ms was taking over 60000ms and it got progressively 30-50% slower with each run .. until I closed the drawing and reopened it.
Yes, is better to reopen DWG.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #33 on: January 31, 2013, 09:35:51 AM »
Wow you'll have busy this morning.  :-)

...here we have a lot of work to do...  :cry:

;(time-it '(c:CAB:test))                  > Program running time: 5617 msecs.
;(time-it '(c:ShortLongestByLyr))  > Program running time: 5600 msecs.

Try better your version because I get only 4 lines...


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Shortest & Longest line
« Reply #34 on: January 31, 2013, 10:37:09 AM »
You're quite right, code updated.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

LE3

  • Guest
Re: ( Challenge ) Shortest & Longest line
« Reply #35 on: January 31, 2013, 11:30:36 AM »
was just able to get: Elapsed.TotalMilliseconds=1320.1172 - using c#, see my previous post earlier, including the source.

or by doing an small change: Elapsed.TotalMilliseconds=1265.0109

Code: [Select]
        [CommandMethod("SHOLON")]         
public void cmd_shortestLongestLines()
        {
            var e = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            TypedValue[] tv = { new TypedValue((int)DxfCode.Start, "LINE") };
            var filter = new SelectionFilter(tv);
            var options = new PromptSelectionOptions
            {
                MessageForAdding = "\nAdd lines to selection",
                MessageForRemoval = "\nRemove lines from selection",
                AllowDuplicates = false,
                RejectObjectsFromNonCurrentSpace = true
            };
            var psr = e.GetSelection(options, filter);
            if (psr.Status != PromptStatus.OK) return;
            var sw = new Stopwatch();
            var pairs = new SortedList<double, Line>();
            using (var tr = e.Document.Database.TransactionManager.StartTransaction())
            {
                sw.Start();
                foreach (var id in psr.Value.GetObjectIds())
                {
                    var line = tr.GetObject(id, OpenMode.ForRead) as Line;
                    if (line != null)
                    {
                        pairs.Add(line.Length, line);
                    }
                }
                pairs.RemoveAt(0);
                pairs.RemoveAt(pairs.Count - 1);
                foreach (var pair in pairs)
                {
                    pair.Value.UpgradeOpen();
                    pair.Value.Erase();
                    //tr.GetObject(pair.Value, OpenMode.ForWrite).Erase();
                }
                sw.Stop();
                tr.Commit();
            }
            e.WriteMessage("\nElapsed.TotalMilliseconds={0} \n", sw.Elapsed.TotalMilliseconds);
        }

ok... playmode it is off. have fun!

Here it is a much better performance:

Quote
Command: sholon
Add lines to selection: Specify opposite corner: 38608 found
Add lines to selection:
Elapsed=364msecs short19.6269346852711long1528.88882854822

Code: [Select]
        [CommandMethod("SHOLON")]
        public void cmd_shortestLongestLines()
        {
            var e = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            TypedValue[] tv = { new TypedValue((int)DxfCode.Start, "LINE") };
            var filter = new SelectionFilter(tv);
            var options = new PromptSelectionOptions
            {
                MessageForAdding = "\nAdd lines to selection",
                MessageForRemoval = "\nRemove lines from selection",
                AllowDuplicates = false,
                RejectObjectsFromNonCurrentSpace = true
            };
            var psr = e.GetSelection(options, filter);
            if (psr.Status != PromptStatus.OK) return;
            var sw = new Stopwatch();
            var pairs = new Dictionary<double, Line>();
            KeyValuePair<double, Line> longestLine;
            KeyValuePair<double, Line> shortestLine;
            using (var tr = e.Document.Database.TransactionManager.StartTransaction())
            {
                sw.Start();
                foreach (var id in psr.Value.GetObjectIds())
                {
                    var line = tr.GetObject(id, OpenMode.ForWrite) as Line;
                    pairs.Add(line.Length, line);
                    line.Erase();
                }
                longestLine = pairs.Aggregate((a, b) => b.Key > a.Key ? b : a);
                shortestLine = pairs.Aggregate((a, b) => b.Key < a.Key ? b : a);
                longestLine.Value.Erase(false);
                shortestLine.Value.Erase(false);
                sw.Stop();
                tr.Commit();
            }
            e.WriteMessage("\nElapsed={0}msecs short{1}long{2} \n", sw.ElapsedMilliseconds,
                shortestLine.Key.ToString(CultureInfo.InvariantCulture), longestLine.Key.ToString(CultureInfo.InvariantCulture));
        }
« Last Edit: February 06, 2013, 03:48:15 PM by LE »

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ( Challenge ) Shortest & Longest line
« Reply #36 on: January 31, 2013, 12:04:35 PM »
Bravo Stefan!  :-)

Thank you Lee

weird, I also tried the newly opened dwg...

Comando: _U
Comando A disattivato. Utilizzare il comando ANNULLA per attivarlo

Comando: (time-it '(ph:all1)) Program running time: 4181 msecs.

Comando: (time-it '(c:ShortLongest))Program running time: 2745 msecs.

Weird for me too...
I've made all tests on this: Pentium Dual Core, 3.0 GHz, 2Gb Ram, Autocad 11, 32bit
Then I tried on this configuration: Intel i5 ( x64), 4Gb Ram, Autocad 2012, 64bit
Code: [Select]
(LM:SHORTLONG)    running time =      1232
(LM:SHORTLONG2)   running time =      1248
(THARWAT)         running time =     11981
(PH:ALL1)         running time =     20046
vlax-curve works awful slow on i5 or is something wrong with that computer. If someone had the same results, please let me know.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ( Challenge ) Shortest & Longest line
« Reply #37 on: January 31, 2013, 12:08:38 PM »
vlax-curve works awful slow on i5 or is something wrong with that computer.

Maybe a 64-bit issue? ... I really hope not  :-(

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: ( Challenge ) Shortest & Longest line
« Reply #38 on: January 31, 2013, 12:20:17 PM »
Using Win7 64
Quote
(PH:ALL1)         running time =     390
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #39 on: January 31, 2013, 12:37:19 PM »
Quote
Weird for me too...
I've made all tests on this: Pentium Dual Core, 3.0 GHz, 2Gb Ram, Autocad 11, 32bit
Then I tried on this configuration: Intel i5 ( x64), 4Gb Ram, Autocad 2012, 64bit
Code: [Select]
(LM:SHORTLONG)    running time =      1232
(LM:SHORTLONG2)   running time =      1248
(THARWAT)         running time =     11981
(PH:ALL1)         running time =     20046
vlax-curve works awful slow on i5 or is something wrong with that computer. If someone had the same results, please let me know.

I have AutoCAD 2013 - PC not new: Dell Studio XPS - Intel Core2Duo P7450 2.13GHz 4Gb Ram - Seven 64

Here, without reopen DWG (with oops):
Comando: (time-it '(c:ShortLongest))
Program running time: 3338 msecs.
Comando: OOPS
Comando: (gc)
nil
Comando: (gc)
nil
Comando: (time-it '(ph:all1))
Program running time: 4618 msecs.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Shortest & Longest line
« Reply #40 on: January 31, 2013, 01:03:56 PM »
Using Win7 64
Quote
(PH:ALL1)         running time =     390

See my sig for comp specs. Running vanilla ACAD2006
TIME-IT
(19.6269 1528.89)
Program running time: 234 msecs.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pBe

  • Bull Frog
  • Posts: 402
Re: ( Challenge ) Shortest & Longest line
« Reply #41 on: January 31, 2013, 01:08:17 PM »

Guess we can throw in the 'Min / 'Max function in the mix


with (command "erase"...)

Code: [Select]
(defun c:Long&ShortOfIt ( / dx ls ss i e l_ s_)
(defun dx (d x)(cdr (assoc d (entget x))))
(defun Ls (m y)(list (assoc (apply m (mapcar 'car y)) y))) 
   (if (setq  ss (ssget "_x" '((0 . "LINE"))))
     (progn
         (repeat (setq i (sslength ss))
               (setq e (ssname ss (setq i (1- i)))
                              l_ (cons (list  (distance (dx 10 e )(dx 11 e)) e) l_)     
                              s_ (cons (car l_) s_))
         (setq l_ (ls 'max l_)
                 s_ (ls 'min s_))
           )
         (command "_erase" ss "")
           (entdel (cadr (car l_)))
         (entdel (cadr (car s_)))
       )
     )(princ)
  )

with entdel (entdel ....)

Code: [Select]
(defun c:Long&ShortOfItnc ( / dx ls ss i e l_ s_)
(defun dx (d x)(cdr (assoc d (entget x))))
(defun Ls (m y)(list (assoc (apply m (mapcar 'car y)) y))) 
   (if (setq  ss (ssget "_x" '((0 . "LINE"))))
     (progn
         (repeat (setq i (sslength ss))
               (setq e (ssname ss (setq i (1- i)))
                              l_ (cons (list  (distance (dx 10 e )(dx 11 e)) e) l_)     
                              s_ (cons (car l_) s_))
         (setq l_ (ls 'max l_)
               s_ (ls 'min s_))
           (entdel e)
           )
         
           (entdel (cadr (car l_)))
         (entdel (cadr (car s_)))
       )
     )(princ)
  )

« Last Edit: January 31, 2013, 10:12:35 PM by pBe »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ( Challenge ) Shortest & Longest line
« Reply #42 on: January 31, 2013, 01:08:42 PM »
(PH:ALL1) Program running time: 656 msecs.

Windows 8 X64

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #43 on: January 31, 2013, 01:17:47 PM »
...strange again, with Intel Core2Duo P7450 2.13GHz 4Gb Ram - Seven 64

AutoCAD 2013
;(time-it '(c:CAB:test))                  > Program running time: 5460 msecs.
;(time-it '(c:ShortLongestByLyr))  > Program running time: 5100 msecs.

AutoCAD 2010
;(time-it '(c:CAB:test))                  > Program running time: 2199 msecs.
;(time-it '(c:ShortLongestByLyr))  > Program running time: 1545 msecs.

pBe

  • Bull Frog
  • Posts: 402
Re: ( Challenge ) Shortest & Longest line
« Reply #44 on: January 31, 2013, 01:19:37 PM »
Try running that on this specs

Memory 1.00 GB
Intel Atom (TM) CPU N455 @1.66GHz

OS: Windows 7 Starter
CAD Version: Autocad 2009

I bet you wouldnt like what you see  ;D

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #45 on: January 31, 2013, 02:45:51 PM »
Try running that on this specs

Memory 1.00 GB
Intel Atom (TM) CPU N455 @1.66GHz

OS: Windows 7 Starter
CAD Version: Autocad 2009

I bet you wouldnt like what you see  ;D
Intel Core2Duo P7450 2.13GHz 4Gb Ram - Seven 64
Code: [Select]
AutoCAD 2013
;(time-it '(c:ShortLongest))   Program running time: 3822 msecs.
;(time-it '(ph:all1))          Program running time: 5024 msecs.
;(time-it '(c:Long&ShortOfIt)) Program running time: 7644 msecs.

AutoCAD 2010
;(time-it '(c:ShortLongest))   Program running time: 2028 msecs.
;(time-it '(ph:all1))          Program running time: 67174 msecs.  <<< ?   
;(time-it '(c:Long&ShortOfIt)) Program running time: 5304 msecs

I think that the real difference in performance between all versions is due to the cancellation in a single shot of all entities, the latest versions are almost similar.


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: ( Challenge ) Shortest & Longest line
« Reply #46 on: January 31, 2013, 02:47:30 PM »
New version:
Code - Auto/Visual Lisp: [Select]
  1. (defun C:ShortLongestByLyr2 ( / TblDat SelSet SelSt2 Countr EntSht EntLng
  2.                                 EntDat EntNam LenVal MaxLen MinLen AllSet)
  3.   (defun Dxf (DxfCod EntDat)  (cdr (assoc DxfCod EntDat)))
  4.   (if (= 1 (logand 1 (getvar "UNDOCTL"))) (command "_.UNDO" "_C" "_N"))
  5.   (setvar "HIGHLIGHT" 0)
  6.   (setq SelSt2 (ssadd))
  7.   (while (setq TblDat (tblnext "LAYER" (null TblDat)))
  8.     (if (setq SelSet (ssget "_X" (list '(0 . "LINE") (cons 8 (cdr (assoc 2 TblDat))))))
  9.       (progn
  10.         (setq
  11.           Countr 0
  12.           EntSht (ssname SelSet 0)
  13.           EntLng EntSht
  14.           EntDat (entget EntSht)
  15.           MaxLen (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  16.           MinLen  MaxLen
  17.         )
  18.         (repeat (sslength SelSet)
  19.           (setq
  20.             EntNam (ssname SelSet Countr) EntDat (entget EntNam)
  21.             LenVal (distance (Dxf 10 EntDat) (Dxf 11 EntDat))
  22.             Countr (1+ Countr)
  23.           )
  24.           (cond
  25.             ( (> LenVal MaxLen) (setq MaxLen LenVal  EntLng EntNam) )
  26.             ( (< LenVal MinLen) (setq MinLen LenVal  EntSht EntNam) )
  27.           )
  28.         )
  29.         (setq
  30.           SelSt2 (ssadd EntSht SelSt2)  SelSt2 (ssadd EntLng SelSt2)
  31.           AllSet (cons SelSet AllSet)
  32.         )
  33.       )
  34.     )
  35.   )
  36.   (command "_.ERASE") (foreach ForElm AllSet (command ForElm))
  37.   (command  "_R" SelSt2 "")
  38.   (setvar "HIGHLIGHT" 1)
  39. )

Code: [Select]
;AutoCAD 2010
;(time-it '(c:CAB:test))            Program running time: 2621 msecs.   
;(time-it '(c:ShortLongestByLyr2))  Program running time: 1747 msecs.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: ( Challenge ) Shortest & Longest line
« Reply #47 on: January 31, 2013, 03:40:45 PM »
Thank you all guys for parallel testing.
I like the numbers that came out but that means my computer needs a doctor.
Or I'll let my kids to turn it in a MineCraft machine...