list manipulation - Finding all length-n words on an alphabet that have a specified number of each letter
For example, I might want to generate all length n=6 words on the alphabet {A, B, C} that have one A , three B 's and two C 's. An example of such a word is: 'ABBBCC' . I'd like to generate all such words. I've already tried generating all permutations of a particular string (like 'ABBBCC' ) and deleting all duplicates. This is too slow for my purposes. Answer Permutations is already duplicate-aware: Permutations[{"A", "A", "B"}] {{"A", "A", "B"}, {"A", "B", "A"}, {"B", "A", "A"}} Perhaps you are looking for combinations of a particular length (which can then be permuted). One way to get those is this: f[k_, {}, c__] := If[+c == k, {{c}}, {}] f[k_, {x_, r___}, c___] := Join @@ (f[k, {r}, c, #] & /@ 0~Range~Min[x, k - +c]) Use: f[4, {1, 3, 2}] {{0, 2, 2}, {0, 3, 1}, {1, 1, 2}, {1, 2, 1}, {1, 3, 0}} These represent the words of l...