Large Tuples with Negative Integers

I am trying to run a loop that cycles through the elements of Tuples[{-1,0,1},116] and terminates when a desired result is found.

Unfortunately, this creates a memory problem due to 116. All of the workarounds that I can find, like IntegerDigits, seem to require positive entries in my tuples.

Is there a good technique to help with this?

• You're trying to loop through 22185312344622607535965183080365494317672538611578408721 values? Good luck. Commented Nov 13, 2014 at 0:07
• Umm, that's 3^116 tuples. How do you propose to cycle through them? As for using IntegerDigits, one can take the digits base 3 of some number between 0 and 3^116, and subtract 1 from all digits. Commented Nov 13, 2014 at 0:09
• I do appreciate how big 3^116 is. For the record, I never had any intention of cycling through ALL of these tuples... just enough for my purposes. Commented Nov 13, 2014 at 0:28
• @RossElliot The question indicates ALL, I think. Maybe you should edit it to say "some" or how many. Commented Nov 13, 2014 at 0:43

If you need only a few, then randomly choosing them would be easy and perhaps sufficient. The following will produce n = 10 tuples.

With[{n = 10},
NestWhile[
DeleteDuplicates @ Join[#, RandomInteger[{-1, 1}, {n - Length[#], 116}]] &,
{},
Length[#] < n &]
]


As others said, there are 3^116 such tuples, so no existing computer will be able to cycle through them in reasonable time. Just to put it in some context, it would take a 1 GHz CPU $3^{116}/10^9/3600/24/365.25 = 7\times 10^{38}$ years to go through this many clock cycles, which is many orders of magnitude longer than the age of the universe.

n = 10; (* 116 is excessive *)