Since you're looking for words that are less than 20 characters
, this includes words that are 1, 2, 3 .. or 19 characters
in length (not sure if there is a word in the English language with 19 characters). The total number of possibilities is then 2619 + 2618 + 2617.. + 261.
The brute force way to approach this problem is to create a list which includes all 26 alphabet of the English language. Then inside of a loop for i = 0; i < 20; i++
, you create all possible words of length i
using the 26 characters in the alphabet array. Recursion is your friend here. Once you have a word of length i
, you can then pass it through whatever filtering rules
to be used to define words in the English language, e.g. no words can exist without a vowel as mentioned by slm.
Note: Writing the so called filtering rules
is not a trivial task. For example, it's fairly easy to check if the word contains any of aieou
, but passing this check doesn't mean you've found a word ..there is still quite a long way to go from there.
How long will this brute force method take?
Jimmij posted that 26^20 = 19928148895209409152340197376 ~ 2e28
. Now lets say your computer has a quad core 1.5 GHz processor
and your program is able to exploit each core 100%
. This gives you 1.5e9 x 4 = 6e9
cycles in a second. Each permutation itself will take multiple CPU cycles
as it has to consider 26 characters
for each permutation, etc. This number however is insignificant when compared to the # of permutations
so lets just say that each permutation takes 6 instructions
(and each instruction takes 1 CPU cycle
) to make the math simple. Finally, you get (6 instructions/permutation x 2e28 permutations)/(6e9 instructions/second) = (2e19 seconds) ~ 6.35e11 years
.