Less than sensible, more than pretty, hopefully enjoyable, with a different notion of grouping. Based in part on this question. Gives a new meaning to bubble sort.
list = {a, b, c, d, e, f, g(*, h, l, m, n, o, p, q, r, s, t*)};
likeElements[list_, {idx_}] /; OddQ[idx] := list[[1 ;; ;; 2]];
likeElements[list_, {idx_}] /; EvenQ[idx] := list[[2 ;; ;; 2]];
coords = Transpose[{Range[#], RandomReal[{-0.01, 0.01}, #], RandomReal[{-0.01, 0.01}, #]}] &@Length[list];
Dynamic[
Refresh[Module[{d},
Graphics3D[GraphicsComplex[
coords -= MapIndexed[
Total[Function[x, (d = # - x)/(d = Sqrt[d.d]) Log@d/2^(2 + 2 Sqrt[d])] /@
Drop[likeElements[coords, #2], Ceiling[#2/2]]] +
Total[Function[x, -(d = # - x)/(d = Sqrt[d.d])^2 (d - 1/E) (1 - d/7)/2^(2 + 2 d)] /@
likeElements[coords, #2 + 1]] &, coords],
{MapIndexed[Text[Style[#1, ColorData[2][Mod[First[#2], 2]]], First[#2]] &, list],
Opacity[0.3], Sphere[Range@Length[list], E^-1]}],
PlotRange -> {{-1.5, Length[list] + 1.5}, 4 {-1, 1}, 4 {-1, 1}}]
],
UpdateInterval -> 1]]
Tweaking the coefficients slightly changes the behavior, which is also somewhat dependent on the length of the list. Won't win a speed contest.
The two Total[Function...]
expressions calculate the new positions based on like elements (same parity) attract (first Total
) and unlike repel (second Total
).
Span
e.g.Range[10][[;; ;; 2]]
andRange[10][[2 ;; ;; 2]]
$\endgroup$Part[A, #] & /@ GatherBy[Range@Length@lst, OddQ]
$\endgroup$TakeDrop[#, {1, -1, 2}] &
since V10.2. $\endgroup$