removing repeated items in a stream of numbers

Dec 13, 2006 at 11:53am

removing repeated items in a stream of numbers

is there an object which filters out numbers it has already received, a bit like [change] but with a memory?

#29204
Dec 13, 2006 at 12:27pm

I don’t think so, but you could make something with coll, like this:

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 200 105 33 196617 clear;
#P number 66 194 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 181 203 21 196617 t 0;
#P newex 66 165 29 196617 gate;
#P newex 181 178 32 196617 sel 1;
#P newex 106 114 49 196617 append 1;
#P newex 85 82 40 196617 t i i 1;
#P number 85 58 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N coll memory 1;
#P newobj 181 150 75 196617 coll memory 1;
#P comment 236 106 100 196617 start over;
#P connect 9 0 1 0;
#P connect 6 0 8 0;
#P fasten 7 0 6 0 186 229 169 229 169 158 71 158;
#P connect 5 0 7 0;
#P connect 1 0 5 0;
#P connect 3 0 6 1;
#P connect 3 0 4 0;
#P fasten 3 2 6 0 120 106 71 106;
#P connect 2 0 3 0;
#P connect 3 1 1 0;
#P connect 4 0 1 0;
#P window clipboard copycount 10;

Am 13.12.2006 um 11:53 schrieb bin ray:

>
> is there an object which filters out numbers it has already
> received, a bit like [change] but with a memory?

#90656
Dec 13, 2006 at 12:45pm

On 13-Dec-2006, at 11:53, bin ray wrote:

> is there an object which filters out numbers it has already
> received, a bit like [change] but with a memory?

Not that I know of, but it’s so easy to cobble something together
with Histo and gate. It’s not much different from the perennial ‘how
do I get random numbers without repeats?’

#P outlet 124 197 15 0;
#P window setfont “Sans Serif” 9.;
#P number 124 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 187 128 31 196617 == 1;
#P newex 124 154 29 196617 gate;
#P newex 143 104 54 196617 Histo 255;
#P number 143 82 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P inlet 143 62 15 0;
#P connect 2 0 3 1;
#P connect 5 0 6 0;
#P connect 3 0 5 0;
#P fasten 4 0 3 0 192 150 129 150;
#P connect 2 1 4 0;
#P connect 1 0 2 0;
#P connect 0 0 1 0;
#P window clipboard copycount 7;

“I’ve coughed up more frightening things than that before breakfast”
— Grandpa Simpson

Adding a clear message and parametizing the input data range left as
an exercise.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#90657
Dec 13, 2006 at 3:21pm

Quote: bin wrote on Wed, 13 December 2006 12:53
—————————————————-
> is there an object which filters out numbers it has already received, a bit like [change] but with a memory?
—————————————————-

Not that I know of, but you could make something pretty easily with the zl series..

Like this:

#P comment 71 251 28 196617 out;
#P comment 148 59 33 196617 reset;
#P newex 90 94 53 196617 t i i i 1;
#P number 71 232 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 118 183 21 196617 t 0;
#P newex 71 212 29 196617 gate;
#P message 148 94 41 196617 zlclear;
#P newex 148 143 18 196617 t l;
#P button 148 75 15 0;
#P number 90 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 118 164 40 196617 zl sect;
#P newex 148 123 44 196617 zl union;
#P comment 90 59 28 196617 in;
#P connect 6 0 2 0;
#P connect 6 0 1 0;
#P connect 1 0 5 0;
#P connect 4 0 6 0;
#P connect 7 0 9 0;
#P connect 5 0 1 1;
#P connect 5 0 2 1;
#P connect 2 0 8 0;
#P connect 10 3 7 0;
#P connect 10 0 7 1;
#P connect 3 0 10 0;
#P connect 8 0 7 0;
#P connect 10 2 2 0;
#P connect 10 1 1 0;

#90658
Dec 13, 2006 at 3:56pm

here is an urn with no repeats on end of loop

max v2;
#N vpatcher 495 244 1095 644;
#P window setfont “Sans Serif” 12.;
#P window linecount 1;
#P newex 143 340 31 9109516 print;
#P button 80 74 15 0;
#P newex 86 219 27 9109516 i;
#P newex 102 301 21 9109516 t b;
#P newex 86 269 50 9109516 sel 1;
#P newex 86 245 48 9109516 ==;
#P newex 84 188 50 9109516 t i b i;
#P window linecount 2;
#P message 124 143 36 9109516 clear , bang;
#P window linecount 1;
#P newex 84 116 50 9109516 urn 10;
#P newex 102 332 31 9109516 i;
#P connect 8 0 1 0;
#P fasten 5 0 1 0 91 293 191 293 191 110 89 110;
#P fasten 2 0 1 0 129 183 194 183 194 108 89 108;
#P connect 1 0 3 0;
#P connect 3 1 7 0;
#P connect 7 0 4 0;
#P connect 4 0 5 0;
#P connect 5 1 6 0;
#P connect 6 0 0 0;
#P connect 3 0 7 1;
#P connect 3 2 0 1;
#P connect 1 1 2 0;
#P connect 3 2 4 1;
#P connect 0 0 9 0;
#P pop;

On 12/13/06, Mattijs Kneppers wrote:
>
>
> Quote: bin wrote on Wed, 13 December 2006 12:53
> —————————————————-
> > is there an object which filters out numbers it has already received, a
> bit like [change] but with a memory?
> —————————————————-
>
> Not that I know of, but you could make something pretty easily with the zl
> series..
>
> Like this:
>
> #P comment 71 251 28 196617 out;
> #P comment 148 59 33 196617 reset;
> #P newex 90 94 53 196617 t i i i 1;
> #P number 71 232 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 118 183 21 196617 t 0;
> #P newex 71 212 29 196617 gate;
> #P message 148 94 41 196617 zlclear;
> #P newex 148 143 18 196617 t l;
> #P button 148 75 15 0;
> #P number 90 76 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 118 164 40 196617 zl sect;
> #P newex 148 123 44 196617 zl union;
> #P comment 90 59 28 196617 in;
> #P connect 6 0 2 0;
> #P connect 6 0 1 0;
> #P connect 1 0 5 0;
> #P connect 4 0 6 0;
> #P connect 7 0 9 0;
> #P connect 5 0 1 1;
> #P connect 5 0 2 1;
> #P connect 2 0 8 0;
> #P connect 10 3 7 0;
> #P connect 10 0 7 1;
> #P connect 3 0 10 0;
> #P connect 8 0 7 0;
> #P connect 10 2 2 0;
> #P connect 10 1 1 0;
>
> –
> SmadSteck – http://www.smadsteck.nl
> Interactive audiovisual sampling soft- and hardware
>
>

#90659
Dec 13, 2006 at 4:55pm

On 13-Dec-2006, at 16:21, Mattijs Kneppers wrote:

> Not that I know of, but you could make something pretty easily

Is anyone keeping score?

Ray should offer prizes for smallest and most flexible solutions.
Say, a meal at Chez Gerard near Victoria.

– P

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#90660
Dec 13, 2006 at 5:20pm

Quote: Peter Castine wrote on Wed, 13 December 2006 17:55
—————————————————-
> On 13-Dec-2006, at 16:21, Mattijs Kneppers wrote:
>
> > Not that I know of, but you could make something pretty easily
>
> Is anyone keeping score?
>
> Ray should offer prizes for smallest and most flexible solutions.
> Say, a meal at Chez Gerard near Victoria.

That would be awesome. From a pre-announced moment, people submit solutions during one day. To determine the winner, time of posting after launch, originality, flexibility, cpu-efficiency and of course size (on screen and in text) will be taken into account.

I would definitely participate! Already drooling on possible problems :D..

Mattijs

Btw, if the prize is a meal in NY, has someone got a spare bed? I’ll pay the beer.

#90661
Dec 14, 2006 at 12:21am

thanks! …the histo one works fine

#90662
Dec 14, 2006 at 2:52pm

Mattijs Kneppers wrote:
> Not that I know of, but you could make something pretty easily with
> the zl series..

nice one, though its restricted to the last 256 entries, but this could
be an advantage…
And the same idea with a limit of 4096 elements:

Stefan

#P window setfont “Sans Serif” 9.;
#P number 111 254 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 111 232 83 196617 mxj list.Length;
#P newex 174 108 32 196617 int;
#P button 208 64 15 0;
#P newex 174 86 44 196617 onebang;
#P comment 71 273 28 196617 out;
#P newex 90 64 115 196617 t i i i 1 b i;
#P number 71 254 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 132 205 21 196617 t 0;
#P newex 71 232 29 196617 gate;
#P newex 111 158 22 196617 t l;
#P number 90 46 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 132 183 102 196617 mxj list.Intersection;
#P newex 111 135 73 196617 mxj list.Union;
#P comment 90 29 28 196617 in;
#P comment 199 42 32 196617 reset;
#P connect 5 0 14 0;
#P connect 5 0 2 1;
#P fasten 5 0 3 1 116 178 229 178;
#P connect 13 0 2 1;
#P fasten 13 0 3 1 179 129 229 129;
#P connect 3 0 7 0;
#P connect 9 1 2 0;
#P connect 2 0 5 0;
#P connect 14 0 15 0;
#P connect 9 4 11 0;
#P connect 9 5 13 1;
#P connect 11 0 13 0;
#P connect 9 2 3 0;
#P connect 4 0 9 0;
#P connect 9 0 6 1;
#P fasten 9 3 6 0 158 114 76 114;
#P connect 12 0 11 1;
#P fasten 7 0 6 0 137 227 76 227;
#P connect 6 0 8 0;
#P window clipboard copycount 16;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#90663
Dec 14, 2006 at 3:12pm

bin ray wrote:
> thanks! …the histo one works fine

but is limited to a VERY limited range.
The most universal one is the solution from Jeremy. To make it a bit
smaller I’d do it like that:

#P window setfont “Sans Serif” 9.;
#P number 76 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 95 51 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 153 99 29 196617 clear;
#P newex 76 151 29 196617 gate;
#P newex 120 99 28 196617 pack;
#P newex 95 72 85 196617 t i i i 1;
#N coll ;
#P newobj 145 125 37 196617 coll;
#P connect 1 1 2 0;
#P fasten 2 0 0 0 125 121 150 121;
#P fasten 0 0 3 0 150 146 81 146;
#P fasten 1 3 3 0 175 94 81 94;
#P connect 1 0 3 1;
#P connect 3 0 6 0;
#P fasten 4 0 0 0 158 121 150 121;
#P connect 5 0 1 0;
#P connect 1 2 0 0;
#P window clipboard copycount 7;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#90664
Dec 14, 2006 at 3:17pm

bin ray wrote:
> thanks! …the histo one works fine

but is limited to a VERY limited range.
The most universal one is the solution from Jeremy. To make it a bit
smaller I’d do it like that:

#P window setfont “Sans Serif” 9.;
#P number 76 175 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 95 51 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 153 99 29 196617 clear;
#P newex 76 151 29 196617 gate;
#P newex 120 99 28 196617 pack;
#P newex 95 72 85 196617 t i i i 1;
#N coll ;
#P newobj 145 125 37 196617 coll;
#P connect 1 1 2 0;
#P fasten 2 0 0 0 125 121 150 121;
#P fasten 0 0 3 0 150 146 81 146;
#P fasten 1 3 3 0 175 94 81 94;
#P connect 1 0 3 1;
#P connect 3 0 6 0;
#P fasten 4 0 0 0 158 121 150 121;
#P connect 5 0 1 0;
#P connect 1 2 0 0;
#P window clipboard copycount 7;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#90665
Dec 14, 2006 at 3:22pm

So, do I get the free dinner?

jb

Am 14.12.2006 um 16:12 schrieb Stefan Tiedje:

> the solution from Jeremy

#90666
Dec 14, 2006 at 5:11pm

Quote: Jeremy Bernstein wrote on Thu, 14 December 2006 16:22
—————————————————-
> So, do I get the free dinner?
>
> jb
>

I agree, Jeremy wins. Although Stephans addition makes it better. Only, Stephan, you shouldn’t have added an extra output to the trigger, I liked that part in Jeremey’s patch.

Mattijs

#90667
Dec 16, 2006 at 12:10pm

Mattijs Kneppers wrote:
> I agree, Jeremy wins. Although Stephans addition makes it better.
> Only, Stephan, you shouldn’t have added an extra output to the
> trigger, I liked that part in Jeremey’s patch.

Or what about splitting new and old? (and if you need a trigger use a
bangbang…)

Stefan (with the f…)

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#N vpatcher 20 74 620 474;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 50 50 58 196617 route bang;
#P newex 50 72 39 196617 t clear;
#P newex 58 151 50 196617 gate 2;
#P newex 109 99 48 196617 pack 0 2;
#P newex 98 72 43 196617 t i i i 1;
#N coll ;
#P newobj 120 125 43 196617 coll;
#P inlet 50 30 15 0;
#P outlet 98 173 15 0;
#P outlet 58 173 15 0;
#P connect 2 0 8 0;
#P connect 8 0 7 0;
#P fasten 4 3 6 0 136 94 63 94;
#P fasten 3 0 6 0 125 146 63 146;
#P connect 6 0 0 0;
#P connect 8 1 4 0;
#P connect 4 0 6 1;
#P connect 6 1 1 0;
#P connect 4 1 5 0;
#P connect 4 2 3 0;
#P fasten 5 0 3 0 114 121 125 121;
#P fasten 7 0 3 0 55 121 125 121;
#P pop;
#P newobj 32 69 47 196617 p splold;
#P number 69 114 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 32 114 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 32 32 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 87 32 16 196617 7;
#P message 69 32 16 196617 3;
#P button 106 32 15 0;
#P window linecount 8;
#P comment 128 33 100 196617 split new and old values. new values come
out the left outlet , once it happend they come out the right outlet…
A bang erases the memory.;
#P connect 1 0 7 0;
#P connect 2 0 7 0;
#P connect 3 0 7 0;
#P connect 4 0 7 0;
#P connect 7 1 6 0;
#P connect 7 0 5 0;
#P window clipboard copycount 8;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#90668
Dec 17, 2006 at 1:38pm

Quote: Stefan Tiedje wrote on Sat, 16 December 2006 13:10
—————————————————-
> Mattijs Kneppers wrote:
> > I agree, Jeremy wins. Although Stephans addition makes it better.
> > Only, Stephan, you shouldn’t have added an extra output to the
> > trigger, I liked that part in Jeremey’s patch.
>
> Or what about splitting new and old? (and if you need a trigger use a
> bangbang…)
>
> Stefan (with the f…)
>

Hi Stefan (sorry about the ph),

A nice improvement. I would do the trigger Jeremy’s way though (note the [t i i 1] has one less i compared to Stefan’s). Updating the coll and outputting through the gate don’t have to be in sync. It even has some educational value.. :)

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#N vpatcher 20 74 255 319;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 98 71 55 9109513 t i i 1;
#P newex 50 50 58 9109513 route bang;
#P newex 50 72 39 9109513 t clear;
#P newex 58 151 50 9109513 gate 2;
#P newex 109 99 48 9109513 pack 0 2;
#N coll ;
#P newobj 120 125 43 9109513 coll;
#P inlet 50 30 15 0;
#P outlet 98 173 15 0;
#P outlet 58 173 15 0;
#P connect 2 0 7 0;
#P connect 7 0 6 0;
#P fasten 8 2 5 0 147 94 63 94;
#P fasten 3 0 5 0 125 146 63 146;
#P connect 5 0 0 0;
#P connect 7 1 8 0;
#P connect 8 0 5 1;
#P connect 5 1 1 0;
#P fasten 8 0 4 0 103 97 114 97;
#P connect 8 1 3 0;
#P fasten 6 0 3 0 55 121 125 121;
#P fasten 4 0 3 0 114 121 125 121;
#P pop;
#P newobj 24 76 47 9109513 p splold;
#P number 61 121 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 24 121 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 24 39 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 79 39 16 9109513 7;
#P message 61 39 16 9109513 3;
#P button 98 39 15 0;
#P window linecount 8;
#P comment 120 40 93 9109513 split new and old values. new values come out the left outlet , once it happend they come out the right outlet… A bang erases the memory.;
#P connect 7 0 5 0;
#P connect 7 1 6 0;
#P connect 4 0 7 0;
#P connect 3 0 7 0;
#P connect 2 0 7 0;
#P connect 1 0 7 0;
#P window clipboard copycount 8;

#90669
Dec 18, 2006 at 9:34pm

Mattijs Kneppers wrote:
> A nice improvement. I would do the trigger Jeremy’s way though (note
> the [t i i 1] has one less i compared to Stefan’s). Updating the coll
> and outputting through the gate don’t have to be in sync. It even has
> some educational value.. :)

Both is identical, even the order of execution. If there is a trigger
object anyway, I never connect any of the outlets to two different
destinations, instead, i put in as many outlets as I need connections.
Especially in an educational context, it will make the patch more
readable even if the order does not matter for all connections…

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#90670
Dec 20, 2006 at 10:38am

Quote: Stefan Tiedje wrote on Mon, 18 December 2006 22:34
—————————————————-
> Mattijs Kneppers wrote:
> > A nice improvement. I would do the trigger Jeremy’s way though (note
> > the [t i i 1] has one less i compared to Stefan’s). Updating the coll
> > and outputting through the gate don’t have to be in sync. It even has
> > some educational value.. :)
>
> Both is identical, even the order of execution. If there is a trigger
> object anyway, I never connect any of the outlets to two different
> destinations, instead, i put in as many outlets as I need connections.
> Especially in an educational context, it will make the patch more
> readable even if the order does not matter for all connections…
>

Ah, as a rule I never make multiple connections in a forced order when their order doesn’t matter. This helps me understand my old patches. That is a point I would prefer to make to new max users.

Although I agree that this specific patch is more readable if you put in more outlets.

Mattijs

#90671
Dec 21, 2006 at 6:01pm

I think I would use a javascript for this … would it be less performant than a native-max version using colls, zl, etc ?

#90672
Dec 22, 2006 at 11:59am

Quote: julienbreval wrote on Thu, 21 December 2006 19:01
—————————————————-
> I think I would use a javascript for this … would it be less performant than a native-max version using colls, zl, etc ?
—————————————————-

That would be a nice test! Would you care do it for us? Let a qmetro empty some uzi’s on the patch/js and see what the maximum framerate is in both cases. Or do it with a fixed metro and see what the avarage cpu usage is on both cases. I’m curious!

Mattijs

#90673
Dec 27, 2006 at 2:39pm

Quote: Mattijs wrote on Fri, 22 December 2006 12:59
—————————————————-
> That would be a nice test! Would you care do it for us?
—————————————————-

Why not ? But I am moving from my apartment this week and I don’t have any more computer with Max/MSP here. The computer that I use today for mail and so on has no installed operating system so I am using a K-ubuntu Linux live CD :)

The only problem I see about the javascript is that the list of numbers that have already occured can only be longer and longer, hence the algorithm will be slower and slower. Maybe computers are fast enough for you don’t see any difference but it has to be tested. Solutions to his could be:
- limiting the size of the memory to N elements
- using a manual reset

#90674

You must be logged in to reply to this topic.