title: How to generate all possible combinations?
body: <p>I'm currently trying to make a <code>Set</code> of all possible combinations from an <code>Array</code> of <code>Strings</code>, were each element contains only one letter. </p>
  
  <p>The <code>Array</code> itself can contain the same letter twice or even more and they should only be used as often as they occur.</p>
  
  <p>The <code>Set</code>should later contain all combinations from a minimum of 2 letters up to the length of the given <code>Array</code>.</p>
  
  <p>I searched here on stackoverflow, but only found permutation functions that ignore the fact, that each letter should only be used as often as they occur.</p>
  
  <p>This is my first Swift 2 project, so please forgive my greenhornish-ness :)</p>
  
  <p><strong>What I want</strong></p>
  
  <pre><code>var array = ["A", "B", "C","D"]
  var combinations: Set&lt;String&gt;
  
  ... &lt;MAGIC&gt; ...
  
  print(combinations)
  // "AB", "ABC", "ABD", "ABCD", "ABDC", "AC", "ACB", "ACD", "ACBD", "ACDB", and so on ...
  </code></pre>
  
  <p><strong>My current approach</strong></p>
  
  <pre><code>func permuation(arr: Array&lt;String&gt;) {
  
      for (index, elementA) in arr.enumerate() {
          //1..2..3..4
          var tmpString = elementA
          var tmpArray = arr
          tmpArray.removeAtIndex(index)
  
          for (index2, elementB) in tmpArray.enumerate() {
              // 12..13..14
              var tmpString2 = tmpString + elementB
              var tmpArray2 = tmpArray
  
              //[3,4]
              tmpArray2.removeAtIndex(index2)
  
              results.append(tmpString2)
          }
      }
  
  }
  permuation(array)
  print(results)
  // "["AB", "AC", "AD", "BA", "BC", "BD", "CA", "CB", "CD", "DA", "DB", "DC"]"
  </code></pre>
  
  <p>I know, this is so terribly wrong in so many ways, but I'm stuck with this code, and don't know how to add a recursive functionality.</p>