Apologies for the simple nature but can't quite grasp a nice way of doing this.
take a list ~ m0 = Table[RandomInteger[], 20]
{1,1,0,1,0,1,0,0,0,0,1,1,1,1,1,1,1,0,1,1}
I want to send any 1 followed by a 1 to 0 such that the example would go to:
{0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1}
I'm sure there is a quick and elegant way of doing this but it escapes me without a clunky method using ReplaceRepeated[].
Thanks if anyone has a go.
Edit*
Just for reference of timing:
In[27]:= m0
ReplaceRepeated[m0,{s___,1,1,e___} :> {s,0,1,e}]//AbsoluteTiming
Out[27]= {1,1,0,1,0,1,0,0,0,0,1,1,1,1,1,1,1,0,1,1}
Out[28]= {0.0000940839,{0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1}}
Edit*
Thanks for all the Interesting attempts! Here is the timings when scaled to a bigger list
In[205]:= m0//Length
ReplaceRepeated[m0,{s___,1,1,e___} :> {s,0,1,e}];//RepeatedTiming
Flatten[Split[m0]/.{x__,1}:>{0{x},1}];//RepeatedTiming
Differences[Append[m0,0]]/.{-1->1,1->0};//RepeatedTiming
First/@(Partition[Append[m0,0],2,1]/.{1,1}->{0,0});//RepeatedTiming
Append[BitShiftRight@@@Partition[m0,2,1],Last@m0];//RepeatedTiming
Out[205]= 500
Out[206]= {0.0020,Null}
Out[207]= {0.0004,Null}
Out[208]= {0.000097,Null}
Out[209]= {0.00036,Null}
Out[210]= {0.00020,Null}
