born Posted September 11 Share Posted September 11 Hello people, again struggling to find the name of the function which ranges all values in a list to a specific sum of the list. Any help? Quote Link to comment Share on other sites More sharing options...
opmo Posted September 11 Share Posted September 11 Do you mean: get-count Quote Link to comment Share on other sites More sharing options...
born Posted September 11 Author Share Posted September 11 2 hours ago, opmo said: Do you mean: get-count No. The function which does something like this: ;; scale all numbers of lst that the sum of lst is 25 (setf lst '(1 2 3 4 5)) (setf list-sum (sum lst)) (setf scale 25) (setf result1 (loop for i in lst collect (* 1.0 (* scale (/ i list-sum))))) ;; test (sum result1) (setf result2 (loop for i in lst collect (round (* 1.0 (* scale (/ i list-sum)))))) ;; test (sum result2) Quote Link to comment Share on other sites More sharing options...
opmo Posted September 11 Share Posted September 11 (setf lst '(1 2 3 4 5)) (setf list-sum (sum lst)) (setf scale (/ 25 list-sum)) (scale-numbers scale lst) I will add a round (keyword) into the function. (scale-numbers scale lst :round t) => (2 3 5 7 8) Quote Link to comment Share on other sites More sharing options...
opmo Posted September 11 Share Posted September 11 We could make a new function scale-to-sum (scale-to-sum 25 '(1 2 3 4 5) :round t) => (2 3 5 7 8) Will be part of the next update. Quote Link to comment Share on other sites More sharing options...
opmo Posted September 11 Share Posted September 11 The function scale-to-sum is part of OM 3.0.29095 AM and Stephane Boussuge 2 Quote Link to comment Share on other sites More sharing options...
born Posted September 12 Author Share Posted September 12 I would suggest to add a keyword :sum to the function scale-numbers. Quote Link to comment Share on other sites More sharing options...
opmo Posted September 12 Share Posted September 12 Yes, this could be done. I will have a look. Stephane Boussuge 1 Quote Link to comment Share on other sites More sharing options...
opmo Posted September 12 Share Posted September 12 Done: (scale-numbers .3 '(3 4 2 3 4 2 1)) => (0.90000004 1.2 0.6 0.90000004 1.2 0.6 0.3) (scale-numbers 25 '(1 2 3 4 5) :sum t) => (1.6666666 3.3333333 5.0 6.6666665 8.333333) Quote Link to comment Share on other sites More sharing options...
opmo Posted September 12 Share Posted September 12 Done in OM 3.0.29099 Quote Link to comment Share on other sites More sharing options...
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.