Define 2nd list element values from 1st list elements

Define 2nd list element values from 1st list elements

avinash00002002
Collaborator Collaborator
998 Views
12 Replies
Message 1 of 13

Define 2nd list element values from 1st list elements

avinash00002002
Collaborator
Collaborator

Hi!

 

I have a list that I want to create a new list based on 1st list.

 

my list is:

 

(70.0 132.0 70.0 132.0 70.0 70.0 150.0 70.0 150.0 70.0 70.0 70.0 70.0 130.0 70.0 150.0 70.0 130.0 70.0 70.0 150.0 70.0 70.0 132.0 70.0 132.0 70.0 132.0)

I have derived that there is a 4 type of value in above list. like (70.0 130.0 132.0 150.0)  so,

I want to set the value in second list,

if 70.0 then (/ 19.0 4.0)

if  130.0 then (/ 19.0 3.0)

if 132,0 then (/ 19.0 2.0)

if 150,0 then 19.0

how to do? any help!

0 Likes
Accepted solutions (1)
999 Views
12 Replies
Replies (12)
Message 2 of 13

marko_ribar
Advisor
Advisor
(mapcar '(lambda ( x ) (cond ( (= x 70.0) (/ 19.0 4.0) ) ( (= x 130.0) (/ 19.0 3.0) ) ( (= x 132.0) (/ 19.0 2.0) ) ( (= x 150.0) 19.0 ) ( t x ))) '(70.0 132.0 70.0 132.0 70.0 70.0 150.0 70.0 150.0 70.0 70.0 70.0 70.0 130.0 70.0 150.0 70.0 130.0 70.0 70.0 150.0 70.0 70.0 132.0 70.0 132.0 70.0 132.0))
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 13

avinash00002002
Collaborator
Collaborator

Hi!

Thanks, for reply.

 

If my list is minimum 1 no. to N nos. of elements in the list. then....

0 Likes
Message 4 of 13

marko_ribar
Advisor
Advisor

@avinash00002002 wrote:

Hi!

Thanks, for reply.

 

If my list is minimum 1 no. to N nos. of elements in the list. then....


I don't understand...

Please, explain better... Give examples of possible situations and desired resulting outcomes...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 5 of 13

avinash00002002
Collaborator
Collaborator

Hi!

I said my list is N nos. of list

 

1.    if my list elements is only one member like... (51) then the value of other list is 7.0

2.    if my list elements are two members like... (51 60) then the value of other list is 7.0 & 5.0

3.   if my list elements are more than two nos. like... (25, 30, 40, 45, 51, 55, 57, 60, 80, 95, 100) etc..

below calculation for all above lists.

Now it calculate the nos. of elements present in the list. say 11 nos. as per 3rd no.

it will divide ( 19 / nos. of elements ) = 1.72

 

LIST EXAMPLES:

(57 56 97 97 56 57 97 97 56 57 97 97 56 97 56 97 56 97 56 105 97 56 97 56)
(64, 64, 51, 36, 36, 36)
(115 65 115 65 115 65 65 120 120 94 65 120 65 120 65 120 65 65 105 65 65 65 103 115)

ETC..

0 Likes
Message 6 of 13

marko_ribar
Advisor
Advisor

@avinash00002002 wrote:

Hi!

I said my list is N nos. of list

 

1.    if my list elements is only one member like... (51) then the value of other list is 7.0

2.    if my list elements are two members like... (51 60) then the value of other list is 7.0 & 5.0

3.   if my list elements are more than two nos. like... (25, 30, 40, 45, 51, 55, 57, 60, 80, 95, 100) etc..

below calculation for all above lists.

Now it calculate the nos. of elements present in the list. say 11 nos. as per 3rd no.

it will divide ( 19 / nos. of elements ) = 1.72

 

LIST EXAMPLES:

(57 56 97 97 56 57 97 97 56 57 97 97 56 97 56 97 56 97 56 105 97 56 97 56)
(64, 64, 51, 36, 36, 36)
(115 65 115 65 115 65 65 120 120 94 65 120 65 120 65 120 65 65 105 65 65 65 103 115)

ETC..


Still you haven't explained well... I am seeking for examples showing both reference lists and resulting lists - outcomes... What is N and what is N nos - (we need to see what routine should do - not just reference list examples - if you can't write it manually, then try on some simple examples with only 4-5 elements and post them both separately - each example with both lists...)

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 7 of 13

avinash00002002
Collaborator
Collaborator

LIST EXAMPLES:

LIST-->  (57 56 97 97 56 57 97 97 56 57 97 97 56 97 56 97 56 97 56 105 97 56 97 56)

 

STEPS: REMOVE DUPLICATES FROM ABOVE LIST and ascending

 = (56 57 97 105)

SO, TOTAL 4 ELEMENT VALUE

SO, 19/4.0

= 4.75

[ AT THE NEW LIST (57 56 97 105) 

from above list for First Element = 4.75 x 1 == 4.75 (where 1 = element position)

for 2nd element 4.75 X 2 = 9.5 (where 2 = element position)

for 3rd element 4.75 X 3 = 14.25 (where 3 = element position)

for 4rd element 4.75 X 4 = 19 (where 4 = element position) ]

above calculation is after removing duplicates 4 elements are remaining, so we have divide 19 to the 4 

if we have 12 element after removing duplicates then we have to divide 19 to the 12.

the ultimate results is: (9.5 4.75 14.25 14.25 4.75 9.5 14.25 14.25 4.75 9.5 14.25 14.25 4.75 14.25 4.75 14.25 4.75 14.25 4.75 19 14.25 4.75 14.25 4.75)

 

 

 

now we see second list

 list = (64, 64, 51, 36, 36, 36)

after removing duplicates  the list is (36 51 64)

so, we have to divide 19 to the 3 nos.

1. 6.3 --> for 36
2. 12.3 --> for 51
3. 19 --> for 64

list = (64, 64, 51, 36, 36, 36)
result= (6.3 6.3 12.3 6.3 6.3 6.3)

3rd example

list = (115 65 115 65 115 65 65 120 120 94 65 120 65 120 65 120 65 65 105 65 65 65 103 115)

after removing duplicate = (65 94 103 105 115 120) = total 6 element.

so, we have to divide 19/6.0 = 3.16

1. 3.16 (= 3.16)
2. 6.32 (= 3.16 *2)
3. 9.48 (= 3.16 *3)
4. 12.64 (= 3.16 * 4)
5. 15.8 (= 3.16 * 5)
6. 18.96 (= 3.16 *6)

final result is

= (15.8 3.16 15.8 3.16 15.8 3.16 3.16 19 19 6.32 3.16 19 3.16 19 3.16 19 3.16 3.16 105 3.16 3.16 3.16 9.48 15.8)

0 Likes
Message 8 of 13

marko_ribar
Advisor
Advisor

Sorry for delay, I haven't noticed you posted reply... My phone didn't beep...

 

(defun foo ( lst / unique l k )

  (defun unique ( l / a ll )
    (while (setq a (car l))
      (if (vl-some (function (lambda ( x ) (equal x a 1e-6))) (cdr l))
        (setq ll (cons a ll) l (vl-remove-if (function (lambda ( x ) (equal x a 1e-6))) (cdr l)))
        (setq ll (cons a ll) l (cdr l))
      )
    )
    (reverse ll)
  )

  (setq l (vl-sort (unique lst) (function <)))
  (setq k (/ 19.0 (length l)))
  (mapcar (function (lambda ( x ) (* k (1+ (vl-position x l))))) lst)
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 9 of 13

avinash00002002
Collaborator
Collaborator

Great work,

 

I have mentioned that if the number of element is only 1. then result is 7.0 --> (5) as a list

 

and the number of element is only 2. then result is 7.0 and 5.0 --> (7 5) as a list

 

any updating reqd.

0 Likes
Message 10 of 13

marko_ribar
Advisor
Advisor
(defun foo ( lst / unique l k )

  (defun unique ( l / a ll )
    (while (setq a (car l))
      (if (vl-some (function (lambda ( x ) (equal x a 1e-6))) (cdr l))
        (setq ll (cons a ll) l (vl-remove-if (function (lambda ( x ) (equal x a 1e-6))) (cdr l)))
        (setq ll (cons a ll) l (cdr l))
      )
    )
    (reverse ll)
  )

  (cond
    ( (= (length lst) 1)
      (list 5.0)
    )
    ( (= (length lst) 2)
      (list 7.0 5.0)
    )
    ( t
      (setq l (vl-sort (unique lst) (function <)))
      (setq k (/ 19.0 (length l)))
      (mapcar (function (lambda ( x ) (* k (1+ (vl-position x l))))) lst)
    )
  )
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 11 of 13

avinash00002002
Collaborator
Collaborator

Thanks, That is ok.

 

I need After removing duplicate element in the list, if 1 then result list is (7.0)

and

after removing duplicate element in the list. if 2 then result list is (7.0 5.0)

 

Thanks,

 

Avinash

0 Likes
Message 12 of 13

marko_ribar
Advisor
Advisor
(defun foo ( lst / unique l k )

  (defun unique ( l / a ll )
    (while (setq a (car l))
      (if (vl-some (function (lambda ( x ) (equal x a 1e-6))) (cdr l))
        (setq ll (cons a ll) l (vl-remove-if (function (lambda ( x ) (equal x a 1e-6))) (cdr l)))
        (setq ll (cons a ll) l (cdr l))
      )
    )
    (reverse ll)
  )

  (setq l (vl-sort (unique lst) (function <)))
  (cond
    ( (= (length l) 1)
      (mapcar (function (lambda ( x ) 7.0)) lst)
    )
    ( (= (length l) 2)
      (mapcar (function (lambda ( x ) (if (= (vl-position x l) 0) 7.0 5.0))) lst)
    )
    ( t
      (setq k (/ 19.0 (length l)))
      (mapcar (function (lambda ( x ) (* k (1+ (vl-position x l))))) lst)
    )
  )
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 13 of 13

marko_ribar
Advisor
Advisor
Accepted solution

Although, given the logic you want with unique lists > 2, smaller numbers => smaller resulting numbers... I'd write function like this :

 

(defun foo ( lst / unique l k )

  (defun unique ( l / a ll )
    (while (setq a (car l))
      (if (vl-some (function (lambda ( x ) (equal x a 1e-6))) (cdr l))
        (setq ll (cons a ll) l (vl-remove-if (function (lambda ( x ) (equal x a 1e-6))) (cdr l)))
        (setq ll (cons a ll) l (cdr l))
      )
    )
    (reverse ll)
  )

  (setq l (vl-sort (unique lst) (function <)))
  (cond
    ( (= (length l) 1)
      (mapcar (function (lambda ( x ) 5.0)) lst)
    )
    ( (= (length l) 2)
      (mapcar (function (lambda ( x ) (if (= (vl-position x l) 0) 5.0 7.0))) lst)
    )
    ( t
      (setq k (/ 19.0 (length l)))
      (mapcar (function (lambda ( x ) (* k (1+ (vl-position x l))))) lst)
    )
  )
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes