Sum of Integers in Coll

njw's icon

Hello,

How do I find the sum of ten integers stored (from index 0-9) in coll?

I'm sure there is a simple way to do it but I just can't get my head around it.

Thanks for your help.

nick

Chris Muir's icon

On Nov 21, 2008, at 11:23 AM, nick williams wrote:

> How do I find the sum of ten integers stored (from index 0-9) in coll?

I don't know of a simpler way than indexing through the range you want
to sum, and accumulating them:

Max Patch
Copy patch and select New From Clipboard in Max.

Chris Muir
cbm@well.com    
http://www.xfade.com

njw's icon

That's cracked it! Many thanks Chris.

Regards,

Nick

Ben Bracken's icon

Also, the almighty zl offers some options:

Max Patch
Copy patch and select New From Clipboard in Max.

njw's icon

"the almighty zl"

Indeed it is. This seems to be an even more elegant solution. Thank you Ben.

Bests,

Nick

njw's icon

I've just been experimenting with Ben's patch and discovered that it was getting it's sums wrong! It seems that the arguments in the zl object just needed to be switched e.g. List length followed by Mode. After switching these arguments Ben's patch gives the correct sum.

It seems that the zl helpfile may be misleading, stating:

"The first argument to the zl object sets its mode of operation"

This does not appear to be the case if using zl in Group mode.

Anyhoo, I have switched the zl arguments and included the patch in this post to resolve the issue for anyone interested in this thread in the future.

Cheers to all,

Nick

Max Patch
Copy patch and select New From Clipboard in Max.

Luke Hall's icon

In fact an integer before the mode argument sets the maximum size of lists that [zl] will work with. The default is 256 I think. In your case both [zl 10 group] and [zl group 10] will work, but if you want to then change the number of items to group using the right inlet to something more than 10 then only the latter example will.

lh