title: Permutations of multisets
body: <p>I'm trying to calculate the permutation of the word banana, but the code I made calculates it incorrectly, it doesn't take into account the letters that are repeated in the word, in words that the letters are not repeated works normally.</p>
  <pre><code>List&lt;String&gt; permute(String word, int l, int r) {
    List&lt;String&gt; output = [];
    if (l == r) {
      print(word);
      output.add(word);
    } else {
      for (int i = l; i &lt;= r; i++) {
        word = swap(word, l, i);
        output = output + permute(word, l + 1, r);
        word = swap(word, l, i);
      }
    }
    return output;
  }
  
  String swap(String a, int i, int j) {
    List&lt;String&gt; charArray = a.split('');
    String temp = '';
  
    temp = charArray[i];
    charArray[i] = charArray[j];
    charArray[j] = temp;
    return charArray.join();
  }
  </code></pre>
  <p>In my current code I get 720 possibilities, but according to the <a href="https://getcalc.com/statistics-letters-permutations.htm" rel="nofollow noreferrer">calculators</a> it should be 60 because of the letters that are repeated, how can I solve this?</p>