Removing consecutive duplicates from a message

bwc's icon

Hello!

I've been attempting to remove consecutive duplicates from a message, while not removing non-consecutive duplicates, such that, for example, "0 3 1 4 4 5 4 8" would return "0 3 1 4 5 4 8". As well, it should work for any number of consecutive duplicates, such as "0 3 1 4 4 4 5 4 8" to "0 3 1 4 5 4 8".

I've tried different combinations of zl iter 2, zl thin, and trying to recollect the output into a single message, but I haven't been able to figure out the right flow. Any suggestions or alternative ideas?

Thanks!
Bryan

brendan mccloskey's icon

Hmm

good problem....
Sounds like you could store your list somewhere, then output in pairs after checking for duplicates; could you [zl group 2] your number stream, then thin and recombine?

Only recently discovered the 'Joy of [zl]' so forgive noobness

Brendan

FRid's icon

I hope i understood correctly but i think this will work.
FRid

`

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

and indeed much like Brendan's description

xidance's icon

it´s easy if i understand it right. but you have to handle the first item seperately. like in frid's patch the result would be wrong if the initial list would start with "1" - or in general if the first item of the list to filter equals the last item of recently filtered list.

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

`

xidance's icon

another way, using zl slice for the exception (edit: and zl join):

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

`

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

This may not be the most efficient approach, but it is simple:

xidance's icon

@chris

it loses the 0 as first item when [change] still has its initial 0 (or first item, if it equals the last item of the previous list).

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

OK, so set it to something you never expect to see:

xidance's icon

sure, but someone wins the lottery. means it challenges weird coincidences when handling huge amounts of filtered lists.

xidance's icon

my second version has a similar bug, it doesn´t work for starting "0 0" in the example. fixing it is a bit too complicated due to the message order of zl slice.

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

but it works for all possible integers in any order:

bwc's icon

Thanks everyone - this helped out a lot!

Ben Bracken's icon
Max Patch
Copy patch and select New From Clipboard in Max.

A good opportunity to take advantage of the 'zlclear' message:

xidance's icon

[zl change]... it´s just so simple.

Floating Point's icon
Max Patch
Copy patch and select New From Clipboard in Max.

you only need one object to do this: [zl sect}:

Ben Bracken's icon

Nice, Terry!

yp's icon

bwc: "I've been attempting to remove consecutive duplicates from a message, while not removing non-consecutive duplicates,"
[zl sect] does remove non-consecutive duplicates, as in the example terry provided.