This seems like a very inefficient way of doing what I want. I generate all permutations of (for example) {1, 1, 2, 2}
, then for each permutation I generate its rotations, select the first one in Sort
order, and use that for GatherBy
.
list = {1, 1, 2, 2};
display@GatherBy[Permutations@list, Sort[Table[RotateLeft[#, i], {i, 0, Length@# - 1}]][[1]]& ]
(* {{"1122", "1221", "2112", "2211"}, {"1212", "2121"}} *)
How can I do this more efficiently?