Removing consecutive duplicates from a message
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
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
I hope i understood correctly but i think this will work.
FRid
`
and indeed much like Brendan's description
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.
`
another way, using zl slice for the exception (edit: and zl join):
`
This may not be the most efficient approach, but it is simple:
@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).
OK, so set it to something you never expect to see:
sure, but someone wins the lottery. means it challenges weird coincidences when handling huge amounts of filtered lists.
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.
but it works for all possible integers in any order:
Thanks everyone - this helped out a lot!
A good opportunity to take advantage of the 'zlclear' message:
[zl change]... it´s just so simple.
you only need one object to do this: [zl sect}:
Nice, Terry!
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.