# resolved list sum

## Recommended Posts

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?

##### Share on other sites

Do you mean: get-count

##### Share on other sites

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

##### Share on other sites

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

##### Share on other sites

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.

##### Share on other sites

The function scale-to-sum is part of OM 3.0.29095

##### Share on other sites

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

##### Share on other sites

Yes, this could be done. I will have a look.

##### Share on other sites

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

##### Share on other sites

Done in OM 3.0.29099

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
• #### Browser

• Video Gallery

• Lessons