How many words are possible with the english alphabet.
Hi I wanted to write a program to do this just out of boredom and i started to realize that the prog might take a very long time to run.
So we have the alphabet to start all capitals A-Z.
I want to write every possible combination of the letters to file. Up to 10 characters in length.
So the output file would look something like.
Code:
A
B // 1 char in length
C
...
...
AA
AB //2 char in length
AC
......
AAA
AAB //3 char in length and so on up to
AAC
.........
AAAAAAAAAA
ABAAAAAAAA
ACAAAAAAAA
.....
ZZZZZZZZZX
ZZZZZZZZZY //10 char in length.
ZZZZZZZZZZ
I dont know much concerning the math involved to caluculate the total possible combinations and i tried to study up on factorials but im not understanding them very well. So I was wondering if anyone could crunch some numbers and tell me the total # of possible combinations.
I was thinking it might be 26^1! + 26^2! + 26^3! ...... +26^10!
But i checked some of the math and 26^4! comes out to
9.107 x 10^33
=9107000000000000000000000000000000
I am thinking my reasoning above is wrong so if someone knows the correct way to calculate the total possibilities i would appreciate some help. Thanks.
Re: How many words are possible with the english alphabet.
I do not think that factorial is involved here. Consider a similiar problem using numbers: how many three digit integers are there? We could consider this the same as asking the size of the range [0,1000), hence the answer is 1000. In your case it is slightly different, but the count should just be: 26 + 26^2 + 26^3 + ... + 26^9 + 26^10.
Re: How many words are possible with the english alphabet.
The factorials don't look correct to me.
Single letters = 26
Two letters = 26 for each single letter = 26^2
Three letters = 26 for each two letter combination = 26^3
etc
Re: How many words are possible with the english alphabet.
Create a program that can do addition in base 26.
Code:
//in base 26
word++;
//write word to file
Re: How many words are possible with the english alphabet.
I once read a sci-fi short story where a group of monks, who's destiny it was to write out all the names of God (Every combination of 10 letters or something like that). When the job was completed then the purpose of the universe would be over and it would be dismantled. The monks, being a modern lot, thought that a computer would help. As the last name is printed out, the stars start to wink out...
So maybe you shouldn't attempt this project :eek:
Re: How many words are possible with the english alphabet.
Quote:
Originally Posted by JohnW@Wessex
I once read a sci-fi short story where a group of monks, who's destiny it was to write out all the names of God (Every combination of 10 letters or something like that). When the job was completed then the purpose of the universe would be over and it would be dismantled. The monks, being a modern lot, thought that a computer would help. As the last name is printed out, the stars start to wink out...
That sounds like a rehashing of Lucas' tower of Hanoi story :p
Re: How many words are possible with the english alphabet.
Okay thanks. I had the factorial idea stuck in my head and could not get away from it.
26^1 + 26^2 .... + 26^10
=
1.468 x 10^14 possible combinations.
Ill write the prog which i dont think will be a problem and then count the lines in the output file. I still have a feeling it will take a while to run .
Re: How many words are possible with the english alphabet.
Quote:
Originally Posted by g.eckert
Ill write the prog which i dont think will be a problem and then count the lines in the output file.
Note that the integer that you expect to get is not guaranteed to fit into an unsigned long.
Re: How many words are possible with the english alphabet.
Assuming each string takes 1 microsecond to create, then your program run should take about 4 years 34 weeks and 1 day :eek:
Re: How many words are possible with the english alphabet.
Do you have 1.6 million gigabytes of free disk space for the file? That's what I have calculated will be required assuming an 8-bit character text file with a new line character for each unique word. And as suggested, it will probably take a while to write the entire file.
Re: How many words are possible with the english alphabet.
haha yea. I realized that. My solution, i havnt tried, was to count how many times an integer maxed out at 2,000,000,000 reset the integer, then increment another variable indicating it rolled over. So it might max out say 650000 times at 2 billion. and have a remainder of 1,234,567. I can just do some multiplication and print the value not really store it. XD
Reply to #8
Re: How many words are possible with the english alphabet.
4 years hmm.....
1.6 million gigs hmm......
I dont want to try this anymore.
Re: How many words are possible with the english alphabet.
Definitely a "Non Visual C++ Issue" :-D
Re: How many words are possible with the english alphabet.
Code:
/*
Words
By: Gerald Eckert
Prints all possible
combinations of the alphabet up 5 charcters in length.
*/
#include <iostream>
using namespace std;
//The alphabet
const char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
int main()
{
//Iterate up to 5 character words.
for(int i=0;i<5;i++)
{
switch(i)
{
//For 1 character words.
case 0: for(int a=0;a<25;a++)
cout<<alphabet[a]<<endl;
break;
//For 2 character words.
case 1: for(int a=0; a<26 ;a++)
for(int b=0;b<26;b++)
cout<<alphabet[a]<<alphabet[b]<<endl;
break;
//For 3 character words.
case 2: for(int a=0;a<26;a++)
for(int b=0;b<26;b++)
for(int c=0;c<26;c++)
cout<<alphabet[a]<<alphabet[b]<<alphabet[c]<<endl;
break;
//For 4 character words.
case 3: for(int a=0;a<26;a++)
for(int b=0;b<26;b++)
for(int c=0;c<26;c++)
for(int d=0;d<26;d++)
cout<<alphabet[a]<<alphabet[b]<<alphabet[c]<<alphabet[d]<<endl;
//For 5 character words
case 4:break;
}
}
return(0);
}
I ran the above which implements up to 4 character words. It took about 94 seconds. Im not sure its the best way to do what i want but it makes sense to me. Any comments on making it faster? My algorithm seems to hit every combo i think. The DOS window doesnt hold all the lines so i cant search back to the begining only like 200 lines or something.
Re: How many words are possible with the english alphabet.
If you only want to count, you do not need to actually generate the strings. So, it is just a matter of whether you want to implement a formula, or write a program that goes through the motion of iterating over all possibilities while incrementing a count.