Anagram Descrambler: Discover All Possible Combinations for Fun!

  • Thread starter Orion1
  • Start date
In summary, the number of possible combinations for an anagram word can be calculated using the formula n!, where n is the number of letters in the word. This can be implemented in a programming language such as C++ using a recursive function to generate all possible permutations of the letters in the word.
  • #1
Orion1
973
3

I am attempting to solve an anagram game puzzle just for fun, however what is difficult is the number of possible combinations for a typical anagram.

For example, in DNA there are 4 bases 'A','C','G','T'.

The equation that I derive for the number of possible combinations is:
[tex]N_c = N_b^L[/tex]
[tex]N_b[/tex] - base unit number
[tex]L[/tex] - base unit length

So, for one base of length L = 1, there are 4 combinations:
[tex]N_c = 4^1 = 4[/tex]

Increasing the length to L = 4, there are 256 combinations:
[tex]N_c = 4^4 = 256[/tex]

However, for English word anagram descrambling there are 26 base unit letters.

So, for one base of length L = 1, there are 26 combinations:
[tex]N_c = 26^1 = 26[/tex]

Increasing the length to L = 4, there are 456976 combinations:
[tex]N_c = 26^4 = 456976[/tex]

I am inquiring if any programmers here can write a simple program in Basic or in Visual Basic, with a better logistical code than I can write that does not require a lot of computational algorithmic cycles for descrambling an input anagram word and output all the possible combinations, for example:

input: edco
[tex]N_c = 4^4 = 256[/tex] - maximum combination number for input anagram word?

output 1: deco
...
output n: code
...

I am not certain that the number of possible combinations equation that I have stated is accurate for scrambled anagram words, since each anagram letter can only be used once in a sequence. So what would the equation be for a scrambled anagram word?

Reference:
http://en.wikipedia.org/wiki/Anagram"
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
You should be thinking about permutations rather than combinations. An anagram is just a rearrangement of the letters in some word. For a given four-letter word, there are 4! (= 4 * 3 * 2 * 1 = 24) different permutations of the four letters. More generally, for a word with n letters, there are n! possible anagrams.

Going back to your example with four letters, for each permutation, there are four possible choices for the first letter. For the second letter, there are three unused letters, so three possible choices. For the third letter, there are only two possible choices. Finally, for the fourth letter, there is just one unused letter.
 
  • #3
Don't know VB so I can't help you much there.

However, here's a version in C++ that I derived from code from "Practical Algorithms in C++" by Flamig, B. Do note that it's recursive. It's one of those things that are probably annoying to do iteratively. Also, I used a C style string for it, which I normally wouldn't do. I would normally comment it as well, but there you go.

Anyways, if you can code in VB you should be able to convert it easily enough:

Code:
#include <iostream>
#include <cstring>

using namespace std;

void permute(char bytes[], const int start, const int len)
{
    for (int i = 0; i < len; i++)
    {
        cout << bytes[i];
    }
    cout << endl;
    
    if (start < len)
    {
        for (int i = len-2; i >= start; i--)
        {
            for (int j = i+1; j < len; j++)
            {
                char tmp = bytes[i];
                bytes[i] = bytes[j];
                bytes[j] = tmp;
                
                permute(bytes, i+1, len);
            }
            
            char tmp = bytes[i];
            for (int k = i; k < len-1; k++)
            {
                bytes[k] = bytes[k+1];
            }
            bytes[len-1] = tmp;
        }
    }
}

int main(int argc, char *argv[])
{
    char word[] = "1234";
    
    permute(word, 0, strlen(word));
}
 

Related to Anagram Descrambler: Discover All Possible Combinations for Fun!

1. How does the Anagram Descrambler work?

The Anagram Descrambler uses algorithms and dictionaries to rearrange the letters of a given word or phrase into all possible combinations. It then checks the validity of each combination against its database of known words, providing a list of all valid anagrams.

2. Is the Anagram Descrambler accurate?

Yes, the Anagram Descrambler is highly accurate as it uses a comprehensive dictionary and advanced algorithms to generate anagrams. However, it may not recognize obscure or uncommon words.

3. Can I use the Anagram Descrambler for any language?

Yes, the Anagram Descrambler can be used for any language as long as it has a dictionary for that language. It also allows users to add their own custom dictionaries for specific languages.

4. Can the Anagram Descrambler be used for longer phrases or sentences?

Yes, the Anagram Descrambler can handle longer phrases and sentences. However, the longer the input, the longer it may take to generate all possible combinations.

5. Is the Anagram Descrambler useful for anything other than entertainment?

Yes, the Anagram Descrambler can also be used for educational purposes, such as word games and puzzles. It can also be helpful in solving anagrams in crosswords or other word-based games.

Similar threads

  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
1
Views
1K
  • Precalculus Mathematics Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
23
Views
2K
  • Programming and Computer Science
Replies
4
Views
9K
  • Electromagnetism
Replies
16
Views
2K
Back
Top