Author Topic: -={ Challenge }=- Group List by Number  (Read 26858 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Group List by Number
« Reply #30 on: March 13, 2010, 03:48:44 PM »
my version, only for speed...

Code: [Select]
(defun GBN_1_EV (l n / b lst)
 (setq b (list '(reverse a)))
 (repeat (/ n 4)
  (setq b (cons '(setq
                  a
                  (cons (cadddr l) (cons (caddr l) (cons (cadr l) (cons (car l) a))))
                  l
                  (cddddr l)
                 ) ;_  setq
                b
          ) ;_  cons
  ) ;_  setq
 ) ;_  repeat
 (setq n (rem n 4))
 (repeat (/ n 3)
  (setq b (cons '(setq
                  a
                  (cons (caddr l) (cons (cadr l) (cons (car l) a)))
                  l
                  (cdddr l)
                 ) ;_  setq
                b
          ) ;_  cons
  ) ;_  setq
 ) ;_  repeat
 (setq n (rem n 3))
 (repeat (/ n 2)
  (setq b (cons '(setq
                  a
                  (cons (cadr l) (cons (car l) a))
                  l
                  (cddr l)
                 ) ;_  setq
                b
          ) ;_  cons
  ) ;_  setq
 ) ;_  repeat
 (setq n (rem n 2))
 (repeat (/ n 1)
  (setq b (cons '(setq
                  a
                  (cons (car l) a)
                  l
                  (cdr l)
                 ) ;_  setq
                b
          ) ;_  cons
  ) ;_  setq
 ) ;_  repeat
 (eval (cons 'defun (cons 'f1 (cons '(a) b))))
 (while l (setq lst (cons (f1 nil) lst)))
 (reverse lst)
)

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: -={ Challenge }=- Group List by Number
« Reply #31 on: March 13, 2010, 03:51:52 PM »
Excellent. Now having done this one needs to consider context. What's the typical context this function would be used? Maybe you'll use the function to take the flat list of doubles returned by (vlax-get polyline 'coordinates) and convert instead to a list of points (because for whatever reason you were eschewing dxf data), grouping by 2 or 3 depending if it's a lightweight or heavyweight polyline. Is it reasonable to anticipate you could have a polyline with 3000 to 5000 vertices? Back to you Jim.

That is exactly my purpose, [I also used it in this to group the attribs into 8's], but it would have to be quite an extreme case in which one would be dealing with 3000-5000 polyline vertices I would think.

But then, irrelevant of the number of vertices, if all the functions produce the same result then surely you would just use the fastest every time... unless you wanted to demonstrate some sophisticated coding in your programs...  :evil:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: -={ Challenge }=- Group List by Number
« Reply #32 on: March 13, 2010, 04:19:36 PM »
That is exactly my purpose, [I also used it in this to group the attribs into 8's], but it would have to be quite an extreme case in which one would be dealing with 3000-5000 polyline vertices I would think.

lol, lucky guess. :) As for vertex count, have you ever received data generated by other CAD/GIS systems? Can certainly be in that magnitude.

But then, irrelevant of the number of vertices, if all the functions produce the same result then surely you would just use the fastest every time... unless you wanted to demonstrate some sophisticated coding in your programs...  :evil:

Ha. :) For me the "need for speed" is eclipsed by the "need for code clarity", that is, a year from now ill I be able to understand how a given function works, in the event something trips it up? That doesn't mean one has to trade performance for clarity per se. It does mean I won't spend a ton of time on a particular function to squeeze the nth bit of performance out of it, unless I'm certain the function will have to process huge amounts of data or it will be called in an iteration hundreds or thousands of times. Then it gets put on the scope. Otherwise I try to balance readable code with efficient code, tho some may not view my coding as particularly peppy or readable; the latter being widely subjective ...

Edit: Crap, my grammar has gone out the window. :shame:
« Last Edit: March 13, 2010, 04:25:39 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Group List by Number
« Reply #33 on: March 13, 2010, 04:25:03 PM »

List of 10240 elements, Grouped by 5
Code: [Select]
Benchmarking ..........Elapsed milliseconds / relative speed for 128 iteration(s):

    (GBN_1_EV L N)............1328 / 2.54 <fastest>
    (GROUPBYNUM_MAC4 L N).....2734 / 1.23
    (GROUPBYNUM_MAC3 L N).....2828 / 1.19
    (GROUPBYNUM_MAC2 L N).....3375 / 1 <slowest>

List of 10240 elements, Grouped by 15
Code: [Select]
Benchmarking ..........Elapsed milliseconds / relative speed for 128 iteration(s):

    (GBN_1_EV L N)............1063 / 2.54 <fastest>
    (GROUPBYNUM_MAC4 L N).....2485 / 1.09
    (GROUPBYNUM_MAC3 L N).....2532 / 1.07
    (GROUPBYNUM_MAC2 L N).....2703 / 1 <slowest>

List of 10240 elements, Grouped by 45
Code: [Select]
Benchmarking ..........Elapsed milliseconds / relative speed for 128 iteration(s):

    (GBN_1_EV L N)............1031 / 2.35 <fastest>
    (GROUPBYNUM_MAC2 L N).....2375 / 1.02
    (GROUPBYNUM_MAC4 L N).....2406 / 1.01
    (GROUPBYNUM_MAC3 L N).....2421 / 1 <slowest>

List of 327680 elements, Grouped by 15
Code: [Select]
Benchmarking .....Elapsed milliseconds / relative speed for 4 iteration(s):

    (GBN_1_EV L N)............1063 / 2.54 <fastest>
    (GROUPBYNUM_MAC4 L N).....2453 / 1.1
    (GROUPBYNUM_MAC3 L N).....2547 / 1.06
    (GROUPBYNUM_MAC2 L N).....2703 / 1 <slowest>

List of 1280 elements, Grouped by 15
Code: [Select]
Benchmarking .............Elapsed milliseconds / relative speed for 1024 iteration(s):

    (GBN_1_EV L N)............1344 / 2.02 <fastest>
    (GROUPBYNUM_MAC4 L N).....2516 / 1.08
    (GROUPBYNUM_MAC3 L N).....2547 / 1.07
    (GROUPBYNUM_MAC2 L N).....2718 / 1 <slowest>


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: -={ Challenge }=- Group List by Number
« Reply #34 on: March 13, 2010, 04:28:15 PM »
I had grabbed all the defuns in the thread, and mine from the other thread. One run to illuminate the magnitude I made reference to before:

Code: [Select]
   LST sports 11264 items, N = 4 ...
    
    Elapsed milliseconds / relative speed for 16 iteration(s):
    
        (GROUPBYNUM_MAC3 LST N).......437 / 40.34 <fastest>
        (GROUPBYNUM_MAC2 LST N).......452 / 39.00
        (GROUPBYNUM2 LST N)...........452 / 39.00
        (GROUPITEMS_MP LST N).........468 / 37.67
        (GROUPBYNUM LST N)............484 / 36.42
        (WIZ-GRP LST N)...............515 / 34.23
        (SPLIT LST N).................609 / 28.95
        (GBN LST N)...................609 / 28.95
        (LIST_GROUPING LST N).......13026 / 1.35
        (GBN_AJT LST N).............16427 / 1.07
        (GBN_AJT_NONIL LST N).......17020 / 1.04
        (GBN_AJT2 LST N)............17628 / 1.00 <slowest>

_shrug_
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: -={ Challenge }=- Group List by Number
« Reply #35 on: March 13, 2010, 04:34:55 PM »
lol, lucky guess. :) As for vertex count, have you ever received data generated by other CAD/GIS systems? Can certainly be in that magnitude.

Oh, perhaps - I don't deal with drawings at all really, so my judgement doesn't really mean much..

Ha. :) For me the "need for speed" is eclipsed by the "need for code clarity", that is, a year from now ill I be able to understand how a given function works, in the event something trips it up? That doesn't mean one has to trade performance for clarity per se. It does mean I won't spend a ton of time on a particular function to squeeze the nth bit of performance out of it, unless I'm certain the function will have to process huge amounts of data or it will be called in an iteration hundreds or thousands of times. Then it gets put on the scope. Otherwise I try to balance readable code with efficient code, tho some may not view my coding as particularly peppy or readable; the latter being widely subjective ...

I would agree - I would always go for a loop over recursion, (unless the latter method really simplifies the problem), and in most cases the loop (whether it be foreach, while, repeat), is both easier to read and usually faster.

my version, only for speed...

Very nice! Building a function to fit each case... I suppose the function may be even more efficient if you continued the idea to construct (/ n 5) and upwards, but the code may get a bit tedious...
« Last Edit: March 13, 2010, 04:39:13 PM by Lee Mac »

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: -={ Challenge }=- Group List by Number
« Reply #36 on: March 13, 2010, 04:41:23 PM »
my version, only for speed...
you scare me, Evgeniy :)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Group List by Number
« Reply #37 on: March 13, 2010, 04:50:13 PM »
I set myself the task, not just write fast code.
I wanted to show not a universal program.
Here's another approach, the program uses a pre-known data - I know the list is very long.

you scare me, Evgeniy :)

Indeed, this code, I do not like - you can write ten times fewer lines ...

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: -={ Challenge }=- Group List by Number
« Reply #38 on: March 13, 2010, 04:52:09 PM »
Even knowing that the list is long, I very much doubt that I could have come up with that code  :lol:

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Group List by Number
« Reply #39 on: March 13, 2010, 04:55:33 PM »
Even knowing that the list is long, I very much doubt that I could have come up with that code  :lol:

now you have another trick, the next time you'll be able to use it.  :wink:

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: -={ Challenge }=- Group List by Number
« Reply #40 on: March 13, 2010, 04:58:08 PM »
Even knowing that the list is long, I very much doubt that I could have come up with that code  :lol:

now you have another trick, the next time you'll be able to use it.  :wink:

Indeed, I have learnt so much from your codes  8-)

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: -={ Challenge }=- Group List by Number
« Reply #41 on: March 13, 2010, 05:00:48 PM »
you scare me, Evgeniy :)

Indeed, this code, I do not like - you can write ten times fewer lines ...
i'm not scared by the code, actually. i'm scared of you, of how resourceful you are

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: -={ Challenge }=- Group List by Number
« Reply #42 on: March 13, 2010, 05:06:59 PM »
i'm not scared by the code, actually. i'm scared of you, of how resourceful you are

I can not find work, where it is really necessary and appreciated ...
Possible, these skills can only be used here?

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: -={ Challenge }=- Group List by Number
« Reply #43 on: March 13, 2010, 05:09:18 PM »
i'm not scared by the code, actually. i'm scared of you, of how resourceful you are

I can not find work, where it is really necessary and appreciated ...
Possible, these skills can only be used here?

I agree - I was looking for work in this area also, between my studies - many won't consider you unless you have knowledge of C#/C++ (or somewhere around that level). I think it is because LISP is so accessible, so many feel that can cope by themselves.  :|

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: -={ Challenge }=- Group List by Number
« Reply #44 on: March 13, 2010, 05:22:01 PM »
Seriously? You guys cannot find work? What industries are you targeting? AutoCAD programming, primarily LISP bashing, has put bacon on my plate for 15 years. Before that a combination of design and programming for another 10, before that engineering for another 6. Please don't interpret this as bragging, I'm just saying -- if I can do it surely you guys can. I've worked in the municipal, industrial and oil/gas industries. What industries are you targeting? Are you trying to get in as a programmer or an an engineer/technologist who can design/code? I'm curious. Hope all of you get employment using your coding skills, it's far too good to serve only as learning resources for others.
« Last Edit: March 13, 2010, 05:35:52 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst