Jason Cawley
Wolfram Science Group
Phoenix, AZ USA
Registered: Aug 2003
Posts: 712 |
In Mathematica, you could just type -
Tuples[{0,1,2},12]
You'd get a list of 531441 lists each 12 long, with each element out of the alphabet 0, 1, 2. The total number comes out that way because that is 3^12.
But it is somewhat easier in a simple case like this to just treat each combination as a 12 digit number in base 3. You are just counting through them, from
{0,0,0,0,0,0,0,0,0,0,0} to
{0,0,0,0,0,0,0,0,0,0,1} to
{0,0,0,0,0,0,0,0,0,0,2} to
{0,0,0,0,0,0,0,0,0,1,0} to
{0,0,0,0,0,0,0,0,0,1,1} ...
So you can get any portion of them and uniquely name each one, as -
IntegerDigits[x-1,3,12]
With x running from 1 to 531441. (Or to start at the "zeroth" and go to 531440, just remove that -1).
So, say I wanted the first 100. I'd Map that over Range[100] (which just gives a list from 1 to 100), like this -
IntegerDigits[#-1, 3, 12]&/@Range[100]
When I want the next batch I'd just ask for -
IntegerDigits[#-1, 3, 12]&/@Range[101,200]
You can get the whole lot in one go with Tuples, or with a big Range or a Table. But since that is rather large and unwieldy, for most purposes it will be more useful to get each from its integer "name", as above.
Report this post to a moderator | IP: Logged
|