Forums > MaxMSP

quick addition of many numbers

September 2, 2008 | 2:27 pm

Greetings,

I’m looking to do some adding. For one, I’d like to be able to quickly add the numbers present in a list together. No [zl] mode that I know of does this. My list contains, for example, [1, 3, 4, 6, 7]. Upon inputting the list into this object, the sum (21) will be output.

Also, I’d like to have an object or abstraction that keeps a running total of the sum of all the numbers which are input into it.

These two are actually pretty similar. What’s the best way of accomplishing this in 4.6?

Jay


September 2, 2008 | 2:31 pm

[accum]


September 2, 2008 | 2:41 pm

I would say [iter] – [accum]

but bizarrely on my machine on both max 5 and 4.6, accum isn’t accumulating.

Mac OS X 10.5.4
Max 5.0.3 and 4.6.3


September 2, 2008 | 2:44 pm

Thanks for the responses. I’m not familiar with [accum]. Sounds like I need to get familiar.

Jay


September 2, 2008 | 6:28 pm

There is a zl mode. It’s zl sum. I’m not sure if that mode exists under 4.6, however. Accum certainly will work, and you could easily use iter, trigger, and accum together to make an abstraction that did the same thing as zl sum.


September 2, 2008 | 7:00 pm

On Sep 2, 2008, at 11:28 AM, Jer Welter wrote:

> There is a zl mode. It’s zl sum. I’m not sure if that mode exists
> under 4.6, however.

It doesn’t.

You could also use + with feedback:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 389 373 103 196617 Number box optional;
#P window linecount 2;
#P comment 91 373 103 196617 Number box required to break feedback;
#P window linecount 1;
#P message 197 91 103 196617 1 2 3 4 5 6 7 8 9 10;
#P newex 197 139 25 196617 iter;
#P newex 197 111 27 196617 t l b;
#P comment 139 216 60 196617 Numbers In;
#P button 266 215 15 0;
#P newex 207 321 27 196617 t i i;
#P number 350 371 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 350 321 27 196617 t b i;
#P newex 350 348 44 196617 accum;
#P number 197 215 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 266 284 14 196617 0;
#P number 197 371 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 197 348 37 196617 +;
#P comment 283 218 35 196617 Reset;
#P connect 13 0 11 0;
#P connect 12 0 4 0;
#P connect 11 0 12 0;
#P fasten 11 1 9 0 219 133 271 133;
#P connect 4 0 1 0;
#P connect 4 0 6 0;
#P connect 3 0 8 0;
#P connect 3 0 5 0;
#P connect 9 0 3 0;
#P connect 8 0 1 0;
#P connect 8 1 1 1;
#P connect 5 0 7 0;
#P connect 6 1 5 1;
#P connect 6 0 5 0;
#P fasten 2 0 1 1 202 391 238 391 238 343 229 343;
#P connect 1 0 2 0;
#P window clipboard copycount 16;

Chris Muir
cbm@well.com

http://www.xfade.com



kjg
September 2, 2008 | 7:49 pm

another option, providing the lists don’t get longer than 9 items:

expr $i1+$i2+$i3+$i4+$i5+$i6+$i7+$i8+$i9


September 2, 2008 | 10:23 pm

On 2 sept. 08, at 21:49, Klaas-Jan Govaart wrote:

> another option, providing the lists don’t get longer than 9 items:

another one: [mean] * [zl len] ;-)

ej


September 3, 2008 | 9:58 am

Send your list to lp.sigma.

It’s that easy.

Lp.sigma is in the Litter Starter Pack. URI below.

Some folks have suggested that a name like "lp.add" or "lp.sum" might be more obvious, but I actually polled Litter Power users on this and the broad majority found sigma sufficiently obvious and/or more attractive. So there it is.

Best — Peter


September 3, 2008 | 10:04 am

Quote: Emmanuel Jourdan wrote on Wed, 03 September 2008 00:23
—————————————————-
> another one: [mean] * [zl len] ;-)
—————————————————-

Cute, but does have potential precision problems with int/float conversion.

Never mind that it’s a Rube Goldberg-like solution to a simple problem. (Heath Robinson for the Brits)


Viewing 10 posts - 1 through 10 (of 10 total)