TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on March 06, 2010, 02:06:36 PM

Title: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 06, 2010, 02:06:36 PM
The Challenge:

To group a list into sub-lists of a desired length.

Example:

Code: [Select]
(GroupByNum '(1 2 3 4 5 6) 2)

((1 2) (3 4) (5 6))

Code: [Select]
(GroupByNum '(1 2 3 4 5 6) 3)

((1 2 3) (4 5 6))

Have fun!
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 06, 2010, 02:11:49 PM
... (http://www.theswamp.org/index.php?topic=5108.0)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 06, 2010, 02:12:24 PM
Ahh... I even did a search first  :-(
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 06, 2010, 02:15:51 PM
Oh well, here's my offering anyway...

Code: [Select]
(defun GroupByNum (lst num / rtn) (setq rtn nil) 
  (if lst
    (cons (reverse
            (repeat num
              (progn
                (setq rtn (cons (car lst) rtn) lst (cdr lst)) rtn)))

          (GroupByNum lst num))))
Title: Re: -={ Challenge }=- Group List by Number
Post by: VovKa on March 06, 2010, 06:06:38 PM
it's past midnight here in Ukraine and can't beat anything better out of my tortured brain
Code: [Select]
(defun GroupByNum (lst num / rslt)
  (if (zerop (car (setq rslt
(if lst
   (if (listp (car (setq rslt (GroupByNum (cdr lst) num))))
     (cons (1- num) (cons (list (car lst)) rslt))
     (cons (1- (car rslt)) (cons (cons (car lst) (cadr rslt)) (cddr rslt)))
   )
   (list num)
)
  )
     )
      )
    (cdr rslt)
    rslt
  )
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 06, 2010, 06:25:59 PM
Nice one VovKa, that's gonna take me a while to work out....  :oops:
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 06, 2010, 06:50:55 PM
That is actually awesome - working from the bottom up... I don't know how you come up with the ideas...!  :lol:
Title: Re: -={ Challenge }=- Group List by Number
Post by: VovKa on March 07, 2010, 03:43:19 AM
not my idea, actually :(
it's a commonly used way of implementing iteration
another example (http://www.caduser.ru/forum/index.php?PAGE_NAME=message&FID=23&TID=39551&MID=222692#message222692)
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy on March 07, 2010, 03:49:47 AM
may boil the brain...  :-D

Code: [Select]
(defun gbn (l n)
 (if l
  (f l nil n n)
 )
)
(defun f (a b n i)
 (if (> n 0)
  (f (cdr a)(cons (car a) b) (1- n) i)
  (cons (reverse b) (gbn a i))
 )
)

test:
Code: [Select]
(gbn '(1 2 3 4 5 6) 1) ;=> '((1) (2) (3) (4) (5) (6))
(gbn '(1 2 3 4 5 6) 2) ;=> '((1 2) (3 4) (5 6))
(gbn '(1 2 3 4 5 6) 3) ;=> '((1 2 3) (4 5 6))
(gbn '(1 2 3 4 5 6) 4) ;=> '((1 2 3 4) (5 6 nil nil))
Title: Re: -={ Challenge }=- Group List by Number
Post by: wizman on March 07, 2010, 04:54:31 AM
Vovka, Lee this gives odd result:

(groupbynum '(1 2 3 4 5 6 7 8 9 10) 3)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 07, 2010, 06:36:09 AM
Very nice Evgeniy!

Bouncing between the two functions for each group!  :lol:
Title: Re: -={ Challenge }=- Group List by Number
Post by: VovKa on March 07, 2010, 09:01:55 AM
Vovka, Lee this gives odd result:

(groupbynum '(1 2 3 4 5 6 7 8 9 10) 3)
yep, function ends in an unfinished state :(

Evgeniy, mine is boiling :)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 07, 2010, 09:15:55 AM
Not only more concise and smarter, but also faster too:  :evil:

Code: [Select]
(BenchMark '((gbn '(1 2 3 4 5 6) 3) (GroupByNum '(1 2 3 4 5 6) 3) (GroupByNum_vk '(1 2 3 4 5 6) 3)))
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (GBN (QUOTE (1 2 3 4 5 6)) 3)...............1217 / 1.12 <fastest>
    (GROUPBYNUM (QUOTE (1 2 3 4 5 6)) 3)........1264 / 1.07
    (GROUPBYNUM_VK (QUOTE (1 2 3 4 5 6)) 3).....1357 / 1.00 <slowest>
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 07, 2010, 09:20:17 AM
Simpler, but perhaps faster:

Code: [Select]
(defun GroupByNum_Mac2 (l n / a b)
  (while l
    (repeat n
      (setq a (cons (car l) a) l (cdr l)))
    (setq b (cons (reverse a) b) a nil))
  (reverse b))

Code: [Select]
(defun GroupByNum_Mac3 (l n / a b i)
  (while l (setq i n)
    (while (< 0 i)
      (setq a (cons (car l) a) l (cdr l) i (1- i)))
    (setq b (cons (reverse a) b) a nil))
  (reverse b))
Title: Re: -={ Challenge }=- Group List by Number
Post by: kraz on March 10, 2010, 08:22:59 PM
(defun list_grouping(lst numb / glist tlist c)
 (if (listp lst)
  (progn
   (setq glist '() tlist '() c 1)
   (foreach e lst
    (if (eq (rem c numb) 0)
     (setq glist (append glist (list (append tlist (list e)))) tlist '())
     (setq tlist (append tlist (list e)))
    )
    (setq c (1+ c))
   )
   (if (> (length tlist) 0)
    (append glist (list tlist))
     glist
   );if
  )
  nil
 )
)

;;;;;;;;;;;;;;;;;
(list_grouping '(1 2 3 4 5 6 7 8 9 10) 3) -> ((1 2 3) (4 5 6) (7 8 9) (10))

hmm...i thought '(1 2 3 4 5 6 7 8 9 10) 3) -> ((1 2 3) (4 5 6) (7 8 9) (10 nil nil)) is not true...so....hehe
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 11, 2010, 06:26:42 AM
Thanks Alan  :-)  Nice code also  :-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: wizman on March 12, 2010, 02:26:39 PM
Here's another nth:


Code: [Select]
(defun wiz-grp (l n / a b c d)
    (while (Setq d l)
        (while (< (setq b (length a)) n)
            (setq a (cons (nth b d) a) l (cdr l)))
            (setq  c (cons (reverse a) c)  a nil))
            (reverse c))
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 12, 2010, 02:30:25 PM
Nice one Wiz  ^-^

Loving the new avatar btw  :-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: wizman on March 12, 2010, 02:48:52 PM
Thanks Lee, Good codes from all too... :-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: gile on March 13, 2010, 11:52:29 AM
Hi,

I am late (I had not much time for lisping these days) but here're my 2 cents

Code: [Select]
(defun split (l n / sub)
  (defun sub (a n)
    (if (< 0 n)
      (cons (car a) (sub (setq l (cdr a)) (1- n)))
    )
  )
  (if l
    (cons (sub l n) (split l n))
  )
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 11:54:14 AM
Nice one Gile  :-)  You do love the recursive solutions  8-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 12:21:16 PM
Here is the result I get:

Code: [Select]
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (GROUPBYNUM_MAC3 LST 2).....1357 / 1.40 <fastest>
    (WIZ-GRP LST 2).............1482 / 1.28
    (GBN_EV LST 2)..............1545 / 1.23
    (GROUPBYNUM_MAC2 LST 2).....1575 / 1.21
    (GROUPBYNUM_MAC1 LST 2).....1654 / 1.15
    (SPLIT_GILE LST 2)..........1700 / 1.12
    (GROUPBYNUM_VK LST 2).......1731 / 1.10
    (GBN_AJT LST 2).............1872 / 1.02
    (GBN_AJT2 LST 2)............1903 / 1.00 <slowest>
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 01:19:20 PM
Judging the posted performances it's obvious to me you guys are testing using a list with pretty modest size, guessing < 100 items. Re-run your tests with a list of 10000 items and you will find a huge difference in performance between the algorithms. Also, you should vary the "group by" value. Subtitle: One test does paint an accurate picture of relative performances. Just sayin'. :)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 01:50:54 PM
You make a good point Michael, I shall try your recommendations  - thanks  :-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 02:03:32 PM
Ok, retesting with Michael's suggestions:

List with 200 elements, Grouped by 2
Code: [Select]
  (setq a '(0 1 2 3 4 5 6 7 8 9))
  (repeat 20 (setq lst (append a lst)))

Code: [Select]
Benchmarking ...............Elapsed milliseconds / relative speed for 4096 iteration(s):

    (GROUPBYNUM_MAC3 LST 2).....1482 / 2.04 <fastest>
    (WIZ-GRP LST 2).............1872 / 1.62
    (GBN_EV LST 2)..............1950 / 1.55
    (GROUPBYNUM_MAC2 LST 2).....2028 / 1.49
    (SPLIT_GILE LST 2)..........2215 / 1.37
    (GROUPBYNUM_MAC1 LST 2).....2262 / 1.34
    (GROUPBYNUM_VK LST 2).......2496 / 1.21
    (GBN_AJT2 LST 2)............2902 / 1.04
    (GBN_AJT LST 2).............3027 / 1.00 <slowest>

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

    (GROUPBYNUM_MAC3 LST 5).....1201 / 2.09 <fastest>
    (GROUPBYNUM_MAC2 LST 5).....1388 / 1.81
    (GROUPBYNUM_MAC1 LST 5).....1482 / 1.70
    (GBN_EV LST 5)..............1498 / 1.68
    (WIZ-GRP LST 5).............1498 / 1.68
    (SPLIT_GILE LST 5)..........1591 / 1.58
    (GBN_AJT2 LST 5)............2106 / 1.19
    (GBN_AJT LST 5).............2122 / 1.18
    (GROUPBYNUM_VK LST 5).......2512 / 1.00 <slowest>

List of 200 elements, Grouped by 20
Code: [Select]
Benchmarking ...............Elapsed milliseconds / relative speed for 4096 iteration(s):

    (GROUPBYNUM_MAC3 LST 20).....1045 / 2.40 <fastest>
    (GROUPBYNUM_MAC2 LST 20).....1092 / 2.30
    (GROUPBYNUM_MAC1 LST 20).....1139 / 2.20
    (SPLIT_GILE LST 20)..........1263 / 1.99
    (GBN_EV LST 20)..............1295 / 1.94
    (WIZ-GRP LST 20).............1357 / 1.85
    (GBN_AJT LST 20).............1732 / 1.45
    (GBN_AJT2 LST 20)............1747 / 1.44
    (GROUPBYNUM_VK LST 20).......2511 / 1.00 <slowest>

Hopefully this is a more rounded test.
Title: Re: -={ Challenge }=- Group List by Number
Post by: VovKa on March 13, 2010, 02:18:22 PM
if (length lst) is a multiple of n
Code: [Select]
(defun GroupByNum_Mac4 (l n / a b i)
  (setq l (reverse l))
  (while l
    (setq i n)
    (while (< 0 i)
      (setq a (cons (car l) a)
    l (cdr l)
    i (1- i)
      )
    )
    (setq b (cons a b)
  a nil
    )
  )
  b
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 02:43:53 PM
Try it with:

(setq lst '(0 1 2 3 4 5 6 7 8 9 0))
        
(repeat 10 (setq lst (append lst lst)))

(length lst)

11264

with a group length of say 16

the relative difference between the slowest and fastest will be more in the order to 40 to 50 times

let the weeping begin
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy on March 13, 2010, 02:54:10 PM
You need the fastest function for the huge list?
for this case, you need to forget about recursion, and use a specialized algorithm ...
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 02:55:17 PM
List Length = 210x10 = 10240,  Grouped by 16:

Code: [Select]
Benchmarking ..........Elapsed milliseconds / relative speed for 128 iteration(s):

    (GROUPBYNUM_MAC3 LST 16)......1607 / 22.80 <fastest>
    (GROUPBYNUM_MAC4 LST 16)......1623 / 22.58
    (GROUPBYNUM_MAC2 LST 16)......1700 / 21.56
    (GROUPBYNUM_MAC1 LST 16)......1841 / 19.90
    (SPLIT_GILE LST 16)...........1981 / 18.50
    (GBN_EV LST 16)...............2090 / 17.53
    (WIZ-GRP LST 16)..............2090 / 17.53
    (GROUPBYNUM_VK LST 16)........3978 / 9.21
    (GBN_AJT2 LST 16)............36598 / 1.00
    (GBN_AJT LST 16).............36645 / 1.00 <slowest>
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 03:14:03 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.
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy 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)
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac 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  (http://www.theswamp.org/index.php?topic=32431.0)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:
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 04:19:36 PM
That is exactly my purpose, [I also used it in this  (http://www.theswamp.org/index.php?topic=32431.0)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:
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy 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>

Title: Re: -={ Challenge }=- Group List by Number
Post by: MP 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_
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac 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...
Title: Re: -={ Challenge }=- Group List by Number
Post by: VovKa on March 13, 2010, 04:41:23 PM
my version, only for speed...
you scare me, Evgeniy :)
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy 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 ...
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac 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:
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy 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:
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac 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-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: VovKa 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
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy 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?
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac 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.  :|
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP 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.
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 05:34:45 PM
I targeted all industries involving CAD design, but approached as a programmer (as I have very little experience in any particular field with my age and studies) - many said they were not interested, and others said they could not afford to take on anyone with the current financial climate... It would be a great job indeed to get paid to do what you love - you must be pretty happy Michael.
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 05:53:25 PM
I targeted all industries involving CAD design, but approached as a programmer (as I have very little experience in any particular field with my age and studies) - many said they were not interested, and others said they could not afford to take on anyone with the current financial climate... It would be a great job indeed to get paid to do what you love

Maybe therein lies the rub. Earlier in my career I didn't try to get in on the merits of my programming, even tho I had close to 10 years programming experience before shaking hands with AutoCAD. I'd get in on the basis of interest in pursuing engineering, identifying I could do some automation if required. Once in the door opportunities to automate work processes etc. abound, as do the opportunities to demonstrate skills in said area. In no time the programming eclipses the engineering. This has repeated itself time and again. The last job I took, coming up 2 years now, was solely on the basis of learning how to design pipelines. I had zero experience. My programming wasn't even on the table. Just this week my boss gave the nod for a programming project estimated to have 900 hours programming and another 600 for documentation, training prep and training. Hope this inspires you or gives you alternative employment strategies.

Subtitle: The most direct path to your goals isn't always direct.

you must be pretty happy Michael.

Thru the miracle of drugs I'm working towards that, been a long ride.
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 05:59:06 PM
Maybe therein lies the rub. Earlier in my career I didn't try to get in on the merits of my programming, even tho I had close to 10 years programming experience before shaking hands with AutoCAD. I'd get in on the basis of interest in pursuing engineering, identifying I could do some automation if required. Once in the door opportunities to automate work processes etc. abound, as do the opportunities to demonstrate skills in said area. In no time the programming eclipses the engineering. This has repeated itself time and again. The last job I took, coming up 2 years now, was solely on the basis of learning how to design pipelines. I had zero experience. My programming wasn't even on the table. Just this week my boss gave the nod for a programming project estimated to have 900 hours programming and another 600 for documentation, training prep and training. Hope this inspires you or gives you alternative employment strategies.

Subtitle: The most direct path to your goals isn't always direct.

That's some really good advice, thanks mate. I really see how that is a much better way in, and getting a lot of other experience along the way. Thanks  :-)

you must be pretty happy Michael.
Thru the miracle of drugs I'm working towards that, been a long ride.

Seriously?


Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 06:08:09 PM
That's some really good advice, thanks mate. I really see how that is a much better way in, and getting a lot of other experience along the way. Thanks  :-)

My great pleasure. The experience makes for interesting jobs. And the more varied your engineering background the greater your ability to adapt to new challenges. I've programmed everything from data loggers, water distribution analysis and modeling, water treatment plants, heat trace modeling to pipeline design automation. It has not been a boring ride. Incidentally, I was a high school drop out, never even finished grade 10, tho I have a bit of grade 11 math (the only subject I liked aside from science). I don't advocate this last bit of info as a strategy tho. It does underscore my statement "If I can do it surely you guys can".

you must be pretty happy Michael.
Thru the miracle of drugs I'm working towards that, been a long ride.

Seriously?

(http://files.myopera.com/drlaunch/albums/37656/ya-srsly001.jpg)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 13, 2010, 06:16:16 PM
My great pleasure. The experience makes for interesting jobs. And the more varied your engineering background the greater your ability to adapt to new challenges. I've programmed everything from data loggers, water distribution analysis and modeling, water treatment plants, heat trace modeling to pipeline design automation. It has not been a boring ride. Incidentally, I was a high school drop out, never even finished grade 10, tho I have a bit of grade 11 math (the only subject I liked aside from science). I don't advocate this last bit of info as a strategy tho. It does underscore my statement "If I can do it surely you guys can".

Exactly, the more you apply yourself the more employable you become... great strategy (except the drop-out part   ;-) ) Thanks again.
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 06:50:49 PM
Thanks again.

you're very welcome lee
Title: Re: -={ Challenge }=- Group List by Number
Post by: wizman on March 13, 2010, 07:58:23 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)
)


Wow, You're very good at this Evgeniy.
Title: Re: -={ Challenge }=- Group List by Number
Post by: alanjt on March 13, 2010, 09:06:42 PM
Now we should convert it back to a single list.
Title: Re: -={ Challenge }=- Group List by Number
Post by: MP on March 13, 2010, 10:56:53 PM
Now we should convert it back to a single list.

see the squish (http://www.theswamp.org/index.php?topic=4064.msg48404#msg48404) function for one way
Title: Re: -={ Challenge }=- Group List by Number
Post by: Lee Mac on March 14, 2010, 08:03:26 AM
Now we should convert it back to a single list.

see the squish (http://www.theswamp.org/index.php?topic=4064.msg48404#msg48404) function for one way

Interesting thread indeed - same technique that Evgeniy uses in his first code I believe  :-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy on March 14, 2010, 08:30:12 AM
Interesting thread indeed - same technique that Evgeniy uses in his first code I believe  :-)

I was interested to write in this style. My function is easy to translate into a more familiar sight ...
Title: Re: -={ Challenge }=- Group List by Number
Post by: Bhull1985 on March 03, 2014, 07:37:08 AM
That's some really good advice, thanks mate. I really see how that is a much better way in, and getting a lot of other experience along the way. Thanks  :-)

My great pleasure. The experience makes for interesting jobs. And the more varied your engineering background the greater your ability to adapt to new challenges. I've programmed everything from data loggers, water distribution analysis and modeling, water treatment plants, heat trace modeling to pipeline design automation. It has not been a boring ride. Incidentally, I was a high school drop out, never even finished grade 10, tho I have a bit of grade 11 math (the only subject I liked aside from science). I don't advocate this last bit of info as a strategy tho. It does underscore my statement "If I can do it surely you guys can".

you must be pretty happy Michael.
Thru the miracle of drugs I'm working towards that, been a long ride.

Seriously?

(http://files.myopera.com/drlaunch/albums/37656/ya-srsly001.jpg)

Sorry to thread necro but this one was too interesting not to comment on.
I can fully attest to  the validity of what MP says, especially the comment about "once your foot is in the door, programming opportunities abound"
LISP is like a dirty little secret sometimes, that not a lot of companies want to strive to commit resources to because of the variable productiveness of any LISP routines they may have used in the past.
For me it was a family connection, so yeah I cheated...but that was how I got my foot in the door and since then I've ran with it. It's very possible. Drafting and design, with no college....just from knowing someone in the business who had a good relationship with their boss. Just enough of one to convince him to let me help out for a few days...after that, he approached me with a job offer. It wasn't until later that year at that same company that I was first introduced to lisp, only as a third-party gifted tool that at the time amazed me, due to the automation it exemplified....but it wasn't until half of a decade later that LISP would once again become a part of my career.
Gas and oil and architecture they're always going to be there....work will be around. If you can reach the people who are in management positions via family connection, out-of-work friendships, or the most basic method- employee to employer or from staff to management, then any intelligent person would leverage the power of automation upon the desires of cad-bees.
If you can code, and you're in a position to show how your code can be effective, this to me has been the only successful method in truly getting the 'o.k.' to code for a living.
I'm a fledling but lisp is so powerful I've been able to put code together that allowed 3 end-users to create an entire refinery's p&id processes , from scratch to 160 cad documents in a matter of weeks, nearly eliminating all of the red/greenlining that those same managers would spend hours of their own time to do. Now the same company has hired me direct and wants me to take a look at the electrical and civil structural processes in addition to see where I can streamline and/or make more efficient their existing methods. Not to interfere here guys, but hey try this out for size....even old-bears like it when the fish are dropped at their feet instead. Just made that metaphor up but I think it's apt.
It seems to me like there's a very small niche that autocad programmers fit into. Yet there's a ton of room for growth---I shudder to think of the efficiency someone such as lee could provide to a company willing to rework their processes from the ground up, integrating custom routines and applications to automate processes and eliminate the human error contained within the manual versions of those tasks...
My 2 cents, sry from the necro'in
Title: Re: -={ Challenge }=- Group List by Number
Post by: chlh_jd on March 05, 2014, 12:26:54 AM
All of yours are very good !

Personally, I like the 3rd function of Lee Mac's .

The number group by , usually does not exceed 4 .

here just post my always use function .
Code: [Select]
(defun list-comp (a b / mid rslt)
    (repeat (/ (length a) b)
      (setq mid nil)
      (repeat b
(setq mid (cons (car a) mid)
      a   (cdr a)
)
      )
      (setq rslt (cons (reverse mid) rslt))
    )
  (if a (reverse (cons a rslt))
    (reverse rslt))
  )
Title: Re: -={ Challenge }=- Group List by Number
Post by: chlh_jd on March 05, 2014, 12:57:57 AM
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)
)
Very profound code , Evgeniy  :-)
I take long time to learn it , thank you very much !
Personally , I would like use
Code: [Select]
(vl-list* (cadddr l) (caddr l) (cadr l) (car l) a)to replace
Code: [Select]
(cons (cadddr l) (cons (caddr l) (cons (cadr l) (cons (car l) a))))
Title: Re: -={ Challenge }=- Group List by Number
Post by: chlh_jd on March 05, 2014, 01:12:11 AM
Some qustion :
Code: [Select]
(setq l '(1 2 3 4 5 6 7 8 9 10 11))(f l 3) get the result which one is better ?
Code: [Select]
((1 2 3) (4 5 6) (7 8 9) (10 11 nil))or
Code: [Select]
((1 2 3) (4 5 6) (7 8 9) (10 11))
Title: Re: -={ Challenge }=- Group List by Number
Post by: ElpanovEvgeniy on March 05, 2014, 09:39:24 AM
Personally , I would like use
Code: [Select]
(vl-list* (cadddr l) (caddr l) (cadr l) (car l) a)to replace
Code: [Select]
(cons (cadddr l) (cons (caddr l) (cons (cadr l) (cons (car l) a))))

I think your code will run slower.
But I did not check...
 :-)
Title: Re: -={ Challenge }=- Group List by Number
Post by: LE3 on March 05, 2014, 10:33:35 AM
I targeted all industries involving CAD design, but approached as a programmer (as I have very little experience in any particular field with my age and studies) - many said they were not interested, and others said they could not afford to take on anyone with the current financial climate... It would be a great job indeed to get paid to do what you love - you must be pretty happy Michael.

First time I read this old thread --- and for curiosity purposes (if you could answer it), do you work now as programmer for a company now?

kudos.
Title: Re: -={ Challenge }=- Group List by Number
Post by: ur_naz on March 08, 2014, 05:23:31 PM
Very, very lazy GroupByNum...
Code - Auto/Visual Lisp: [Select]
  1. (defun firstn (n lst)
  2.   (if (< 0 n)
  3.     (cons (car lst) (firstn (1- n) (cdr lst)))))
  4.  
  5. (defun nthcdr (n lst)
  6.   (if (< n 0) lst (nthcdr (1- n) (cdr lst))))
  7.  
  8. (defun GroupByNum (n lst)
  9.   (if lst (cons (firstn n lst) (GroupByNum n (nthcdr n lst)))))
Title: Re: -={ Challenge }=- Group List by Number
Post by: irneb on March 10, 2014, 07:12:33 AM
Be careful using recursion on long lists. You could run into stack overflows, especially since AutoLisp does not do tail-call otimization. Other than that good functional code, though firstn & GroupByNum are not tail recursive - so even if ALisp was optimizing it wouldn't work on these.

BTW, "Lazy" has slightly different connotation in some programming circles. Rather than being a way to describe slow running programs, it actually means the opposite: A lazy algorithm only calculates the results as and when needed, such that it uses the least amount of resources and takes only as little time as needed - then builds on its results afterwards without re-calculating for each new query.

Unfortunately a true lazy algorithm isn't possible in AutoLisp. We don't have access to reference calling on variables, not to mention an easy OOP system. But you can do something similar using a cached store of results - though I'm not sure it would be faster in all cases. Especially this one where each call could be on a totally different list and number combination.
Title: Re: -={ Challenge }=- Group List by Number
Post by: reltro on March 10, 2014, 04:55:20 PM
Hey...
maybe like this?

Code: [Select]
(defun-q GroupByNum (n L / F R)
    nil
    (if (not (setq F (cadr (assoc n (eval (nth 1 GroupByNum))))))
        (setq GroupByNum
            (subst
                (list 'quote
                    (cons
                        (list
                            n
                            (setq F
                                (vl-list*
                                    'list
                                    (quote (car L))
                                    (repeat (- n 1)
                                        (setq F
                                            (cons
                                                (quote (car (setq L (cdr L))))
                                                F
                                            )
                                        )
                                    )
                                )
                            )
                        )
                        (eval (nth 1 GroupByNum))
                    )
                )
                (nth 1 GroupByNum)
                GroupByNum
            )
        )
    )
   
    (while L
        (setq R (cons (eval F) R)
              L (cdr L)
        )
    )
   
    (reverse R)
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: chlh_jd on March 12, 2014, 08:53:53 AM
Hey...
maybe like this?

Code: [Select]
(defun-q GroupByNum (n L / F R)
    nil
    (if (not (setq F (cadr (assoc n (eval (nth 1 GroupByNum))))))
        (setq GroupByNum
            (subst
                (list 'quote
                    (cons
                        (list
                            n
                            (setq F
                                (vl-list*
                                    'list
                                    (quote (car L))
                                    (repeat (- n 1)
                                        (setq F
                                            (cons
                                                (quote (car (setq L (cdr L))))
                                                F
                                            )
                                        )
                                    )
                                )
                            )
                        )
                        (eval (nth 1 GroupByNum))
                    )
                )
                (nth 1 GroupByNum)
                GroupByNum
            )
        )
    )
   
    (while L
        (setq R (cons (eval F) R)
              L (cdr L)
        )
    )
   
    (reverse R)
)
Oh , another beautiful codes which is difficult to understand .
It also open my eyes , thank you , although it is slower .
Title: Re: -={ Challenge }=- Group List by Number
Post by: Marc'Antonio Alessi on March 12, 2014, 04:24:24 PM
another attempt
Code: [Select]
(defun ALE_GroupByNum3 (l n / a b x)
  (while l
    (repeat (/ n 10)
      (setq
        a (append a (list
            (car l) (cadr l) (caddr l) (cadddr l) (cadddr (cdr l)) (cadddr (cddr l))
            (cadddr (cdddr l)) (cadddr (cddddr l)) (cadddr (cddddr (cdr l)))
            (cadddr (cddddr (cddr l)))
          )         )
        l (cddddr(cddddr(cddr l)))
      )
    )
    (if (zerop (setq x (rem n 10)))
      (setq b (cons a b)  a nil)
      (setq b (cons (append a (First09 x l)) b)   l (Cdr09 x l)  a nil)
    )
  )
  (reverse b)
)
(defun First09 (n l)   
  (cond
    ( (eq 1 n) (list (car l))                                                )
    ( (eq 2 n) (list (car l) (cadr l))                                       )
    ( (eq 3 n) (list (car l) (cadr l) (caddr l))                             )
    ( (eq 4 n) (list (car l) (cadr l) (caddr l) (cadddr l))                  )
    ( (eq 5 n) (list (car l) (cadr l) (caddr l) (cadddr l) (cadddr (cdr l))) )
    ( (eq 6 n)
      (list (car l) (cadr l) (caddr l) (cadddr l) (cadddr (cdr l)) (cadddr (cddr l)))
    )
    ( (eq 7 n)
      (list
        (car l) (cadr l) (caddr l) (cadddr l) (cadddr (cdr l))
        (cadddr (cddr l)) (cadddr (cdddr l))
      )
    )
    ( (eq 8 n)
      (list
        (car l) (cadr l) (caddr l) (cadddr l) (cadddr (cdr l))
        (cadddr (cddr l)) (cadddr (cdddr l)) (cadddr (cddddr l))
      )
    )
    ( (eq 9 n)
      (list
        (car l) (cadr l) (caddr l) (cadddr l) (cadddr (cdr l)) (cadddr (cddr l))
        (cadddr (cdddr l)) (cadddr (cddddr l)) (cadddr (cddddr (cdr l)))
      )
    )
  )
)
(defun Cdr09 (n l)   
  (cond
    ( (eq 1 n) (cdr l) )
    ( (eq 2 n) (cddr l) )
    ( (eq 3 n) (cdddr l) )
    ( (eq 4 n) (cddddr l) )
    ( (eq 5 n) (cddddr(cdr l)) )
    ( (eq 6 n) (cddddr(cddr l)) )
    ( (eq 7 n) (cddddr(cdddr l)) )
    ( (eq 8 n) (cddddr(cddddr l)) )
    ( (eq 9 n) (cddddr(cddddr(cdr l))) )
  )
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Marc'Antonio Alessi on March 13, 2014, 01:50:58 PM
Again, not faster!  :realmad:
Code: [Select]
(defun ALE_GroupByNum_L (l n / b f1 f2)
  (setq f1 (strcat "first" (itoa n))  f2 (strcat "cdr" (itoa n)))
  (or
    (eval (read f1))
    (progn
      ( (lambda (/ TmpCod OutLst NumElm)
          (setq NumElm n  OutLst nil)
          (repeat NumElm
            (setq TmpCod 'l)
            (repeat (/ (1- NumElm) 4) (setq TmpCod (cons 'cddddr (list TmpCod))))
            (repeat (rem (1- NumElm) 4) (setq TmpCod (cons 'cdr (list TmpCod))))
            (setq TmpCod (cons 'car (list TmpCod)) NumElm (1- NumElm)  OutLst  (cons TmpCod OutLst))
          )
          (eval
            (cons 'defun (cons (read f1) (cons '(l) (list (cons 'list OutLst)))))
          )
        )
      ) 
      ( (lambda (/ TmpCod)
          (setq TmpCod 'l)
          (repeat (/ n 4) (setq TmpCod (cons 'cddddr (list TmpCod))))
          (repeat (rem n 4) (setq TmpCod (cons 'cdr (list TmpCod))))
          (eval
            (cons 'defun (cons (read f2) (cons '(l) (list TmpCod))))
          )
        )
      )
    )
  )
  (while l
    (setq b (cons ((eval (read f1)) l) b)  l ((eval (read f2)) l))
  )
  (reverse b)
)
Title: Re: -={ Challenge }=- Group List by Number
Post by: Marc'Antonio Alessi on March 13, 2014, 04:10:48 PM
better... :)
Code: [Select]
(defun ALE_GroupByNum_L5 (l n / a f1 f2)
  (or
    (setq f1 (eval (read (strcat "First" (itoa n)))) f2 (eval (read (strcat "cdr" (itoa n)))))
    (progn
      (setq f1 (strcat "First" (itoa n))  f2 (strcat "cdr" (itoa n)))
      ( (lambda (/ TmpCod OutLst NumElm TmpNum)
          (setq NumElm n  OutLst nil)
          (repeat NumElm
            (setq TmpCod 'l  NumElm (1- NumElm)  TmpNum NumElm)
            (repeat (/ TmpNum 4)                       (setq TmpCod (cons 'cddddr (list TmpCod))))
            (repeat (/ (setq TmpNum (rem TmpNum 4)) 3) (setq TmpCod (cons 'cdddr  (list TmpCod))))
            (repeat (/ (setq TmpNum (rem TmpNum 3)) 2) (setq TmpCod (cons 'cddr   (list TmpCod))))
            (repeat (rem TmpNum 2) (setq TmpCod (cons 'cdr (list TmpCod))))
            (setq TmpCod (cons 'car (list TmpCod))   OutLst  (cons TmpCod OutLst))
          )
          (setq f1 (eval (eval (cons 'defun (cons (read f1) (cons '(l) (list (cons 'list OutLst))))))))
        )
      ) 
      ( (lambda (/ TmpCod)
          (setq TmpCod 'l)
          (repeat (/ n 4)                 (setq TmpCod (cons 'cddddr (list TmpCod))))
          (repeat (/ (setq n (rem n 4)) 3)(setq TmpCod (cons 'cdddr  (list TmpCod))))
          (repeat (/ (setq n (rem n 3)) 2)(setq TmpCod (cons 'cddr   (list TmpCod))))
          (repeat (rem n 2)               (setq TmpCod (cons 'cdr    (list TmpCod))))
          (setq f2 (eval (eval (cons 'defun (cons (read f2) (cons '(l) (list TmpCod)))))))
        )
      )
    )
  )
  (while (setq a (cons (f1 l) a)  l (f2 l)))
  (reverse a)
)