3
$\begingroup$

I'm trying to get all possible combinations of {0,-1} for a certain length. So let's say I want length 2. Then I want my output to be

{0,0}, {0,-1}, {-1,0}, {-1,-1}

and if I want lengths 3 then I want my output to be

{0,0,0}, {0,0,-1}, {0,-1,0}, {0,-1,-1}, {-1,0,0}, {-1,0,-1}, {-1,-1,-1}, {-1,-1,0}

The Permutations function isn't working for this how I'd like it to.

$\endgroup$
0

1 Answer 1

7
$\begingroup$

Use Tuples:

Tuples[{0, -1}, n]

This gives all lists of length n formed from the elements in the set {0, -1}.

$\endgroup$
1
  • $\begingroup$ Thank you! Not sure how I didn't know about this $\endgroup$ Oct 23, 2015 at 1:34

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