0
$\begingroup$

How can I create all possible lists of twelve elements when each element can be -1 or 1. That is, 2^12 different lists.

$\endgroup$
  • 2
    $\begingroup$ You are looking for all 12-tuples of $\{-1, 1\}$. Tuples is of course the the keyword to look up in the documentation. $\endgroup$ – Henrik Schumacher Apr 28 '19 at 8:32
3
$\begingroup$

You can use Tuples:

res = Tuples[{-1,1}, 12];
% //Length
res[[;;10]]

4096

{{-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}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1}, {-1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1}}

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.