On Oct 15, 3:26*pm, Marc Gravell <marc.grav...@gmail.comwrote:
I haven't let it run to completion, but how about below; it uses a
char[] rather than lots of strings to save the GC some work... it only
goes 5 levels deep on the stack, so shouldn't blow up...
Marc
* * * * static void Main()
* * * * {
* * * * * * char[] data = new char[5];
* * * * * * Loop(data, 0);
* * * * * * Console.WriteLine(count);
* * * * }
* * * * static int count;
* * * * static void Loop(char[] buffer, int level)
* * * * {
* * * * * * int nextLevel = level + 1;
* * * * * * for (char c = 'A'; c < 'Z'; c++)
* * * * * * {
* * * * * * * * buffer[level] = c;
* * * * * * * * if (nextLevel == buffer.Length)
* * * * * * * * {
* * * * * * * * * * Console.WriteLine(buffer);
* * * * * * * * * * count++;
* * * * * * * * }
* * * * * * * * else
* * * * * * * * {
* * * * * * * * * * Loop(buffer, nextLevel);
* * * * * * * * }
* * * * * * }
* * * * }
Marc,
This is tight but I like it. Yes, it works. I also added a
container to it (like a hastable ot arraylist to store the
enumeration). Say, if you had a array of chars say char[] myChars =
{'A', 'C', 'E', 'X', 'Y'}
or something liek that - do you think it possible to cycle through
them and not all the letters in the alphabet?
PS: Small issue, I changed:
for (char c = 'A'; c < 'Z'; c++)
to
for (char c = 'A'; c <= 'Z'; c++)