Among the programming projects I ran into recently was one to calculate all of the combinations of letters one could make from a phone number. Companies do this sort of thing all the time. They generate the combinations and then look for words related to their business so they can use it as a mnemonic and help people remember their phone number. Probably a bigger deal before domain names than now but still useful.
How many possible combinations are there? Well, that depends. It can be a low or 2187 (3 to the 7th power) and a high of 16384 (4 to the 7th power). The highest number is for phone numbers with all 7s and/or 9s.
I’m trying to write small bits of code to keep my mind active and solving interesting (to me) little programs. Initially I didn’t care to write this program (though eventually I did) so was thinking around the problem from other directions. What if I took a word and had a program generate a phone number? That was fun. And pretty easy. So I thought about the logical (to me anyway) next step. What if I had a list of 7 letter words and generated a file with the phone numbers that matched each word?
It turns out I have a small word list with just under 114,000 words in it. Step one was building a new file with only the seven letter words in it. A nice little project that is simple even for beginners.
I borrowed the code from the earlier program that turned a word into a number. A handy thing that shows the value of methods and reusable code. I used that to create the file with a list of seven letter words and phone numbers. A list of just over 22,000 for what its worth.
When I did write the program to create all the possible combinations of characters for a phone number I had a nice data file to use to check my work. That was surprisingly helpful.
Anyone out there assigning the program to create all the combinations of letters for a phone number? What interesting solutions are students coming up with?
No comments:
Post a Comment