# Word Scramble

Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last
• 08-21-2002
Unregistered
Word Scramble
Does anyone know an algorithm to find all possible combinations of letters of a word
• 08-21-2002
Ruski
If you find out the word lenght and put the word in an ARRAY, its probably gonna be very easy to do that :)
• 08-21-2002
BMJ
Do you mean if you had "ABOFGHIEQ", find all the possible words?

- or -

Do you mean if you had "BMJ lives in Chicago", find all the different possible letter combinations?

:confused:
• 08-21-2002
Ruski
Does anyone know an algorithm to find all possible combinations of letters of a word :)
• 08-21-2002
BMJ
Hey, I'm just making sure... people on this board have a habit of poorly phrasing questions; sheesh :D :)
• 08-21-2002
harry_p
I've also noticed quite a few people who are very snotty to others. It's not necessary.

Brendan
• 08-21-2002
Prelude
>Does anyone know an algorithm to find all possible combinations of letters of a word
Yes, but the real question is do you want to find the number of combinations or actually print each combination? If all you are doing is finding N and printing that then the solution is simply finding the factorial of the number of letters in the word:
Code:

```long perm ( int len ) {   int N = 1;   for ( ; len > 1; len-- )     N *= len;   return N; }```
Actually printing each combination is more difficult because you have to take a string and rotate the characters accordingly for each combination.

-Prelude
• 08-21-2002
Unregistered
I actually need to print all the combinations on the screen
• 08-21-2002
Unregistered
Reiterate
I think I might need to clarify my dilemma. I need to print into a file using fstream a list of all the possible combinations of a word. The word can be anylength and combinations don't need to be words.

For example:

if the user inputs "that" the following list would be produced, but unlike this list it shouldn't have repititions.

that
thta
taht
tath
ttha
ttah
htat
htta
hatt
hatt
htat
htta
atth
atht
ahtt
ahtt
atth
atht
ttah
ttha
that
thta
taht
tath
• 08-21-2002
Prelude
>I think I might need to clarify my dilemma.
There's no need for clarification. Here is what I meant by rotate the letters in the word:
Code:

```#include <iostream> #include <string> // No error checking is done, beware. void rotate ( std::string &s, int len ) {   int i, pos = s.length() - len;   char temp = s[pos];   for ( i = pos + 1; i < s.length(); i++ )     s[i - 1] = s[i];   s[i - 1] = temp; } void perm ( std::string &s, int len ) {   if ( len != 1 ) {     for ( int i = 0; i < len; i++ ) {       perm ( s, len - 1 );       if ( len == 2 )         std::cout<< s <<std::endl;       rotate ( s, len );     }   } } int main() {   std::string word;   std::cout<<"Enter a word: "<<std::flush;   std::getline ( std::cin, word );   perm ( word, word.length() );   return 0; }```
Feel free to use that as a template, but be sure you understand what it is doing, that is have the fun. :) Now, since I'm sure if I do not tell you this you will come back saying that it doesn't do what you wanted...Of course it doesn't, this prints all combinations. If you want to remove duplicates then you need to save each combination in some kind of list and check each new combination to see if it is already there. This is a project for you, I refuse to write all of your homework.

Good luck! :)

-Prelude
• 08-22-2002
Unregistered
my friend forgot to note that the code may not contain arrays
thanks,
sm
• 08-22-2002
Unregistered
y the way our whole class is stumped since all but one person did much programming durring the summer
(summer jobs)
so pretty much all of our class is having trouble creating loops
i thank you for any info you can give that might be of any use
- sm
• 08-22-2002
Prelude
>the code may not contain arrays
My first response to this was "Bwahahaha". :D This is the second most ridiculous restriction I have heard, the first being to write non-trivial programs in Scheme without using assignments. Yes, it is as hard as it sounds. Could you be specific as to what your exact requirements are so that I can be in a better position to answer accurately?

-Prelude
• 08-22-2002
Unregistered
since we have not formally learned arrays we are not allowed to use them in our programs with few exceptions
• 08-22-2002
quzah
If you can't use arrays, use pointer notation. :D Wherever you have:

array[x]

Replace it with:

*(array+x)

See how much fun that is?

Quzah.
Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last