title: How to get all the possible 3 letter permutations?
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/756055/listing-all-permutations-of-a-string-integer">Listing all permutations of a string/integer</a></p>
  </blockquote>
  
  <p>For example,</p>
  <pre><code>aaa .. aaz .. aba .. abz .. aca .. acz .. azz .. baa .. baz .. bba .. bbz .. zzz
  </code></pre>
  <p>Basically, imagine counting binary but instead of going from 0 to 1, it goes from a to z.</p>
  <p>I have been trying to get this working to no avail and the formula is getting quite complex. I'm not sure if there's a simpler way to do it.</p>
  <h2>Edit</h2>
  <p>I have something like this at the moment but it's not quite there and I'm not sure if there is a better way:</p>
  <pre><code>private IEnumerable&lt;string&gt; GetWordsOfLength(int length)
  {
      char letterA = 'a', letterZ = 'z';
  
      StringBuilder currentLetters = new StringBuilder(new string(letterA, length));
      StringBuilder endingLetters = new StringBuilder(new string(letterZ, length));
  
      int currentIndex = length - 1;
  
      while (currentLetters.ToString() != endingLetters.ToString())
      {
          yield return currentLetters.ToString();
  
          for (int i = length - 1; i &gt; 0; i--)
          {
              if (currentLetters[i] == letterZ)
              {
                  for (int j = i; j &lt; length; j++)
                  {
                      currentLetters[j] = letterA;
                  }
  
                  if (currentLetters[i - 1] != letterZ)
                  {
                      currentLetters[i - 1]++;
                  }
              }
              else
              {
                  currentLetters[i]++;
  
                  break;
              }
          }
      }
  }
  </code></pre>