Dayananda Posted December 24, 2019 Posted December 24, 2019 (edited) a = (100 125 10 97) Now how can I get the maximum value of above list (max a) does not works. But (car a) = 100 it can get Edited December 24, 2019 by Dayananda Quote
hanhphuc Posted December 24, 2019 Posted December 24, 2019 49 minutes ago, Dayananda said: a = (100 125 10 97) Now how can I get the maximum value of above list (max a) does not works. But (car a) = 100 it can get (apply 'max a) 1 Quote
Lee Mac Posted December 25, 2019 Posted December 25, 2019 (apply 'max a) will always be the quickest, but will be susceptible to the inherent limitation in the number of arguments that you can supply to the min or max functions, and will therefore fail for long lists; other alternatives which avoid this limit might be: (car (vl-sort a '>)) But sorting is also unnecessarily slow - on average on the order of O(n log(n)) when only a maximum is required, and so this method should be avoided. Another alternative might be: (setq r (car a)) (foreach x (cdr a) (if (< r x) (setq r x))) 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.