Sum of Integers in Coll
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
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:
Chris Muir
cbm@well.com
http://www.xfade.com
That's cracked it! Many thanks Chris.
Regards,
Nick
Also, the almighty zl offers some options:
"the almighty zl"
Indeed it is. This seems to be an even more elegant solution. Thank you Ben.
Bests,
Nick
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
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