While playing Words with Friends my randomly chosen opponent played “radiale” as her first word. Since that used up all of her tiles, she received a bonus on top of all the points the word itself got, resulting in a one-move score of 53 points! Rather than being impressed I was upset at the large deficit I would have to overcome.
To combat this I did what comes naturally: Write an R script to find the perfect word!
Needing to combine my seven letters with one of her letters there were two routes I could take. The first would be for each combination of my seven letters and one of hers, find all 40,320 (8!) permutations then hit dictionary.com to see if it is a real word for a total of 282,240 (8!*7) http calls. That seemed a bit excessive and impractical so I moved on to the next idea.
So, first thing I did was pull a list of common eight-letter words. Then for each combination of my letters and one of hers (only 7 iterations) I checked if those letters (in any order) matched the letters in any of the possible words. Once a match was found there was a check for the counts of the letters and if that passed then the word was recorded as a true match.
The algorithm took about 17 seconds to run and found me one possible word for my letters combined with one of hers: “headrace”, for 63 points! Perhaps I should have been able to figure that out on my own, but where would be the fun in that. Find the code after the break.
Jared Lander is the Chief Data Scientist of Lander Analytics a New York data science firm, Adjunct Professor at Columbia University, Organizer of the New York Open Statistical Programming meetup and the New York and Washington DC R Conferences and author of R for Everyone.