# Generating a variable size table one element at a time

I can produce a variable size list of strings like AACBBAABC with this code:

test[n_] :=
Flatten[ Table[ StringJoin @@ Table[ Subscript[\[Zeta], i], {i, 1, n}], ##] & @@
Table[{ Subscript[\[Zeta], i], {"A", "B", "C"}}, {i, 1, n}], n - 1]


My problem is that ultimately n will be such that the table has $10^{17}$ elements.
What I want to do is generating the elements one at a time so that I can run a test on the string to validate it. The number of good strings will be $<<10^{17}$. In essence I need a code that will have a variable number of loops depending on n. My $70$ year old brain is having a problem coming up with an answer!

-
$10^{17}$ elements??? At 1 byte per element, that's about 100 peta bytes! Do you work for the NSA or Google? :D – R. M. Nov 27 '13 at 20:39
If you could check a billion elements per second (a rate of 1 GHz), it would take approximately π years. You might want to figure out how to skip large chunks of elements. – Michael E2 Nov 27 '13 at 21:01
Your test function looks too complex. Why don't you use something simple and fast like test[n_] := StringJoin @@@ Tuples[{"A", "B", "C"}, {n}] – halirutan Nov 27 '13 at 21:11
test[n] equivalent to Tuples[{"A","B","C"},n]. What is it that you want to know about all tuples of this triplet? Perhaps you want to know how many there are? If so, this can be much more easily found that listing them all. BTW, what constitutes a good string? – DavidC Nov 27 '13 at 21:14
For a fixed length string, what you want is a Gray code. Alternatively, if you were interested in permutations, there's NextPermutation, and something similar could be created for Tuples. – rcollyer Nov 27 '13 at 21:20