rcanzlovar.com

How to use regular expressions to cheat in scrabble

September 22, 2007

How to use regular expressions to cheat in scrabble

SO on some unix machines there is a dictionary. on the macosx machine i am sitting at, it is /usr/share/dict/words. Clever use of the ‘grep’ utility can yield some interesting results. Let’s say that you have the the letters k,i,u,l,t,v,s. There’s a place whre you have three spaces before a N, followed perhaps by one more letter on the board: **grep ‘1[kiultvs][kiultvs]n[kiultvs]′/usr/share/dict/words *  * yieldsthefollwing :  * * grep’2[kiultvs][kiultvs]n[kiultvs]′/usr/share/dict/words *  * kvintskinkskunkslinkslunkstinkstintstunkstuntsuintNowthisdoesntnecessarilyaddresswhatdowowhenyouonlyhaveoneofaletter, butitbreaksthelistdownabit, doesntit?Nowyoucouldgetdifferentresultsifyoudidntcarehowmanylettersbeforeorafterstunk * * grep ’3n[kiultvs]*′/usr/share/dict/words *  * ininitisinkinksinsistinstillinsultintilintuitintuitivistknitknutununitunkillunkissunkistunlistunlitunlustunslitunstillunsuituntiluntilluntiltoops, forgota *  :  * * grep ‘4n[kiultvs] ′/usr/share/dict/words *  * ininitisinkinksinsistinstillinsultintilintuitintuitivistivinkilnkinkinkknitknutkunkkvintliinlikinlinlinitislinklinkslintluntnninilnisusnitnunulnullnutsillikinsinsinksinuitissinussinusitissiskinskinskinkskunskunkslinkslunksluttikinstinkstintstunstunkstuntsuintsunsunksunlitsuntsuttintiklintintinktinttintisttsuntuntunisttunktunututinununitunkillunkissunkistunlistunlitunlustunslitunstillunsuituntiluntilluntiltvintvulnokenoughofthatsilliness.Theselistscangetlong.Howcanyoumaximizeyourreturn?wellthatKisworth5points, soifyouhadatripleletterscoreboxtwospacesawayfroman′, youcouldsay *  * grep[kv][kiultvs][kiultvs]n[kiultvs]*’ /usr/share/dict/words** Notice in this case we still might get some results wiht multiple k or v but otherwise, if anything comes up here, it’ll be useful in maximizing that multiplier. You can also fix between two letters, say like ’j..n.*’ (which would be a way to describe this if you didnt care what the letters were.. say you were looking for something in a crossword): grep ‘^j[kiultvs][kiultvs]n[kiultvs]$’ /usr/share/dict/words oops, forgot something: grep ’5j[kiultvs][kiultvs]n[kiultvs] $’ /usr/share/dict/words In regular expressions, * means ’0 or more’, while + means ’1 or more’ It might get tiresome to type the path of the dictionary sometimes, so another way to do any of the above things, you could do the command like this: cat /usr/share/dict/words | grep ’6j[kiultvs][kiultvs]n[kiultvs] $' ** And if you don't like to type or paste the list of words so many times, here's another way to denote a certain number of them: **cat /usr/share/dict/words | grep '^[kiultvs]_j[kiultvs]{2}n[kiultvs]_$ And if you wants somewhere between 2 and 4 of them at the end, you would: cat /usr/share/dict/words | grep ’7j[kiultvs]{2}n[kiultvs]{2,4}$’ remember, you would substitute in whatever you have in these examples to use them on your current hand right now