I have a list of the form
{{0, 0, 0, 0, 0, 0, a, b, c, d, e, f}, {0, 0, 0, 0, 0, 1, a, c, b, d, f, e}, {2, 2, 2, 2, 1, 2, b, f, c, a, d, e}, ... }
and I would like to translate it into variables of the form w[c1, c2, x, y]
following these rules:
- the values
c1
andc2
are taken from the numeric values of each sublist in order - the values of
x
andy
are taken from the string values of each sublist in order but each pair is reordered in alphanumeric order.
Following my example, I expect something of the form:
{w[0, 0, a, b] w[0, 0, c, d] w[0, 0, e, f], w[0, 0, a, c] w[0, 0, b, d] w[0, 1, e, f], w[2, 2, b, f] w[2, 2, a, c] w[1, 2, d, e], ...}
(notice the terms w[2, 2, c, a]
must be w[2, 2, a, c]
and similarly with w[0, 1, e, f]
)
I can use a replace function of the form /. {c1_,c2_,c3_,c4_, ..., a1_,a2_,a3_,a4,...} -> w[c1,c2,a1,a2] ...
but it does not seem a very optimal solution. Besides, I will need to generalize it in case I change the number of elements in my initial list.
This question is a follow-up to a previous question: Fast enumeration of all perfect matchings in complete graph, where the solution was Ok for that purpose, but now I need to recover the variables in this particular form.
w[]
meant to be products? Or is it a typo for missing comas? $\endgroup$