I have a sequence of SQL calls, which I want to use to detect loops (and hence unnecessary duplicate sql calls), but it got me thinking of this more general problem.
Given a list, say
[a,b,c,b,c,a,b,c,b,c,a,b,b]
Is there some way I can turn that into
a,[[b,c]*2,a]*2,b*2
or, [a,[b,c]*2]*2,a,b*2
That is, detect repetitions (possibly nested ones).