Author Topic: Grid point list conversion  (Read 7873 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Grid point list conversion
« on: September 11, 2020, 03:17:32 PM »
Hey guys,
Haven't been mapping lists for a while and now I'm banging my head on this one -

The following matrix list represents the grid point coordinates in the attached image:
Code: [Select]
'(
  ("1-1" "1-2" "1-3" "1-4" "1-5" "1-6" "1-7")
  ("2-1" "2-2" "2-3" "2-4" "2-5" "2-6" "2-7")
  ("3-1" "3-2" "3-3" "3-4" "3-5" "3-6" "3-7")
  ("4-1" "4-2" "4-3" "4-4" "4-5" "4-6" "4-7")
)

I need some help in writing a subfoo to convert it like so:
Code: [Select]
'(
  ("1-1" "1-2" "2-1" "2-2")
  ("1-2" "1-3" "2-2" "2-3")
  ("1-3" "1-4" "2-3" "2-4")
  ("1-4" "1-5" "2-4" "2-5")
  ("1-5" "1-6" "2-5" "2-6")
  ("1-6" "1-7" "2-6" "2-7")
  ("2-1" "2-2" "3-1" "3-2")
  ("2-2" "2-3" "3-2" "3-3")
  ("2-3" "2-4" "3-3" "3-4")
  ("2-4" "2-5" "3-4" "3-5")
  ("2-5" "2-6" "3-5" "3-6")
  ("2-6" "2-7" "3-6" "3-7")
  ("3-1" "3-2" "4-1" "4-2")
  ("3-2" "3-3" "4-2" "4-3")
  ("3-3" "3-4" "4-3" "4-4")
  ("3-4" "3-5" "4-4" "4-5")
  ("3-5" "3-6" "4-5" "4-6")
  ("3-6" "3-7" "4-6" "4-7")
)

The items in the new list represent the rectangular sectors of the whole grid.

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #1 on: September 11, 2020, 04:31:26 PM »
tired brain ... quick & dirty ... no hand holding ... assumes non jagged nested lists ... forgive me if it doesn't achieve what you want but it's been so long since I played ...

Code: [Select]
(defun subfoo ( lst / r a b c d )
    (repeat (1- (length lst))
        (repeat (1- (length (car (mapcar 'set '(a b) lst))))
            (setq r (cons (append (mapcar 'set '(c d) a) (mapcar 'set '(c d) b)) r))
            (mapcar 'set '(a b) (mapcar 'cdr (list a b)))
        )
        (setq lst (cdr lst))
    )
    (reverse r)
)

(subfoo yourlist)

(   ("1-1" "1-2" "2-1" "2-2")
    ("1-2" "1-3" "2-2" "2-3")
    ("1-3" "1-4" "2-3" "2-4")
    ("1-4" "1-5" "2-4" "2-5")
    ("1-5" "1-6" "2-5" "2-6")
    ("1-6" "1-7" "2-6" "2-7")
    ("2-1" "2-2" "3-1" "3-2")
    ("2-2" "2-3" "3-2" "3-3")
    ("2-3" "2-4" "3-3" "3-4")
    ("2-4" "2-5" "3-4" "3-5")
    ("2-5" "2-6" "3-5" "3-6")
    ("2-6" "2-7" "3-6" "3-7")
    ("3-1" "3-2" "4-1" "4-2")
    ("3-2" "3-3" "4-2" "4-3")
    ("3-3" "3-4" "4-3" "4-4")
    ("3-4" "3-5" "4-4" "4-5")
    ("3-5" "3-6" "4-5" "4-6")
    ("3-6" "3-7" "4-6" "4-7")
)


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

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #2 on: September 11, 2020, 04:53:21 PM »
Well, MP was faster and more elegant, but here is mine...

Code: [Select]
(defun c:recunfoldmatrix ( / matrix-n-m rec n m )

  (defun matrix-n-m ( n m / nn mm itm row mat )
    (setq nn 0)
    (repeat n
      (setq nn (1+ nn) mm 0)
      (repeat m
        (setq mm (1+ mm))
        (setq itm (strcat (itoa nn) "-" (itoa mm)))
        (setq row (cons itm row))
      )
      (setq mat (cons (reverse row) mat) row nil)
    )
    (reverse mat)
  )

  (defun rec ( mat / k itm1 itm2 kk lst )
    (setq k -1)
    (repeat (length mat)
      (setq k (1+ k))
      (setq itm1
        (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
          (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth k mat)) kk)) (nth k mat))) (nth k mat))
        )
      )
      (setq kk nil)
      (setq itm2
        (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
          (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth (1+ k) mat)) kk)) (nth (1+ k) mat))) (nth (1+ k) mat))
        )
      )
      (setq kk nil)
      (setq itm (mapcar '(lambda ( a b ) (append a b)) itm1 itm2))
      (setq lst (cons itm lst))
    )
    (apply 'append (reverse lst))
  )

  (initget 7)
  (setq n (getint "\nSpecify number of rows of matrix : "))
  (initget 7)
  (setq m (getint "\nSpecify number of columns of matrix : "))
  (princ "\n")
  (prin1 (rec (matrix-n-m n m)))
  (princ)
)

;|
Command: RECUNFOLDMATRIX

Specify number of rows of matrix : 4

Specify number of columns of matrix : 7

(("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("2-1" "2-2" "3-1" "3-2") ("2-2" "2-3" "3-2" "3-3") ("2-3" "2-4" "3-3" "3-4") ("2-4" "2-5" "3-4" "3-5") ("2-5" "2-6" "3-5" "3-6") ("2-6" "2-7" "3-6" "3-7") ("3-1" "3-2" "4-1" "4-2") ("3-2" "3-3" "4-2" "4-3") ("3-3" "3-4" "4-3" "4-4") ("3-4" "3-5" "4-4" "4-5") ("3-5" "3-6" "4-5" "4-6") ("3-6" "3-7" "4-6" "4-7"))
|;
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #3 on: September 11, 2020, 05:24:37 PM »
Code: [Select]
(defun f (lst)
  (setq lst (mapcar (function (lambda (e) (mapcar 'list e (cdr e)))) lst))
  (apply 'append (mapcar (function (lambda (e1 e2) (mapcar 'append e1 e2))) lst (cdr lst)))
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #4 on: September 11, 2020, 05:24:58 PM »
Won't last long -- once VovKa and Lee post it will look like it was written by Clumsy Carp ...  :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #5 on: September 11, 2020, 05:26:09 PM »
OMG check out the posting times of the last 2 posts.  :lol:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Grid point list conversion
« Reply #6 on: September 11, 2020, 05:26:20 PM »
Here's another for fun :)
Code - Auto/Visual Lisp: [Select]
  1. (defun _rjpfoo (l / a b r)
  2.   (while (cadr l)
  3.     (setq a (car l)
  4.           b (cadr l)
  5.           l (cdr l)
  6.     )
  7.     (while (cadr a)
  8.       (setq r (cons (list (car a) (cadr a) (car b) (cadr b)) r)
  9.             a (cdr a)
  10.             b (cdr b)
  11.       )
  12.     )
  13.   )
  14.   (reverse r)
  15. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #7 on: September 11, 2020, 05:32:15 PM »
indeed - great participation all around - especially given it's a Friday afternoon (in the Americas) - fun thread !
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #8 on: September 11, 2020, 05:38:18 PM »
especially given it's a Friday afternoon (in the Americas)
and even more especially it's half past midnight in Ukraine
omg what am i doing here :)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #9 on: September 11, 2020, 05:42:50 PM »
omg what am i doing here :)

lol, nerdosis terminosis  :-D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #10 on: September 11, 2020, 05:47:52 PM »
nerdosis terminosis
wow, google just returned nil  :wideeyed2:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #11 on: September 11, 2020, 05:49:54 PM »
Made up disease name: one who has a terminal case of being a nerd. 0.o
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #12 on: September 11, 2020, 06:05:43 PM »
one day we could speak a little Latin
just like good old patricians ;)

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Grid point list conversion
« Reply #13 on: September 11, 2020, 07:10:49 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun square (lst)
  2.     (mapcar
  3.      '(lambda (a b)
  4.         (mapcar 'list a (cdr a) b (cdr b))
  5.       )
  6.       lst
  7.       (cdr lst)
  8.     )
  9.   )
  10. )

bruno_vdh

  • Newt
  • Posts: 107
Re: Grid point list conversion
« Reply #14 on: September 11, 2020, 08:39:18 PM »
Hi,
In the same spirit as the solution given by stephan ...
Code - Auto/Visual Lisp: [Select]
  1. (defun f (l)
  2.   (if (cdr l)
  3.     (append (mapcar 'list (car l) (cdar l) (cadr l) (cdadr l))
  4.             (f (cdr l)))))
« Last Edit: September 11, 2020, 08:44:35 PM by bruno_vdh »

wizman

  • Bull Frog
  • Posts: 290
Re: Grid point list conversion
« Reply #15 on: September 12, 2020, 12:32:35 PM »
Here's a rusty attempt:

Code: [Select]


(defun foo (a)
  (list
    (car a)
    (cadr a)
  )
)

(defun rec (w / y)
  (if (cdadr w)
    (progn
      (Setq y (foo w)
    z (cons (mapcar 'foo y)
    z
      )
      )
      (rec (mapcar 'cdr y))
      (rec (cdr w))
    )
  )
)

(defun rec2 (x / z)
  (rec x)
  (reverse
    (mapcar '(lambda (x)
       (apply 'append x)
     )
    z
    )
  )
)


(rec2 '(
("1-1" "1-2" "1-3" "1-4" "1-5" "1-6" "1-7")
("2-1" "2-2" "2-3" "2-4" "2-5" "2-6" "2-7")
("3-1" "3-2" "3-3" "3-4" "3-5" "3-6" "3-7")
("4-1" "4-2" "4-3" "4-4" "4-5" "4-6" "4-7")
       )
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Grid point list conversion
« Reply #16 on: September 14, 2020, 12:41:07 PM »
Benchmarks
Quote
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (SQUARE L).......1921 / 8.52 <fastest>
    (_RJPFOO L)......2094 / 7.81
    (F_BRUNO L)......2984 / 5.48
    (F L)............3141 / 5.21
    (REC2 L)........13516 / 1.21
    (SUBFOO L)......16359 / 1.00 <slowest>

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #17 on: September 14, 2020, 01:44:09 PM »
awesome
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #18 on: September 14, 2020, 02:24:21 PM »
I would say just "some" - on Serbian... OP haven't replied in any way saying thanks or something equal to anyone participated... I don't know are replies useful to him, but IMHO not reacting to request proposed in first post is humiliating behaviour for all that wanted to contribute... And timings of sub functions - benchmarking for this task are the least meaningful. I'd say that for a matrix 1000x1000 for normal PC it would take around 1 sec for computation with any of proposed subs... And 1000x1000 matrix is IMHO monkey bussines for any kind of situation OP may be facing in real life situation.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #19 on: September 14, 2020, 06:06:20 PM »
... OP haven't replied in any way saying thanks or something equal to anyone participated... I don't know are replies useful to him, but IMHO not reacting to request proposed in first post is humiliating behaviour for all that wanted to contribute ...

I don't feel humiliated but I'm assuming the OP may be engaged with matters of greater importance which could be family, job ... given his tenure here that seems probable.

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

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #20 on: September 15, 2020, 06:37:10 AM »
Benchmarks
benchmarking is tricky  :angel:

loaded from VLIDE
Code: [Select]
_$ (benchmark '((subfoo lst) (_rjpfoo lst) (f lst) (square lst) (fbru lst) (recrib lst)))
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (SQUARE LST)........1701 / 78.48 <fastest>
    (_RJPFOO LST).......2121 / 62.94
    (FBRU LST)..........2356 / 56.66
    (F LST).............2465 / 54.15
    (SUBFOO LST)........9703 / 13.76
    (RECRIB LST)......133491 / 1 <slowest>

LSP loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.lsp")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1763 / 67.88 <fastest>
    (SQUARE LST)........2247 / 53.26
    (FBRU LST)..........3510 / 34.09
    (F LST).............3807 / 31.43
    (SUBFOO LST).......18876 / 6.34
    (RECRIB LST)......119668 / 1 <slowest>

FAS loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.fas")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1077 / 125.05 <fastest>
    (FBRU LST)..........3495 / 38.53
    (F LST).............3807 / 35.38
    (SQUARE LST)........3807 / 35.38
    (SUBFOO LST).......18564 / 7.25
    (RECRIB LST)......134676 / 1 <slowest>

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Grid point list conversion
« Reply #21 on: September 15, 2020, 12:54:02 PM »
Benchmarks
benchmarking is tricky  :angel:

loaded from VLIDE
Code: [Select]
_$ (benchmark '((subfoo lst) (_rjpfoo lst) (f lst) (square lst) (fbru lst) (recrib lst)))
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (SQUARE LST)........1701 / 78.48 <fastest>
    (_RJPFOO LST).......2121 / 62.94
    (FBRU LST)..........2356 / 56.66
    (F LST).............2465 / 54.15
    (SUBFOO LST)........9703 / 13.76
    (RECRIB LST)......133491 / 1 <slowest>

LSP loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.lsp")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1763 / 67.88 <fastest>
    (SQUARE LST)........2247 / 53.26
    (FBRU LST)..........3510 / 34.09
    (F LST).............3807 / 31.43
    (SUBFOO LST).......18876 / 6.34
    (RECRIB LST)......119668 / 1 <slowest>

FAS loaded from Autocad command line
Code: [Select]
Command: (load "D:\\Temp\\tmp1.fas")
Elapsed milliseconds / relative speed for 32768 iteration(s):

    (_RJPFOO LST).......1077 / 125.05 <fastest>
    (FBRU LST)..........3495 / 38.53
    (F LST).............3807 / 35.38
    (SQUARE LST)........3807 / 35.38
    (SUBFOO LST).......18564 / 7.25
    (RECRIB LST)......134676 / 1 <slowest>
That it is :) ... I like your numbers better   :2funny:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CodeDing

  • Newt
  • Posts: 51
Re: Grid point list conversion
« Reply #22 on: September 15, 2020, 02:24:40 PM »
I know I'm a bit late to this party but it was fun to try. so I'll post anyways.
I mainly wanted to try to create without using append.
Code: [Select]
(defun map2sqr (map / squares)
  (mapcar
    '(lambda (m1 m2)
      (mapcar
        '(lambda (c1 c2 c3 c4)
          (setq squares (cons (list c1 c2 c3 c4) squares))
        );lambda
        m1
        (cdr m1)
        m2
        (cdr m2)
      );mapcar
    );lambda
    map
    (cdr map)
  );mapcar
  (reverse squares)
);defun
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #23 on: September 16, 2020, 07:33:25 AM »
Just to prove that benchmark for this task is wrong idea, here are results on my PC. :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:recunfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun rec ( mat / k itm1 itm2 kk lst )
  18.     (setq k -1)
  19.     (repeat (length mat)
  20.       (setq k (1+ k))
  21.       (setq itm1
  22.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  23.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth k mat)) kk)) (nth k mat))) (nth k mat))
  24.         )
  25.       )
  26.       (setq kk nil)
  27.       (setq itm2
  28.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  29.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth (1+ k) mat)) kk)) (nth (1+ k) mat))) (nth (1+ k) mat))
  30.         )
  31.       )
  32.       (setq kk nil)
  33.       (setq itm (mapcar '(lambda ( a b ) (append a b)) itm1 itm2))
  34.       (setq lst (cons itm lst))
  35.     )
  36.     (apply 'append (reverse lst))
  37.   )
  38.  
  39.   (initget 7)
  40.   (setq n (getint "\nSpecify number of rows of matrix : "))
  41.   (initget 7)
  42.   (setq m (getint "\nSpecify number of columns of matrix : "))
  43.   (setq ti (car (_vl-times)))
  44.   (princ "\n")
  45.   (prin1 (rec (matrix-n-m n m)))
  46.   (princ "\n")
  47.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  48.   (princ)
  49. )
  50.  
  51. ;|
  52. Command: RECUNFOLDMATRIX
  53.  
  54. Specify number of rows of matrix : 50
  55.  
  56. Specify number of columns of matrix : 50
  57.  
  58. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  59.  
  60. ...
  61.  
  62. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  63. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  64.  
  65. Elapsed time : 1328.000000000000 milliseconds...
  66. |;
  67.  
  68. ;;; Second test : Elapsed time : 1438.000000000000 milliseconds...
  69.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rjpfoounfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun _rjpfoo ( l / a b r )
  18.     (while (cadr l)
  19.       (setq a (car l)
  20.             b (cadr l)
  21.             l (cdr l)
  22.       )
  23.       (while (cadr a)
  24.         (setq r (cons (list (car a) (cadr a) (car b) (cadr b)) r)
  25.               a (cdr a)
  26.               b (cdr b)
  27.         )
  28.       )
  29.     )
  30.     (reverse r)
  31.   )
  32.  
  33.   (initget 7)
  34.   (setq n (getint "\nSpecify number of rows of matrix : "))
  35.   (initget 7)
  36.   (setq m (getint "\nSpecify number of columns of matrix : "))
  37.   (setq ti (car (_vl-times)))
  38.   (princ "\n")
  39.   (prin1 (_rjpfoo (matrix-n-m n m)))
  40.   (princ "\n")
  41.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  42.   (princ)
  43. )
  44.  
  45. ;|
  46. Command: RJPFOOUNFOLDMATRIX
  47.  
  48. Specify number of rows of matrix : 50
  49.  
  50. Specify number of columns of matrix : 50
  51.  
  52. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  53.  
  54. ...
  55.  
  56. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  57. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  58.  
  59. Elapsed time : 3047.000000000000 milliseconds...
  60. |;
  61.  
  62. ;;; Second test : Elapsed time : 4735.000000000000 milliseconds...
  63.  

As you can see, I was perhaps wrong for 1000x1000 matrix and 1 second, but my function is indeed faster than Ron's - testing sample done at 50x50 matrix... For spacing issues, I didn't copy+pasted all return list, but only first and last summing result...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #24 on: September 16, 2020, 08:58:03 AM »
Just to prove that benchmark for this task is wrong idea, here are results on my PC. :
Marko, can you repeat the test without (prin1 ) ?

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Grid point list conversion
« Reply #25 on: September 16, 2020, 09:57:10 AM »
Marko, I think you take this challenge/benchmark too serious.
« Last Edit: September 16, 2020, 03:47:20 PM by Stefan »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Grid point list conversion
« Reply #26 on: September 16, 2020, 11:29:24 AM »
I agree with "benchmarking is tricky  :angel:", I wanted to add that it can also vary with the CAD software. Perhaps the "Bruno_F" function is worthy of evaluation ...
Code: [Select]
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved

BricsCAD V20
Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST)......1109 / 49.51 <fastest>
    (SQUARE MLIST).......1359 / 40.4
    (VOVKA_F MLIST)......1812 / 30.3
    (_RJPFOO MLIST)......1828 / 30.04
    (MAP2SQR MLIST)......2469 / 22.24
    (SUBFOO MLIST).......5984 / 9.18
    (REC2 MLIST)........12266 / 4.48
    (MR_REC MLIST)......54906 / 1 <slowest>

Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST).....1313 / 2.04 <fastest>
    (SQUARE MLIST)......1359 / 1.97
    (_RJPFOO MLIST).....2000 / 1.34
    (VOVKA_F MLIST).....2078 / 1.29
    (MAP2SQR MLIST).....2672 / 1 <slowest>

Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST).....1109 / 1.65 <fastest>
    (SQUARE MLIST)......1140 / 1.6
    (VOVKA_F MLIST).....1812 / 1.01
    (_RJPFOO MLIST).....1828 / 1 <slowest>

Elapsed milliseconds / relative speed for 524288 iteration(s):
    (BRUNO_F MLIST).....1266 / 1.06 <fastest>
    (SQUARE MLIST)......1344 / 1 <slowest>
Code: [Select]
AutoCAD 2013
Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST)......2438 / 31.63 <fastest>
    (BRUNO_F MLIST)......2766 / 27.88
    (MAP2SQR MLIST)......3031 / 25.45
    (SQUARE MLIST).......3859 / 19.99
    (VOVKA_F MLIST)......7312 / 10.55
    (REC2 MLIST)........28984 / 2.66
    (SUBFOO MLIST)......34016 / 2.27
    (MR_REC MLIST)......77125 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1125 / 2.35 <fastest>
    (BRUNO_F MLIST).....1219 / 2.17
    (MAP2SQR MLIST).....1468 / 1.8
    (SQUARE MLIST)......1469 / 1.8
    (VOVKA_F MLIST).....2641 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1047 / 1.39 <fastest>
    (BRUNO_F MLIST).....1203 / 1.21
    (SQUARE MLIST)......1422 / 1.02
    (MAP2SQR MLIST).....1453 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1094 / 1.2 <fastest>
    (BRUNO_F MLIST).....1313 / 1 <slowest>

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Grid point list conversion
« Reply #27 on: September 16, 2020, 11:58:01 AM »
Just to prove that benchmark for this task is wrong idea, here are results on my PC. :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:recunfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun rec ( mat / k itm1 itm2 kk lst )
  18.     (setq k -1)
  19.     (repeat (length mat)
  20.       (setq k (1+ k))
  21.       (setq itm1
  22.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  23.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth k mat)) kk)) (nth k mat))) (nth k mat))
  24.         )
  25.       )
  26.       (setq kk nil)
  27.       (setq itm2
  28.         (vl-remove-if-not '(lambda ( x ) (= (length x) 2))
  29.           (mapcar '(lambda ( x ) (setq kk (if (null kk) 2 (1+ kk))) (vl-remove-if-not '(lambda ( y ) (< (- kk 3) (vl-position y (nth (1+ k) mat)) kk)) (nth (1+ k) mat))) (nth (1+ k) mat))
  30.         )
  31.       )
  32.       (setq kk nil)
  33.       (setq itm (mapcar '(lambda ( a b ) (append a b)) itm1 itm2))
  34.       (setq lst (cons itm lst))
  35.     )
  36.     (apply 'append (reverse lst))
  37.   )
  38.  
  39.   (initget 7)
  40.   (setq n (getint "\nSpecify number of rows of matrix : "))
  41.   (initget 7)
  42.   (setq m (getint "\nSpecify number of columns of matrix : "))
  43.   (setq ti (car (_vl-times)))
  44.   (princ "\n")
  45.   (prin1 (rec (matrix-n-m n m)))
  46.   (princ "\n")
  47.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  48.   (princ)
  49. )
  50.  
  51. ;|
  52. Command: RECUNFOLDMATRIX
  53.  
  54. Specify number of rows of matrix : 50
  55.  
  56. Specify number of columns of matrix : 50
  57.  
  58. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  59.  
  60. ...
  61.  
  62. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  63. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  64.  
  65. Elapsed time : 1328.000000000000 milliseconds...
  66. |;
  67.  
  68. ;;; Second test : Elapsed time : 1438.000000000000 milliseconds...
  69.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rjpfoounfoldmatrix ( / matrix-n-m rec n m ti )
  2.  
  3.   (defun matrix-n-m ( n m / nn mm itm row mat )
  4.     (setq nn 0)
  5.     (repeat n
  6.       (setq nn (1+ nn) mm 0)
  7.       (repeat m
  8.         (setq mm (1+ mm))
  9.         (setq itm (strcat (itoa nn) "-" (itoa mm)))
  10.         (setq row (cons itm row))
  11.       )
  12.       (setq mat (cons (reverse row) mat) row nil)
  13.     )
  14.     (reverse mat)
  15.   )
  16.  
  17.   (defun _rjpfoo ( l / a b r )
  18.     (while (cadr l)
  19.       (setq a (car l)
  20.             b (cadr l)
  21.             l (cdr l)
  22.       )
  23.       (while (cadr a)
  24.         (setq r (cons (list (car a) (cadr a) (car b) (cadr b)) r)
  25.               a (cdr a)
  26.               b (cdr b)
  27.         )
  28.       )
  29.     )
  30.     (reverse r)
  31.   )
  32.  
  33.   (initget 7)
  34.   (setq n (getint "\nSpecify number of rows of matrix : "))
  35.   (initget 7)
  36.   (setq m (getint "\nSpecify number of columns of matrix : "))
  37.   (setq ti (car (_vl-times)))
  38.   (princ "\n")
  39.   (prin1 (_rjpfoo (matrix-n-m n m)))
  40.   (princ "\n")
  41.   (prompt "\nElapsed time : ") (princ (rtos (- (car (_vl-times)) ti) 2 20)) (prompt " milliseconds...")
  42.   (princ)
  43. )
  44.  
  45. ;|
  46. Command: RJPFOOUNFOLDMATRIX
  47.  
  48. Specify number of rows of matrix : 50
  49.  
  50. Specify number of columns of matrix : 50
  51.  
  52. (("1-1" "1-2" "2-1" "2-2") ("1-2" "1-3" "2-2" "2-3") ("1-3" "1-4" "2-3" "2-4") ("1-4" "1-5" "2-4" "2-5") ("1-5" "1-6" "2-5" "2-6") ("1-6" "1-7" "2-6" "2-7") ("1-7" "1-8" "2-7" "2-8") ("1-8" "1-9" "2-8" "2-9") ("1-9" "1-10" "2-9" "2-10") ("1-10" "1-11" "2-10" "2-11") ("1-11" "1-12" "2-11" "2-12") ("1-12" "1-13" "2-12" "2-13") ("1-13" "1-14" "2-13" "2-14") ("1-14" "1-15" "2-14" "2-15") ("1-15" "1-16" "2-15" "2-16") ("1-16" "1-17" "2-16" "2-17") ("1-17" "1-18" "2-17" "2-18") ("1-18" "1-19" "2-18" "2-19") ("1-19" "1-20" "2-19" "2-20") ("1-20" "1-21" "2-20" "2-21") ("1-21" "1-22" "2-21" "2-22") ("1-22" "1-23" "2-22" "2-23") ("1-23" "1-24" "2-23" "2-24") ("1-24" "1-25" "2-24" "2-25") ("1-25" "1-26" "2-25" "2-26") ("1-26" "1-27" "2-26" "2-27") ("1-27" "1-28" "2-27" "2-28") ("1-28" "1-29" "2-28" "2-29") ("1-29" "1-30" "2-29" "2-30") ("1-30" "1-31" "2-30" "2-31") ("1-31" "1-32" "2-31" "2-32") ("1-32" "1-33" "2-32" "2-33") ("1-33" "1-34" "2-33" "2-34") ("1-34" "1-35" "2-34" "2-35") ("1-35" "1-36" "2-35" "2-36") ("1-36" "1-37" "2-36" "2-37") ("1-37" "1-38" "2-37" "2-38") ("1-38" "1-39" "2-38" "2-39") ("1-39" "1-40" "2-39" "2-40") ("1-40" "1-41" "2-40" "2-41") ("1-41" "1-42" "2-41" "2-42") ("1-42" "1-43" "2-42" "2-43") ("1-43" "1-44" "2-43" "2-44") ("1-44" "1-45" "2-44" "2-45") ("1-45" "1-46" "2-45" "2-46") ("1-46" "1-47" "2-46" "2-47") ("1-47" "1-48" "2-47" "2-48") ("1-48" "1-49" "2-48" "2-49") ("1-49" "1-50" "2-49" "2-50")
  53.  
  54. ...
  55.  
  56. ("49-1" "49-2" "50-1" "50-2") ("49-2" "49-3" "50-2" "50-3") ("49-3" "49-4" "50-3" "50-4") ("49-4" "49-5" "50-4" "50-5") ("49-5" "49-6" "50-5" "50-6") ("49-6" "49-7" "50-6" "50-7") ("49-7" "49-8" "50-7" "50-8") ("49-8" "49-9" "50-8" "50-9") ("49-9" "49-10" "50-9" "50-10") ("49-10" "49-11" "50-10" "50-11") ("49-11" "49-12" "50-11" "50-12") ("49-12" "49-13" "50-12" "50-13") ("49-13" "49-14" "50-13" "50-14") ("49-14" "49-15" "50-14" "50-15") ("49-15" "49-16" "50-15" "50-16") ("49-16" "49-17" "50-16" "50-17") ("49-17" "49-18" "50-17" "50-18") ("49-18" "49-19" "50-18" "50-19") ("49-19" "49-20" "50-19" "50-20") ("49-20" "49-21" "50-20" "50-21") ("49-21" "49-22" "50-21" "50-22") ("49-22" "49-23" "50-22" "50-23") ("49-23" "49-24" "50-23" "50-24") ("49-24" "49-25" "50-24" "50-25") ("49-25" "49-26" "50-25" "50-26") ("49-26" "49-27" "50-26" "50-27") ("49-27" "49-28" "50-27" "50-28") ("49-28" "49-29" "50-28" "50-29") ("49-29" "49-30" "50-29" "50-30") ("49-30" "49-31" "50-30" "50-31") ("49-31" "49-32" "50-31" "50-32") ("49-32" "49-33" "50-32" "50-33") ("49-33" "49-34" "50-33" "50-34") ("49-34" "49-35" "50-34" "50-35") ("49-35" "49-36" "50-35" "50-36
  57. ") ("49-36" "49-37" "50-36" "50-37") ("49-37" "49-38" "50-37" "50-38") ("49-38" "49-39" "50-38" "50-39") ("49-39" "49-40" "50-39" "50-40") ("49-40" "49-41" "50-40" "50-41") ("49-41" "49-42" "50-41" "50-42") ("49-42" "49-43" "50-42" "50-43") ("49-43" "49-44" "50-43" "50-44") ("49-44" "49-45" "50-44" "50-45") ("49-45" "49-46" "50-45" "50-46") ("49-46" "49-47" "50-46" "50-47") ("49-47" "49-48" "50-47" "50-48") ("49-48" "49-49" "50-48" "50-49") ("49-49" "49-50" "50-49" "50-50"))
  58.  
  59. Elapsed time : 3047.000000000000 milliseconds...
  60. |;
  61.  
  62. ;;; Second test : Elapsed time : 4735.000000000000 milliseconds...
  63.  

As you can see, I was perhaps wrong for 1000x1000 matrix and 1 second, but my function is indeed faster than Ron's - testing sample done at 50x50 matrix... For spacing issues, I didn't copy+pasted all return list, but only first and last summing result...

Strange .. when I run the test you created 'c:rjpfoounfoldmatrix' with 50x50 speed is waaay faster than what you posted (AutoCAD 2021)
Quote
Elapsed time : 234.0000000000000 milliseconds...

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

wizman

  • Bull Frog
  • Posts: 290
Re: Grid point list conversion
« Reply #28 on: September 16, 2020, 01:19:46 PM »
Thank you for benchmarking guys.

My nested recursion has failed in speed.  I can't even benchmark it along with your great codes.

Nonetheless, it is fun to solve and see everyone's creativity in approaching the problem.















VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #29 on: September 16, 2020, 02:07:38 PM »
Strange .. when I run the test you created 'c:rjpfoounfoldmatrix' with 50x50 speed is waaay faster than what you posted (AutoCAD 2021)
Quote
Elapsed time : 234.0000000000000 milliseconds...
may i ask you the same thing, Ron?
https://www.theswamp.org/index.php?topic=56239.msg601499#msg601499

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Grid point list conversion
« Reply #30 on: September 16, 2020, 03:26:36 PM »
Strange .. when I run the test you created 'c:rjpfoounfoldmatrix' with 50x50 speed is waaay faster than what you posted (AutoCAD 2021)
Quote
Elapsed time : 234.0000000000000 milliseconds...
may i ask you the same thing, Ron?
https://www.theswamp.org/index.php?topic=56239.msg601499#msg601499
Sure :)
Quote
Command: RJPFOOUNFOLDMATRIX
Specify number of rows of matrix : 50
Specify number of columns of matrix : 50
Elapsed time : 16.00000000000000 milliseconds...

Command: RECUNFOLDMATRIX
Specify number of rows of matrix : 50
Specify number of columns of matrix : 50
Elapsed time : 1438.000000000000 milliseconds...

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #31 on: September 16, 2020, 06:22:41 PM »
Sure :)
Quote
Command: RJPFOOUNFOLDMATRIX
Specify number of rows of matrix : 50
Specify number of columns of matrix : 50
Elapsed time : 16.00000000000000 milliseconds...

Command: RECUNFOLDMATRIX
Specify number of rows of matrix : 50
Specify number of columns of matrix : 50
Elapsed time : 1438.000000000000 milliseconds...

That it is :) ... I like your numbers better   :2funny:
1+

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Grid point list conversion
« Reply #32 on: September 16, 2020, 06:33:40 PM »
I wanted to add that it can also vary with the CAD software.
(BRUNO_F MLIST) is doing
524288 iterations for 1266 ms on Bricscad
and
32768 iterations for 1094 ms on Acad

looks like Bricscad is almost 14 times faster :)
cool

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Grid point list conversion
« Reply #33 on: September 16, 2020, 10:28:59 PM »
looks like Bricscad is almost 14 times faster :)

Awesome but I would have anticipated more. 🚀
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Grid point list conversion
« Reply #34 on: September 17, 2020, 02:15:20 AM »
I wanted to add that it can also vary with the CAD software.
(BRUNO_F MLIST) is doing
524288 iterations for 1266 ms on Bricscad
and
32768 iterations for 1094 ms on Acad

looks like Bricscad is almost 14 times faster :)
cool
AutoCAD 2021 t's even slower...
Code: [Select]
Elapsed milliseconds / relative speed for 32768 iteration(s):
    (BRUNO_F MLIST).....1829 / 1.21 <fastest>
    (SQUARE MLIST)......2219 / 1 <slowest>

Elapsed milliseconds / relative speed for 32768 iteration(s):
    (_RJPFOO MLIST).....1547 / 2.79 <fastest>
    (BRUNO_F MLIST).....1890 / 2.28
    (SQUARE MLIST)......2328 / 1.85
    (VOVKA_F MLIST).....4313 / 1 <slowest>

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Grid point list conversion
« Reply #35 on: September 17, 2020, 02:20:27 AM »
Considering results from my PC, I somehow don't believe to yours Ron... But IMHO, if OP would need matrix more than 50x50 elements I guess he is in nasty problems with his job... Around 1 second is very acceptable timing for a PC and this task... And like I said all proposed functions are good and suitable for this task and I agree with Stefan and his perception...
So my kudos go to Stefan 1+.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Grid point list conversion
« Reply #36 on: September 17, 2020, 11:12:11 AM »
Considering results from my PC, I somehow don't believe to yours Ron...
Yeah the numbers seem strange to me too but I'm just running the test you put together.  :wink:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Grid point list conversion
« Reply #37 on: September 17, 2020, 03:40:54 PM »
Thank you everyone for your contribution!
Indeed I was (and I'm still) busy in real life, agreed that it seems somewhat discrespectful for not replying on time.
Could've spent a few days figuring it out myself, but then I thought it may be better to post it here -
after all the task is related to a bit challenging list manipulation, while I knew I could rely on some of you.
Personally I don't get mad at the times when I provide a solution to an non-replying OP (like in this thread) rather just letting it sink in the web.
Surely I had the time to reply with just "thanks", which would seem more rude for me instead of non-replying -
because its like someone hands you a cigarette: while for a quick question it might be ok, for an algorithmic solution its not.

BTW I do code in my free time as an aside hobby (not making any $ out of it, but maybe as a part-time draughtsman - which is still not alot),
so not solving anything particular for a client - its more like a self-development thing.

My grid is max around 12x12, but we all agree that more and faster is better.
...nobody dropped the million dollar question for the potential usage of this sub.  :idea:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

wizman

  • Bull Frog
  • Posts: 290
Re: Grid point list conversion
« Reply #38 on: September 18, 2020, 01:44:03 AM »
Thank you everyone for your contribution!
Indeed I was (and I'm still) busy in real life, agreed that it seems somewhat discrespectful for not replying on time.
Could've spent a few days figuring it out myself, but then I thought it may be better to post it here -
after all the task is related to a bit challenging list manipulation, while I knew I could rely on some of you.
Personally I don't get mad at the times when I provide a solution to an non-replying OP (like in this thread) rather just letting it sink in the web.
Surely I had the time to reply with just "thanks", which would seem more rude for me instead of non-replying -
because its like someone hands you a cigarette: while for a quick question it might be ok, for an algorithmic solution its not.

BTW I do code in my free time as an aside hobby (not making any $ out of it, but maybe as a part-time draughtsman - which is still not alot),
so not solving anything particular for a client - its more like a self-development thing.

My grid is max around 12x12, but we all agree that more and faster is better.
...nobody dropped the million dollar question for the potential usage of this sub.  :idea:

Thank you for your response.
May i ask the application of this?  Do you need only 2x2 square?

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Grid point list conversion
« Reply #39 on: September 18, 2020, 01:52:47 PM »
...

Thank you for your response.
May i ask the application of this?

I was writing some distributed scattering...
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg