Algorithm to generate all possible letter combinations of given string down to 2 letters

Posted by Alan on Stack Overflow See other posts from Stack Overflow or by Alan
Published on 2010-03-13T18:10:42Z Indexed on 2010/03/13 18:15 UTC
Read the original article Hit count: 889

Algorithm to generate all possible letter combinations of given string down to 2 letters

Trying to create an Anagram solver in AS3, such as this one found here:

http://homepage.ntlworld.com/adam.bozon/anagramsolver.htm

I'm having a problem wrapping my brain around generating all possible letter combinations for the various lengths of strings. If I was only generating permutations for a fixed length, it wouldn't be such a problem for me... but I'm looking to reduce the length of the string and obtain all the possible permutations from the original set of letters for a string with a max length smaller than the original string. For example, say I want a string length of 2, yet I have a 3 letter string of “abc”, the output would be: ab ac ba bc ca cb.

Ideally the algorithm would produce a complete list of possible combinations starting with the original string length, down to the smallest string length of 2. I have a feeling there is probably a small recursive algorithm to do this, but can't wrap my brain around it. I'm working in AS3.

Thanks!

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about algorithm