Author Topic: Combine lists for desk layout and placing blocks  (Read 99 times)

0 Members and 1 Guest are viewing this topic.

Jeroen

• Newt
• Posts: 21
• BricsCAD & AutoLisp
Combine lists for desk layout and placing blocks
« on: April 15, 2019, 07:31:17 AM »
I have a Lisp that creates two lists throug user-input. These lists are measurements of  two different parts.
The lists can change in length. For example (top one in screenshot):

A (2 1 2) -> white-rectangles with "100+" in it
B (3 2) -> red dashed with value)

What I need is a list with points to put in 2 different blocks. (see screenshot, block A and block B)

The start and end-block I got covered.

List A only contains values of 1or 2
List B contains values of 1, 2, 3or 4

It should work in every combination where the total of the sum of the values in the lists are equal. (two more examples in screenshot)

I have been breaking my mind for hours and I cannot figure it out...

Kind regards,
Jeroen Berkers
Jeroen

roy_043

• Water Moccasin
• Posts: 1672
• BricsCAD 18
Re: Combine lists for desk layout and placing blocks
« Reply #1 on: April 15, 2019, 08:35:07 AM »
Your problem is hard to understand.
If both list A and B are based on user input what should the Lisp in fact do?
If only list B is given and you accept a list A with only 1's (as per your image) the algorithm is rather simple.

Code: [Select]
`(defun B_To_A (lstB)  (apply    'append    (mapcar      '(lambda (itm / ret) (repeat itm (setq ret (cons 1 ret))))      lstB    )  ))`

ribarm

• Water Moccasin
• Posts: 2052
• Marko Ribar, architect
Re: Combine lists for desk layout and placing blocks
« Reply #2 on: April 15, 2019, 09:16:11 AM »
Here you are :

Code - Auto/Visual Lisp: [Select]
`(defun c:const-st-a-b-en-lst ( / lst1 lst2 lst3 l l1 l2 lst )  (initget 1)  (setq lst1 (read (strcat "(" (getstring t "\nSpecify first list with numbers - integers : ") ")")))  (initget 1)  (setq lst2 (read (strcat "(" (getstring t "\nSpecify second list with numbers - integers : ") ")")))  (if (and lst1 lst2)    (progn      (repeat (apply '+ lst1)        (setq lst3 (cons 1 lst3))      )      (setq lst (cons "st" lst))      (setq l 0 l1 0 l2 0)      (foreach x lst3        (setq l (+ l x))        (if (= l (apply '+ lst3))          (setq lst (append lst (list "en")))          (if (= l (+ (car lst1) l1))            (if (= l (+ (car lst2) l2))              (progn                (setq lst (append lst (list "b")))                (setq l2 (+ l2 (car lst2)))                (setq l1 (+ l1 (car lst1)))                (setq lst2 (cdr lst2))                (setq lst1 (cdr lst1))              )              (progn                (setq lst (append lst (list "a")))                (setq l1 (+ l1 (car lst1)))                (setq lst1 (cdr lst1))              )            )          )        )      )    )  )  (princ lst)  (princ)) ;|Command: CONST-ST-A-B-EN-LSTSpecify first list with numbers - integers : 2 1 2Specify second list with numbers - integers : 3 2(st a b en)Command:Command: CONST-ST-A-B-EN-LSTSpecify first list with numbers - integers : 1 1 1 1 1 1Specify second list with numbers - integers : 2 2 2(st a b a b a en)Command:Command: CONST-ST-A-B-EN-LSTSpecify first list with numbers - integers : 1 1 1 1 1Specify second list with numbers - integers : 2 3(st a b a a en)|; `

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

M.R. on Youtube

Jeroen

• Newt
• Posts: 21
• BricsCAD & AutoLisp
Re: Combine lists for desk layout and placing blocks
« Reply #3 on: April 15, 2019, 09:35:53 AM »
Thanks Marko, it does exactly what I was looking for.

Jeroen
Jeroen