Author Topic: Replace nth member of a list  (Read 23865 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #45 on: December 31, 2006, 01:25:07 PM »
I never saw, how you use FUNCTION...
Wished to show you a good example!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10400
Re: Replace nth member of a list
« Reply #46 on: December 31, 2006, 01:58:19 PM »
No, I was remarking how your use of FUNCTION made the routine faster when compiled.
I should have been more clear in my statement.
I never use the (Function but always use '(   Too lazy to type function.
It appears to only be a benefit when compiled though. Has that been your experance?

« Last Edit: December 31, 2006, 02:01:29 PM 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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10170
Re: Replace nth member of a list
« Reply #47 on: December 31, 2006, 02:36:56 PM »
no
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10400
Re: Replace nth member of a list
« Reply #48 on: December 31, 2006, 02:40:18 PM »
John, you have some examples where function preformed better?
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #49 on: December 31, 2006, 02:43:31 PM »
Has that been your experience?

Yes, i read help for function...
I always use a full name (almost always)... :)

JohnK

  • Administrator
  • Seagull
  • Posts: 10170
Re: Replace nth member of a list
« Reply #50 on: December 31, 2006, 05:24:26 PM »
Not on me but ive done some testing on an application im creating for my company right now; Its about 850 lines of solid code and I tested several diff methods. However I supose we could whip one up. BUT I think you should be warned that just using one ``improvment'' in your test code inst going to matter much, you need to take other steps as well to ensure faster code.

Code: [Select]
(setq my-lst '(1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
               1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
               1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0))
(benchmark
 '(
    ( (lambda ( lst )
       (mapcar
        (function
         1+) lst))
      my-lst)
    ( (lambda ( lst )
       (mapcar '1+ lst))
      my-lst)
   )
 )

Elapsed milliseconds / relative speed for 8192 iteration(s):

    ((LAMBDA (LST) (MAPCAR (FUNCTION 1+)...).....1031 / 1.05 <fastest>
    ((LAMBDA (LST) (MAPCAR (QUOTE 1+) LS...).....1078 / 1.00 <slowest>

Command:  <Osnap off>
Command: (benchmark
(_>  '(
('(_>          ( (lambda ( lst )
('(((_>             (mapcar
('((((_>              (function
('(((((_>               1+) lst))
('((_>            my-lst)
('(_>          ( (lambda ( lst )
('(((_>             (mapcar '1+ lst))
('((_>            my-lst)
('(_>
('(_>
('(_>   )
(_>  )
Elapsed milliseconds / relative speed for 8192 iteration(s):

    ((LAMBDA (LST) (MAPCAR (FUNCTION 1+)...).....1015 / 1.06 <fastest>
    ((LAMBDA (LST) (MAPCAR (QUOTE 1+) LS...).....1078 / 1.00 <slowest>

Command: (benchmark
(_>  '(
('(_>     ( (lambda ( lst )
('(((_>        (mapcar
('((((_>         (function
('(((((_>          1+) lst))
('((_>       my-lst)
('(_>     ( (lambda ( lst )
('(((_>        (mapcar '1+ lst))
('((_>       my-lst)
('(_>    )
(_>  )
Elapsed milliseconds / relative speed for 8192 iteration(s):

    ((LAMBDA (LST) (MAPCAR (FUNCTION 1+)...).....1031 / 1.03 <fastest>
    ((LAMBDA (LST) (MAPCAR (QUOTE 1+) LS...).....1062 / 1.00 <slowest>
« Last Edit: January 01, 2007, 09:27:49 AM by Se7en »
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #51 on: December 31, 2006, 07:55:59 PM »
If you do not compile the program it is possible to not use (function...

FUNCTION - helps to optimize the program at compilation.
In other cases from it there is not enough sense.

PS. I compile all the projects!

JohnK

  • Administrator
  • Seagull
  • Posts: 10170
Re: Replace nth member of a list
« Reply #52 on: January 01, 2007, 12:05:26 AM »
There is something really goofy going on here. ...I know you cant really test to see if a proced is faster by just a timed test, but this is just plain weird.

Code: [Select]
(progn
 (defun add-one-to-items  ( lst )
  (mapcar (function 1+) lst))

 (defun add-one-to-items--ver2 ( lst )
  (
   (lambda ( lst )
    (mapcar (function 1+) lst))
   lst))

 (defun add-one-to-items--ver3  ( lst )
  (mapcar '1+ lst))

 (defun add-one-to-items--ver4 ( lst )
  (
   (lambda ( lst )
    (mapcar '1+ lst))
   lst))

 (setq my-lst '(1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
                1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
                1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0))
 
 (benchmark
  '(
          (add-one-to-items my-lst)
          (add-one-to-items--ver2 my-lst)
          (add-one-to-items--ver3 my-lst)
          (add-one-to-items--ver4 my-lst)
    )
  )
 )

Elapsed milliseconds / relative speed for 16384 iteration(s):

    (ADD-ONE-TO-ITEMS--VER3 MY-LST).....1719 / 1.03 <fastest>
    (ADD-ONE-TO-ITEMS--VER4 MY-LST).....1719 / 1.03
    (ADD-ONE-TO-ITEMS--VER2 MY-LST).....1750 / 1.01
    (ADD-ONE-TO-ITEMS MY-LST)...........1765 / 1.00 <slowest>

Elapsed milliseconds / relative speed for 16384 iteration(s):

    (ADD-ONE-TO-ITEMS--VER2 MY-LST).....1750 / 1.01 <fastest>
    (ADD-ONE-TO-ITEMS--VER3 MY-LST).....1750 / 1.01
    (ADD-ONE-TO-ITEMS--VER4 MY-LST).....1750 / 1.01
    (ADD-ONE-TO-ITEMS MY-LST)...........1766 / 1.00 <slowest>
2 & 4 should be grouped together or 1 & 3 should... ?!

:?:
« Last Edit: January 01, 2007, 09:28:04 AM by Se7en »
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16897
  • Superior Stupidity at its best
Re: Replace nth member of a list
« Reply #53 on: January 01, 2007, 01:23:41 AM »
I don't mean to be a bug ... but could you guyz please use code tags around code segments ... I dunno why it bothers me so much .. but it does ...
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

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Replace nth member of a list
« Reply #54 on: December 20, 2012, 02:48:47 AM »
Sorry to revive this ancient thread, just figured my version seems to outperform all the others in nearly every instance
Code - Auto/Visual Lisp: [Select]
  1. (defun IB:Replace-Nth  (Source Index Value / Result)
  2.   (if (< -1 Index (length Source))
  3.     (if (<= Index (/ (length Source) 2))
  4.       (progn (repeat (/ Index 4)
  5.                (setq Result (cons (cadddr Source)
  6.                                   (cons (caddr Source) (cons (cadr Source) (cons (car Source) Result))))
  7.                      Source (cddddr Source)))
  8.              (repeat (rem Index 4)
  9.                (setq Result (cons (car Source) Result)
  10.                      Source (cdr Source)))
  11.              (append (reverse Result) (cons Value (cdr Source))))
  12.       (reverse (IB:Replace-Nth (reverse Source) (- (length Source) Index) Value)))
  13.     Source))
And the results:
Code: [Select]
I = 50
Benchmarking ........ done for 8192 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(REPLASE_1 *LIST@ I A)                        8192      1170      1170     13.01
(IB:REPLACE-NTH *LIST@ I A)                   8192      1248      1248     12.20
(REPLACE_CAB *LIST@ I A)                      2048      1965      7860      1.94
(REPLASE *LIST@ I A)                          1024      1077      8616      1.77
(SWAPNTH *LIST@ I A)                          1024      1325     10600      1.44
(REPLASE_2 *LIST@ I A)                        1024      1732     13856      1.10
(REPLACE_DA A I *LIST@)                       1024      1842     14736      1.03
(NTH-REPLACE I A *LIST@)                      1024      1903     15224      1.00
--------------------------------------------------------------------------------

I = 150
Benchmarking ........ done for 4096 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   4096      1170      1170      8.43
(REPLASE_1 *LIST@ I A)                        4096      1545      1545      6.38
(REPLACE_CAB *LIST@ I A)                      1024      1217      4868      2.03
(REPLASE *LIST@ I A)                          1024      1325      5300      1.86
(REPLASE_2 *LIST@ I A)                        1024      1762      7048      1.40
(SWAPNTH *LIST@ I A)                          1024      1888      7552      1.31
(REPLACE_DA A I *LIST@)                        512      1202      9616      1.03
(NTH-REPLACE I A *LIST@)                       512      1233      9864      1.00
--------------------------------------------------------------------------------

I = 250
Benchmarking ........ done for 4096 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   4096      1653      1653      5.96
(REPLASE_1 *LIST@ I A)                        2048      1232      2464      4.00
(REPLACE_CAB *LIST@ I A)                      1024      1201      4804      2.05
(REPLASE *LIST@ I A)                          1024      1341      5364      1.84
(REPLASE_2 *LIST@ I A)                        1024      1733      6932      1.42
(SWAPNTH *LIST@ I A)                           512      1076      8608      1.14
(NTH-REPLACE I A *LIST@)                       512      1219      9752      1.01
(REPLACE_DA A I *LIST@)                        512      1232      9856      1.00
--------------------------------------------------------------------------------

I = 350
Benchmarking ........ done for 2048 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   2048      1014      1014      4.99
(REPLASE_1 *LIST@ I A)                        2048      1700      1700      2.98
(REPLACE_CAB *LIST@ I A)                      1024      1217      2434      2.08
(REPLASE *LIST@ I A)                          1024      1357      2714      1.86
(REPLASE_2 *LIST@ I A)                        1024      1762      3524      1.44
(SWAPNTH *LIST@ I A)                           512      1186      4744      1.07
(REPLACE_DA A I *LIST@)                        512      1232      4928      1.03
(NTH-REPLACE I A *LIST@)                       512      1265      5060      1.00
--------------------------------------------------------------------------------

I = 450
Benchmarking ........ done for 2048 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   2048      1184      1184      4.58
(REPLASE_1 *LIST@ I A)                        1024      1061      2122      2.56
(REPLACE_CAB *LIST@ I A)                      1024      1201      2402      2.26
(REPLASE *LIST@ I A)                          1024      1342      2684      2.02
(REPLASE_2 *LIST@ I A)                        1024      1794      3588      1.51
(REPLACE_DA A I *LIST@)                        512      1186      4744      1.14
(NTH-REPLACE I A *LIST@)                       512      1218      4872      1.11
(SWAPNTH *LIST@ I A)                           512      1357      5428      1.00
--------------------------------------------------------------------------------

I = 550
Benchmarking ........ done for 2048 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   2048      1436      1436      4.26
(REPLACE_CAB *LIST@ I A)                      1024      1200      2400      2.55
(REPLASE_1 *LIST@ I A)                        1024      1264      2528      2.42
(REPLASE *LIST@ I A)                          1024      1340      2680      2.28
(REPLASE_2 *LIST@ I A)                        1024      1748      3496      1.75
(REPLACE_DA A I *LIST@)                        512      1233      4932      1.24
(NTH-REPLACE I A *LIST@)                       512      1248      4992      1.23
(SWAPNTH *LIST@ I A)                           512      1529      6116      1.00
--------------------------------------------------------------------------------

I = 650
Benchmarking ........ done for 2048 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   2048      1653      1653      4.23
(REPLACE_CAB *LIST@ I A)                      1024      1232      2464      2.84
(REPLASE *LIST@ I A)                          1024      1310      2620      2.67
(REPLASE_1 *LIST@ I A)                        1024      1514      3028      2.31
(REPLASE_2 *LIST@ I A)                        1024      1764      3528      1.98
(REPLACE_DA A I *LIST@)                        512      1232      4928      1.42
(NTH-REPLACE I A *LIST@)                       512      1232      4928      1.42
(SWAPNTH *LIST@ I A)                           512      1747      6988      1.00
--------------------------------------------------------------------------------

I = 750
Benchmarking ........ done for 2048 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   2048      1888      1888      4.17
(REPLACE_CAB *LIST@ I A)                      1024      1233      2466      3.19
(REPLASE *LIST@ I A)                          1024      1358      2716      2.90
(REPLASE_1 *LIST@ I A)                        1024      1717      3434      2.29
(REPLASE_2 *LIST@ I A)                        1024      1733      3466      2.27
(NTH-REPLACE I A *LIST@)                       512      1247      4988      1.58
(REPLACE_DA A I *LIST@)                        512      1248      4992      1.58
(SWAPNTH *LIST@ I A)                           512      1966      7864      1.00
--------------------------------------------------------------------------------

I = 850
Benchmarking ........ done for 2048 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   2048      2029      2029      4.37
(REPLACE_CAB *LIST@ I A)                      1024      1201      2402      3.69
(REPLASE *LIST@ I A)                          1024      1310      2620      3.38
(REPLASE_2 *LIST@ I A)                        1024      1794      3588      2.47
(REPLASE_1 *LIST@ I A)                        1024      1965      3930      2.26
(REPLACE_DA A I *LIST@)                        512      1217      4868      1.82
(NTH-REPLACE I A *LIST@)                       512      1248      4992      1.78
(SWAPNTH *LIST@ I A)                           256      1108      8864      1.00
--------------------------------------------------------------------------------

I = 950
Benchmarking ........ done for 1024 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(IB:REPLACE-NTH *LIST@ I A)                   1024      1155      1155      4.32
(REPLACE_CAB *LIST@ I A)                      1024      1217      1217      4.10
(REPLASE *LIST@ I A)                          1024      1295      1295      3.85
(REPLASE_2 *LIST@ I A)                        1024      1778      1778      2.81
(REPLASE_1 *LIST@ I A)                         512      1092      2184      2.29
(NTH-REPLACE I A *LIST@)                       512      1183      2366      2.11
(REPLACE_DA A I *LIST@)                        512      1233      2466      2.02
(SWAPNTH *LIST@ I A)                           256      1248      4992      1.00
--------------------------------------------------------------------------------1050
_$
« Last Edit: December 20, 2012, 02:54:23 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10400
Re: Replace nth member of a list
« Reply #55 on: December 20, 2012, 01:15:46 PM »
Where have you been for the past 6 years?  :evil:

Just kidding, looks like great performance in your test.
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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Replace nth member of a list
« Reply #56 on: December 21, 2012, 12:34:23 AM »
Yeah, wasn't on the Swamp that time. Was mostly hanging out on AutoDesk & Augi, when I had time (was working on this project):

So didn't have a lot of time to spare.

Anyhow, the principle of mine was actually from an algorithm I saw Elpanov Evgeniy use in another routine.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10400
Re: Replace nth member of a list
« Reply #57 on: December 21, 2012, 07:54:03 AM »
Anyhow, the principle of mine was actually from an algorithm I saw Elpanov Evgeniy use in another routine.

Ah yes, a lot of acorns here.  8-)
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.

Lee Mac

  • Seagull
  • Posts: 12726
  • London, England
Re: Replace nth member of a list
« Reply #58 on: December 21, 2012, 06:38:02 PM »
@Irneb, for a little extra concision, this:
Code - Auto/Visual Lisp: [Select]
  1. (cons (cadddr Source) (cons (caddr Source) (cons (cadr Source) (cons (car Source) Result))))

could become:
Code - Auto/Visual Lisp: [Select]
  1. (vl-list* (cadddr Source) (caddr Source) (cadr Source) (car Source) Result)

I'm unsure of any performance benefit however.



ETA: After a quick test, it seems there is in fact a marginal performance benefit:

Code - Auto/Visual Lisp: [Select]
  1. (defun cons-it ( l / r )
  2.     (while l
  3.         (setq r (cons (cadddr l) (cons (caddr l) (cons (cadr l) (cons (car l) r))))
  4.               l (cddddr l)
  5.         )
  6.     )
  7.     (reverse r)
  8. )
  9.  
  10. (defun vl-list*-it ( l / r )
  11.     (while l
  12.         (setq r (vl-list* (cadddr l) (caddr l) (cadr l) (car l) r)
  13.               l (cddddr l)
  14.         )
  15.     )
  16.     (reverse r)
  17. )

Code - Auto/Visual Lisp: [Select]
  1. _$ (setq i 1)
  2. 1
  3. _$ (repeat 100 (setq l (cons i l) i (1+ i)))
  4. 101
  5. _$ (length l)
  6. 100
  7.  
  8. Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):
  9.  
  10.     (VL-LIST*-IT L).....1264 / 1.20 <fastest>
  11.     (CONS-IT L).........1513 / 1.00 <slowest>

Code - Auto/Visual Lisp: [Select]
  1. _$ (setq i 1)
  2. 1
  3. _$ (repeat 1000 (setq l (cons i l) i (1+ i)))
  4. 1001
  5. _$ (length l)
  6. 1000
  7.  
  8. Benchmarking ..............Elapsed milliseconds / relative speed for 2048 iteration(s):
  9.  
  10.     (VL-LIST*-IT L).....1107 / 1.25 <fastest>
  11.     (CONS-IT L).........1389 / 1.00 <slowest>
« Last Edit: December 22, 2012, 08:54:53 AM by Lee Mac »

chlh_jd

  • Guest
Re: Replace nth member of a list
« Reply #59 on: December 24, 2012, 12:39:49 AM »
All Nice codes  :-)
Here's my version
Code: [Select]
;; written by qj-chen
;; Edited by GSLS(SS)
(defun ch-lst (new i lst / j len fst mid)
  (if (/= (type i) (quote list))
    (cond
      ((not (listp lst))
       lst)
      ((minusp i)
       lst
      )
      ((> i (setq len (length lst)))
       lst
      )
      ((> i (/ len 2))
       (reverse (ch-lst new (1- (- len i)) (reverse lst)))
      )
      (t
       (append
(progn
   (setq fst nil)
   (repeat (rem i 4)
     (setq fst (cons (car lst) fst)
   lst (cdr lst)
     )
   )
   (repeat (/ i 4)
     (setq fst (cons (cadddr lst)
     (cons (caddr lst)
   (cons
     (cadr lst)
     (cons
       (car lst)
       fst
     )
   )
     )
       )
   lst (cddddr lst)
     )
   )
   (reverse fst)
)
(list new)
(cdr lst)
       )
      )
    )
    (progn
      (setq j (cadr i)
    i (car i)
      )
      (if j
(progn
  (setq mid (nth i lst))
  (setq mid (ch-lst new j mid))
  (ch-lst mid i lst)
)
(ch-lst new i lst)
      )
    )
  )
)
E.g.
Code: [Select]
(ch-lst 3 2 '(1 1 1 1 1 1 1)) --> '(1 1 3 1 1 1 1)
(ch-lst 3 '(2 2) '((1 1 1 1 1 1 ) (1 1 1 1 1 1 )  (1 1 1 1 1 1)  (1 1 1 1 1 1)  (1 1 1 1 1 1)  (1 1 1 1 1 1) ))
     -->' ((1 1 1 1 1 1)  (1 1 1 1 1 1)  (1 1 3 1 1 1)  (1 1 1 1 1 1)  (1 1 1 1 1 1)  (1 1 1 1 1 1))
Remove nth
Code: [Select]
(defun remove-nth (i lst / j len fst)
  (if (/= (type i) (quote list))
    (cond
      ((or (minusp i) (> i (1- (setq len (length lst)))))
       lst
      )     
      ((> i (/ len 2))
       (reverse (remove-nth (1- (- len i)) (reverse lst)))
      )
      (t
       (append
(progn
   (setq fst nil)
   (repeat (rem i 4)
     (setq fst (cons (car lst) fst)
   lst (cdr lst)
     )
   )
   (repeat (/ i 4)
     (setq fst (cons (cadddr lst)
     (cons (caddr lst)
   (cons
     (cadr lst)
     (cons
       (car lst)
       fst
     )
   )
     )
       )
   lst (cddddr lst)
     )
   )
   (reverse fst)
)
(cdr lst)
       )
      )
    )
    (progn
      (setq j (cadr i)
    i (car i)
      )
      (if j
(mapcar (function (lambda (x) (remove-nth j x))) (remove-nth i lst))
(remove-nth i lst)
      )
    )
  )
)
e.g.
Code: [Select]
(remove-nth 2 '(1 1 3 1 1 1 1)) --> '(1 1  1 1 1 1)
(remove-nth  '(2 2) ' ((1 1 1 1 1 1)  (1 1 1 1 1 1)  (1 1 3 1 1 1)  (1 1 1 1 1 1)  (1 1 1 1 1 1)  (1 1 1 1 1 1)))
     -->((1 1 1 1 1)  (1 1 1 1 1)  (1 1 1 1 1)  (1 1 1 1 1) (1 1 1 1 1))