Author Topic: Combine lists for desk layout and placing blocks  (Read 152 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: 1680
  • 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: 2069
  • 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]
  1. (defun c:const-st-a-b-en-lst ( / lst1 lst2 lst3 l l1 l2 lst )
  2.  (initget 1)
  3.  (setq lst1 (read (strcat "(" (getstring t "\nSpecify first list with numbers - integers : ") ")")))
  4.  (initget 1)
  5.  (setq lst2 (read (strcat "(" (getstring t "\nSpecify second list with numbers - integers : ") ")")))
  6.  (if (and lst1 lst2)
  7.    (progn
  8.      (repeat (apply '+ lst1)
  9.        (setq lst3 (cons 1 lst3))
  10.      )
  11.      (setq lst (cons "st" lst))
  12.      (setq l 0 l1 0 l2 0)
  13.      (foreach x lst3
  14.        (setq l (+ l x))
  15.        (if (= l (apply '+ lst3))
  16.          (setq lst (append lst (list "en")))
  17.          (if (= l (+ (car lst1) l1))
  18.            (if (= l (+ (car lst2) l2))
  19.              (progn
  20.                (setq lst (append lst (list "b")))
  21.                (setq l2 (+ l2 (car lst2)))
  22.                (setq l1 (+ l1 (car lst1)))
  23.                (setq lst2 (cdr lst2))
  24.                (setq lst1 (cdr lst1))
  25.              )
  26.              (progn
  27.                (setq lst (append lst (list "a")))
  28.                (setq l1 (+ l1 (car lst1)))
  29.                (setq lst1 (cdr lst1))
  30.              )
  31.            )
  32.          )
  33.        )
  34.      )
  35.    )
  36.  )
  37.  (princ lst)
  38.  (princ)
  39. )
  40.  
  41. ;|
  42. Command: CONST-ST-A-B-EN-LST
  43. Specify first list with numbers - integers : 2 1 2
  44. Specify second list with numbers - integers : 3 2
  45. (st a b en)
  46. Command:
  47. Command: CONST-ST-A-B-EN-LST
  48. Specify first list with numbers - integers : 1 1 1 1 1 1
  49. Specify second list with numbers - integers : 2 2 2
  50. (st a b a b a en)
  51. Command:
  52. Command: CONST-ST-A-B-EN-LST
  53. Specify first list with numbers - integers : 1 1 1 1 1
  54. Specify second list with numbers - integers : 2 3
  55. (st a b a a en)
  56. |;
  57.  

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