List manipulation

List manipulation

avinash00002002
Collaborator Collaborator
3,313 Views
52 Replies
Message 1 of 53

List manipulation

avinash00002002
Collaborator
Collaborator

Hi!

I have a list which has nos. of vary members. 

(0.816176 6.48044 10.7246 10.3981 1.90985 8.48824 1.69765 3.39529 24.2404 1.63235 22.3306 1.50176 14.7075 17.4335 13.3526 13.3526 14.5769 5.8275 1.25691 11.8019 9.30441 7.72103 8.03118 4.35838 2.17103 3.65647)

I need help that
1. Which member have less than 4 than set to 4, and it will deduct from greater than 4.

Thanks,

Avinash

0 Likes
Accepted solutions (4)
3,314 Views
52 Replies
Replies (52)
Message 2 of 53

marko_ribar
Advisor
Advisor
(mapcar '(lambda ( x ) (cond ( (< x 4) 4 ) ( (> x 4) (- x 4) ) ( t x ) )) lst)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 53

pbejse
Mentor
Mentor

@avinash00002002 wrote:

I need help that
1. Which member have less than 4 than set to 4, and it will deduct from greater than 4.


Can you clarify this for us:

if number is leess than 4.0  

  • --> 0.816176 replace the value as 4.0?

if number is greater than 4.0 deduct 4.0

  • --> 5.8275  = 1.8275 <-- which makes it less than 4?

 

Better yet post the desired result based on the list at post#1

 

 

 

0 Likes
Message 4 of 53

avinash00002002
Collaborator
Collaborator

Thanks for help

 

I need that total of all member are required same as old. is it possible

 

Avinash

0 Likes
Message 5 of 53

avinash00002002
Collaborator
Collaborator
yes, but it is deduct from maximum values
and total of all member are same as before count
0 Likes
Message 6 of 53

avinash00002002
Collaborator
Collaborator
and it will deduct from max. greater value.
0 Likes
Message 7 of 53

pbejse
Mentor
Mentor

Better yet post the desired result based on the list at post# 1

 

 

0 Likes
Message 8 of 53

avinash00002002
Collaborator
Collaborator

Hi!

 

I am attached drawing which has full scale with dimensions and required result fitted in 230mm. (which I have drawn manually.

0 Likes
Message 9 of 53

pbejse
Mentor
Mentor

I'm sorry i still dont get it.  why 4? why 230 ?

What about showing the result from the list at post # 1?

 

 

 

0 Likes
Message 10 of 53

avinash00002002
Collaborator
Collaborator

because,  first and last distance I have set 4mm. so, it will come 222mm and total length is 6800

if you divide 222/ 6800 then result is 0.0326471mm.

now we start multiplication for scaling 0.0326471 * first dimension, second dimension... the list i have post#1.

 

the original length of drawing is 6800mm. I want to fit it in 230mm. slot (which I have drawn in sample drawing)

 

Thanks,

 

Avinash

0 Likes
Message 11 of 53

ronjonp
Mentor
Mentor

Make it a block then use scale relative ?

0 Likes
Message 12 of 53

pbejse
Mentor
Mentor

This is the dimension values at 6800

 

(25.0 198.341 328.4 318.646 58.5266 260.119 52.0242 104.048 742.543 50.0591 684.141 45.8875 450.532 533.964 408.816 408.816 446.36 178.695 38.2918 361.645 285.061 236.662 246.124 133.491 66.7454 112.063 25.0)

 

This is the result  multiplying the list by ( 222 / 680 )

 

(0.816176 6.47524 10.7213 10.4029 1.91072 8.49212 1.69844 3.39685 24.2418 1.63428 22.3352 1.49809 14.7085 17.4323 13.3466 13.3466 14.5723 5.83386 1.25011 11.8066 9.3064 7.72633 8.03522 4.35809 2.17904 3.65853 0.816176)

 

This is the dimension of the "manual" drawing at 230

 

(4.0 10.2469 10.3381 10.0234 5.0 5.02338 5.0 5.0 18.2763 5.0 18.0994 5.0 10.6251 16.8053 12.8715 12.8715 8.9079 5.6175 5.0 7.58824 8.96912 11.4428 7.74176 5.0 5.0 6.5518 4.0)

 

Lets look at the first 6 items

 

0.816176	4.0
6.47524		10.2469
10.7213		10.3381
10.4029		10.0234
1.91072		5.0
8.49212		5.02338

 

1st item is 0.816176 [ less than 4 ]  =  4.0 [ 0 + 4 ]

2nd item is 6.47524 [ greater than 4 ] = 10.2469 [ 6 + 4 ? ]

3nd item is 10.7213 [ greater than 4 ]  = 10.3381 ?

4nd item is 10.4029 [ greater than 4 ]  = 10.0234 ? 

5th item is 1.91072 [ less than 4 ]  =  5.0 [ 1 + 4 ]

6th item is 8.49212 [ greater than 4 ]  =  5.02338   ?

 

 

 

0 Likes
Message 13 of 53

avinash00002002
Collaborator
Collaborator

ok, but required minimum length is 4mm. to fit dimension and text.

0 Likes
Message 14 of 53

avinash00002002
Collaborator
Collaborator

while less than 4mm. than add some values to complete around 4mm. at same time it deduct from 1st higher, 2nd higher value and so on.

0 Likes
Message 15 of 53

avinash00002002
Collaborator
Collaborator
please help me out this type of situations. if any further query please ask.
0 Likes
Message 16 of 53

pbejse
Mentor
Mentor

@avinash00002002 wrote:
please help me out this type of situations. if any further query please ask.

Query? I already did it at post # 12  

pbejse_0-1632582751292.png

 

This below is not enough

 

while less than 4mm. than add some values to complete around 4mm. at same time it deduct from 1st higher, 2nd higher value and so on.

You need to explain why is 6.647524 became 10.2469 but 8.349212 is 5.02338?

What are the conditions for that? it cannot be just random. when you're doing it manually then yes, but thru code you need more than "and so on" .

 

Believe me, we get it. to get 4 as the first value, we need to deduct from some other source.

1st item is now 4.0 , we got it from the next number 6.47524 which leaves 3.29142, ending up as less than 4.0 

Originally its above 4.0 now its 3.29142 but why 10.2469 ? Which means you added 6.95548 which i assume you get from the next number, what is the basis for all that?

 

What you're saying is different from what your're showing on you're sample drawing.

 

Eventually someone will come along and help you, but with that conditions?

 

---------------------------------------------------------------------------------------------------------------------------

(73 39 109 32 115 117 114 101 32 116 104 101 114 101 39 115 32 103 111 105 110 103 32 116 111 32 98 101 32 97 32 108 111 116 32 111 102 32 34 110 111 116 32 119 111 114 107 105 110 103 32 99 111 109 109 101 110 116 115 32 102 114 111 109 32 121 111 117 32 97 115 32 97 32 114 101 115 112 111 110 115 101)

 

 

0 Likes
Message 17 of 53

hak_vz
Advisor
Advisor
(defun plus_minus (lst / take max_lst cnt_4 cnt_8 ret i)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(setq 
		cnt_8 0 
		cnt_4 0
		i -1 
	)
	(while (< (setq i (1+ i)) (length lst))
		(cond
			((<= (nth i lst) 4.0) (setq cnt_4 (1+ cnt_4)))
			((> (nth i lst) 8.0) (setq cnt_8 (1+ cnt_8)))
		)
	)
	(cond
		((>= cnt_8 cnt_4)
			(setq max_lst (take cnt_4 (vl-sort lst '>)) i -1)
			(while (< (setq i (1+ i)) (length lst))
				(cond
				
					((and (< (nth i lst) 4.0) (> cnt_4 0))
						(setq ret (cons (+ (nth i lst) 4.0) ret) cnt_4 (1- cnt_4))
					)
					((member (nth i lst) max_lst)
						(setq ret (cons (- (nth i lst) 4.0) ret))
					)
					(T
						(setq ret (cons (nth i lst) ret))
					)
				)
			)
		)
	)
	(if ret (setq ret(reverse ret)))
	ret
)

 

Here is my solution. For count of all values less then 4 find equal number largest values. Add 4 to each value less than 4 and deduce it to those selected largest values. This works if number of values less then 4 is smaller or equal to number of values greater than 8

Usage:
(setq lst (plus_minus lst))
Command: !lst
(0.816176 6.48044 10.7246 10.3981 1.90985 8.48824 1.69765 3.39529 24.2404 1.63235 22.3306 1.50176 14.7075 17.4335 13.3526 13.3526 14.5769 5.8275 1.25691 11.8019 9.30441 7.72103 8.03118 4.35838 2.17103 3.65647)
Command: (setq nlst (plus_minus lst))
(4.81618 6.48044 6.7246 10.3981 5.90985 8.48824 5.69765 7.39529 20.2404 5.63235 18.3306 5.50176 10.7075 13.4335 9.3526 9.3526 10.5769 5.8275 5.25691 7.8019 9.30441 7.72103 8.03118 4.35838 6.17103 7.65647)
Command: (- (apply '+ lst) (apply '+ nlst))
0.0

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 18 of 53

avinash00002002
Collaborator
Collaborator

Hi!

Great work

this list is a sample it will vary from one to another, this is works great in existing list.

when I use below list it isn't work.

for length 6177

0.894873 1.25282 1.25282 1.25282 1.25282 1.25282 10.1121 1.18123 1.73605 1.28862 2.86359 0.84118 0.196872 2.66672 0.698001 3.31103 29.5308 3.75847 0.590616 24.3047 15.8392 1.53918 2.04031 0.733796 1.4139 8.85924 8.50129 1.4318 21.3875 2.50564 0.357949 1.3781 26.1661 16.5551 0.357949 13.1546 2.38036 1.25282 1.25282 1.25282 1.25282 1.25282
 
another
for length 3600
25 35 35 35 35 35 35 35 130 141.5 69 49 640.5 652.5 247.5 900 50 50 33.5 61
 
why it is not working above list.
0 Likes
Message 19 of 53

hak_vz
Advisor
Advisor

Code will not work if number of values greater than 8 in a list is smaller then number of values less than 4. In that case you have to use some other method.

To make code applicable for different cases you either have to add or remove different value , direction is not always from smallest values to largest, depending on situation. 

We don't know what your values and lengths represent. Give as sample drawing and a set of test lists with desired values so that we can work on it.

My code solves first list according to what you asked, but your explanation was not complete.  It's hard to work on something imaginary when you don't have full information.

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 20 of 53

pbejse
Mentor
Mentor

@avinash00002002 wrote:

..when I use below list it isn't work.

..
why it is not working above list.
 

We don't know what your values and lengths represent. Give as sample drawing and a set of test lists with desired values so that we can work on it.

My code solves first list according to what you asked, but your explanation was not complete.  It's hard to work on something imaginary when you don't have full information.


Thats  2, now you see what i mean?

 

The logic is actually easy.

This is the value of the dimensions at 6800 [ the whole thing including both ends ]

(setq dim '(25.0 198.341    328.4      318.646	  58.5266    260.119
		 52.0242    104.048    742.543	  50.0591    684.141
		 45.8875    450.532    533.964	  408.816    408.816
		 446.36	    178.695    38.2918	  361.645    285.061
		 236.662    246.124    133.491	  66.7454    112.0614
		 25.0
		)
)
(apply '+ dim ) 6800.0
;Divide the target with the current
(setq f ( / 230.000 6800))
(setq smaller (mapcar '(lambda (v) (* v f)) dim))

(0.845588 6.70859    11.1076	10.7777	   1.97958    8.79814
	  1.75964    3.51927	25.1154	   1.69318    23.1401
	  1.55208    15.2386	18.0605	   13.8276    13.8276
	  15.0975    6.0441	1.29516	   12.2321    9.64177
	  8.00474    8.32478	4.51514	   2.25757    3.79031
	  0.845588
	 )

(apply '+ smaller) 230.0

Now what the program needs to do is anyhing below the mimum will be adjusted [ Add ] and the deficiency would be deducted from the rest of the list equally as long as the value will not fall below the minium number.

(setq adjusted (_small dim ( / 230.000 6800)))

;; _Small is the subfunction that follow the logic i mentioned above

(4.0 5.42972   9.82877	 9.49885   4.0	     7.51927   4.0
     4.0       23.8365	 4.0	   21.8612   4.0       13.9597
     16.7817   12.5487	 12.5487   13.8186   4.76522   4.0
     10.9532   8.36289	 6.72587   7.0459    4.51514   4.0
     4.0       4.0
    )
(apply '+ adjusted)
230.0

 

 

0 Likes