Posted September 11, 20231 yr 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?
September 11, 20231 yr Author 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)
September 11, 20231 yr (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)
September 11, 20231 yr 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.
September 12, 20231 yr 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)
Create an account or sign in to comment