First of all, I would like to thank everybody who took part in the discussion. I am still sure that shuffleWis probably the best choice to adapt for my problem. The other promising option were the indexing proposed by @Carl Woll. However it certainly exceeds my current level.
Yet I would like to present an algorithm correcting the version of @march. The algorithm is certainly not efficient enough, but it gives the correct answer without intermediate producing of reduntant sequences.
solution[in_List,n_]:=Module[{k=Length[in],s,ss},
s=Flatten[Permutations/@IntegerPartitions[n-k,{k+1}],1];
ss=Flatten[Permutations/@IntegerPartitions[n-k,{k}],1];
s=Join[Append[0]/@ss,s,Prepend[0]/@ss];
s=Table[0,{#}]&/@#&/@s; (* Taken from @march. Amusing construction. *)
Table[Flatten[Riffle[s[[i]],in]],{i,Length[s]}]
]
solution[{1,2,3},7]
{{0,0,1,0,2,0,3},{0,1,0,0,2,0,3},{0,1,0,2,0,0,3},{0,1,0,2,0,3,0},{1,0,0,2,0,3,0},{1,0,2,0,0,3,0},{1,0,2,0,3,0,0}}
Besides the code
solution[{},7]
results in:
{{0,0,0,0,0,0,0}},
which was very desired (I forgot to mention it in my question).
============= EDIT 26.02.2017
On the advice of Mr.Wisard I have tried to adapt shuffleW code to my problem. I report here on the result.
First of all a function generating allowed binary permutations was constructed:
rp[m_,n_] := Module[{p,q,nn=Binomial[n,m],mm=Binomial[n-1,m-1],i,j,k},
If[n<m,Return[{{}}]];
p=ConstantArray[0,{mm+nn,m+n}];
q=Permutations[Join[ConstantArray[1,m],ConstantArray[0,n-m]]];
For[j=1,j≤mm,j++,k=1;For[i=1,i≤n,i++,If[q[[j,i]]==1,p[[j,k]]=1;k++];k++]];
For[j=1,j≤nn,j++,k=1;For[i=1,i≤n,i++,If[q[[j,i]]==1,k++;p[[j+mm,k]]=1];k++]];
p
]
Further the shuffleW code was reduced to:
shuffle0[s_, n_] := Module[{p, ord},
p = rp[Length[s],n-Length[s]]//Transpose;
ord = Accumulate[p] p + 1;
Outer[Part, {Join[{0}, s]}, ord, 1][[1]]//Transpose
]
The resulting code seems to be quite fast.
With original shuffleW code one can readily solve a more general problem. Given two sets s1,s2 (Length[s1]<=Length[s2]) find all the "shuffled" sequences, in which the elements of s1 are cyclically separated by at least one element of s2.
shuffleA[s1_,s2_] := Module[{p,tp,ord},
p = rp[Length[s1],Length[s2]]//Transpose;
tp = BitXor[p, 1];
ord = Accumulate[p] p + (Accumulate[tp] + Length[s1]) tp;
Outer[Part, {Join[s1,s2]}, ord, 1][[1]]//Transpose
]
PermutationswithRiffleand add enough zeros to the list for larger values ofn– grbl Feb 23 '17 at 16:08Table[{i,j,k}, {i, 1, 3}, {j, i+2, 5}, {k, j+2, 7}]into a recursive function? The Table call produces a list of triplets for where the nonzero entries are positioned. – Carl Woll Feb 23 '17 at 17:11