Jump to content

Featured Replies

Posted

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?

  • 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)

 

(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)

 

  • Author

I would suggest to add a keyword :sum to the function scale-numbers.

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


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy