I was willing to understand the Coolwater's solution of the presented problem here. He proposed the below solution
go[L_, m_] := Normal[SparseArray[Flatten[With[{R = Range[Length[L]]},
MapIndexed[Thread[Thread[{First[#2],
Join[#, Complement[R, #]]}] -> L] &, Subsets[R, {m}]]], 1]]]
go[{1, 2, 3, 4, 5}, 2]
In a reverse procedure I have obtained
L = {1, 2, 3, 4, 5}; R = Range[Length[L]]; m = 2;
Subsets[R, {m}]
(**{{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}}**)
MapIndexed[
Thread[Thread[{First[#2], Join[#, Complement[R, #]]}] -> L] &,
Subsets[R, {m}]]
(**{{{1, 1} -> 1, {1, 2} -> 2, {1, 3} -> 3, {1, 4} -> 4, {1, 5} ->
5}, {{2, 1} -> 1, {2, 3} -> 2, {2, 2} -> 3, {2, 4} -> 4, {2, 5} ->
5}, {{3, 1} -> 1, {3, 4} -> 2, {3, 2} -> 3, {3, 3} -> 4, {3, 5} ->
5}, {{4, 1} -> 1, {4, 5} -> 2, {4, 2} -> 3, {4, 3} -> 4, {4, 4} ->
5}, {{5, 2} -> 1, {5, 3} -> 2, {5, 1} -> 3, {5, 4} -> 4, {5, 5} ->
5}, {{6, 2} -> 1, {6, 4} -> 2, {6, 1} -> 3, {6, 3} -> 4, {6, 5} ->
5}, {{7, 2} -> 1, {7, 5} -> 2, {7, 1} -> 3, {7, 3} -> 4, {7, 4} ->
5}, {{8, 3} -> 1, {8, 4} -> 2, {8, 1} -> 3, {8, 2} -> 4, {8, 5} ->
5}, {{9, 3} -> 1, {9, 5} -> 2, {9, 1} -> 3, {9, 2} -> 4, {9, 4} ->
5}, {{10, 4} -> 1, {10, 5} -> 2, {10, 1} -> 3, {10, 2} ->
4, {10, 3} -> 5}}**)
Which are some results of the solution parties. But I have tried to understand what happen in the first Thread Thread[{First[#2], Join[#, Complement[R, #]]}]
and the second Thread Thread[Thread[{First[#2], Join[#, Complement[R, #]]}] -> L]
.
Because in the first Thread have used #
which returns to Subsets[R, {m}]
and inside the second Thread have used ->
. I cannot use of just Subsets[R, {m}]
for investigating the Thread process also in the Mathematica help I cannot find a Thread with ->
.
In fact what is the duties of two used Thread?!! Can anyone say in a clarified way?!