Mathematica Asked on February 23, 2021
I have a system which is composed of the following blocks
$$[-,+],[+,+],[+,-],[-,-]$$
I can compose a system of $n$ blocks with the only rule that the edges act as a dipole.
for example
$$[-,+][-,+][-,-][+,-]$$
is a possible configuration of $n=4$.
Is it possible to create a code with mathematica that will produce all the possible configurations for any given $n$?
AttachDipole[x : {___, {_, "+"}}] := Append[x, #] & /@ {{"-", "-"}, {"-", "+"}};
AttachDipole[x : {___, {_, "-"}}] := Append[x, #] & /@ {{"+", "-"}, {"+", "+"}};
AttachDipoles[dipls_List] := Join @@ AttachDipole /@ dipls
AllDipoles[n_] :=
Nest[AttachDipoles, {{{"-", "-"}}, {{"-", "+"}}, {{"+", "-"}}, {{"+", "+"}}}, n - 1]
AllDipoles[1]
{{{"-", "-"}}, {{"-", "+"}}, {{"+", "-"}}, {{"+", "+"}}}
AllDipoles[2]
{{{"-", "-"}, {"+", "-"}}, {{"-", "-"}, {"+", "+"}}, {{"-", "+"}, {"-", "-"}}, {{"-", "+"}, {"-", "+"}}, {{"+", "-"}, {"+", "-"}}, {{"+", "-"}, {"+", "+"}}, {{"+", "+"}, {"-", "-"}}, {{"+", "+"}, {"-", "+"}}}
AllDipoles[3]
{{{"-", "-"}, {"+", "-"}, {"+", "-"}}, {{"-", "-"}, {"+", "-"}, {"+", "+"}}, {{"-", "-"}, {"+", "+"}, {"-", "-"}}, {{"-", "-"}, {"+", "+"}, {"-", "+"}}, {{"-", "+"}, {"-", "-"}, {"+", "-"}}, {{"-", "+"}, {"-", "-"}, {"+", "+"}}, {{"-", "+"}, {"-", "+"}, {"-", "-"}}, {{"-", "+"}, {"-", "+"}, {"-", "+"}}, {{"+", "-"}, {"+", "-"}, {"+", "-"}}, {{"+", "-"}, {"+", "-"}, {"+", "+"}}, {{"+", "-"}, {"+", "+"}, {"-", "-"}}, {{"+", "-"}, {"+", "+"}, {"-", "+"}}, {{"+", "+"}, {"-", "-"}, {"+", "-"}}, {{"+", "+"}, {"-", "-"}, {"+", "+"}}, {{"+", "+"}, {"-", "+"}, {"-", "-"}}, {{"+", "+"}, {"-", "+"}, {"-", "+"}}}
Correct answer by Hausdorff on February 23, 2021
Here is a one liner:
n = 3;
DeleteCases[Tuples[Tuples[{-1, 1}, 2], n], {___, {_, x_}, {y_, _}, ___} /; ( x == y)]
{{{-1, -1}, {1, -1}, {1, -1}}, {{-1, -1}, {1, -1}, {1,
1}}, {{-1, -1}, {1, 1}, {-1, -1}}, {{-1, -1}, {1, 1}, {-1,
1}}, {{-1, 1}, {-1, -1}, {1, -1}}, {{-1, 1}, {-1, -1}, {1,
1}}, {{-1, 1}, {-1, 1}, {-1, -1}}, {{-1, 1}, {-1, 1}, {-1,
1}}, {{1, -1}, {1, -1}, {1, -1}}, {{1, -1}, {1, -1}, {1,
1}}, {{1, -1}, {1, 1}, {-1, -1}}, {{1, -1}, {1, 1}, {-1, 1}}, {{1,
1}, {-1, -1}, {1, -1}}, {{1, 1}, {-1, -1}, {1, 1}}, {{1, 1}, {-1,
1}, {-1, -1}}, {{1, 1}, {-1, 1}, {-1, 1}}}
Answered by Daniel Huber on February 23, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP