I would like to “contract” a list of any length k, consisting of n=2 repeating elements, so that all repetitions within the sequence are deleted:
In[1]:= {a, a, b, b, a, b, b, b, a, a, b, b, a};
Out= {a, b, a, b, a, b, a} (*desired output*)
Or in the case of n=3:
In[2]:= {b, a, a, c, a, b, b, c, c, b, a, a, a, b, c, c, c, a, a}
Out= {b, a, c, a, b, c, b, a, b, c, a} (*desired output*)
I am thinking of FoldList or Fold but cannot figure out how to get there in the most succinct manner. Pattern matching also allowed. Thanks in advance for your help!