The following code produces lists of sublists with maximum length 5 that shuffle zeros around an ordered list (here {1,2}
). It produces all permutations while keeping the ordering of the list {1,2}
within the permutations:
mylst[K_]:=Select[Drop[Tuples[{0,1,2},K],1],Total[#]==3&&Count[#,1]==1&&#[[Position[#,x_/;!TrueQ[x==0],{1},1,Heads->False][[1,1]]]]!=2&]
mylst /@ Range[5]
Each of mylst[K]
generates $K(K-1)/2$ terms.
Is there a better way to code mylst
?