{"id":12299,"date":"2025-04-29T09:43:30","date_gmt":"2025-04-29T08:43:30","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=12299"},"modified":"2025-04-29T14:02:38","modified_gmt":"2025-04-29T13:02:38","slug":"cheating-at-spelling-bee-using-the-command-line","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2025\/04\/cheating-at-spelling-bee-using-the-command-line\/","title":{"rendered":"Cheating at Spelling Bee using the command line"},"content":{"rendered":"\n<p><br>The New York Times <a href=\"https:\/\/www.nytimes.com\/puzzles\/spelling-bee\">Spelling Bee<\/a> is a free online word game, where players must construct as many words as possible using the letters provided in the Bee&#8217;s grid, always including the middle letter.  Bonus points for using all the letters and creating a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pangram\">pangram<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.nytimes.com\/puzzles\/spelling-bee\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"625\" height=\"181\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image-1.png?resize=625%2C181&#038;ssl=1\" alt=\"\" class=\"wp-image-12301\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image-1.png?w=767&amp;ssl=1 767w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image-1.png?resize=300%2C87&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image-1.png?resize=624%2C181&amp;ssl=1 624w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/figure>\n\n\n\n<p><br>However, this is the kind of thing which computers are very good at.  If you&#8217;ve become frustrated trying to decipher the abstruse ways of the bee, let the command line help.<br><br>tl;dr:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep -iP \"^[adlokec]{6,}$\" \/usr\/share\/dict\/words |grep a | awk '{ print length, $0 }' |sort -n |cut -f2 -d\" \"<\/pre>\n\n\n\n<!--more-->\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"399\" height=\"393\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image.png?resize=399%2C393&#038;ssl=1\" alt=\"\" class=\"wp-image-12300\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image.png?w=399&amp;ssl=1 399w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2025\/02\/image.png?resize=300%2C295&amp;ssl=1 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Starting with the grid, put each of the letters into grep:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep -iP \"^[adlokec]{6,}$\" \/usr\/share\/dict\/words <\/pre>\n\n\n\n<p>This will find all words in \/usr\/share\/dict\/words, which contain the letters a,d,l,o,k,e or c.   <br>-i is case-insensitive,<br>-P is use Perl regexp<br>^ is the start of the word<br>$ is the end of the word<br>{6,} is repeat the previous search six or more times<\/p>\n\n\n\n<p>This will give us a list of words, however the bee requires us to find a word that also contains the centre letter, so we need to refine the results with an extra grep:<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep -iP \"^[adlokec]{6,}$\" \/usr\/share\/dict\/words |grep a<\/pre>\n\n\n\n<p>Now we&#8217;ve got some useful results!  <br><br>Callao<br>accede<br>acceded<br>accolade<br>addled<br>cackle<br>&#8230;<br>However, they&#8217;d be more useful if they were in order of length, since we get more points for longer words.<\/p>\n\n\n\n<p><br>Now comes the fiddly bit, it&#8217;s given us useful answers, but we want the longest words with the most points.  That&#8217;s where awk comes in.  By passing our results to awk, we can get awk to prefix the length of the word, ready for sorting.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep -iP \"^[adlokec]{6,}$\" \/usr\/share\/dict\/words | grep a | awk '{ print length, $0 }' <\/pre>\n\n\n\n<p>6 Callao<br>6 accede<br>7 acceded<br>8 accolade<br>6 addled<br>&#8230;<br>Now, as before, pipe the results to the next stage in the pipeline..  In this case, sort.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep -iP \"^[adlokec]{6,}$\" \/usr\/share\/dict\/words | grep a | awk '{ print length, $0 }' | sort -n<\/pre>\n\n\n\n<p>sort gives us: <br>-n, &#8211;numeric-sort<br>        compare according to string numerical value<\/p>\n\n\n\n<p>Our output is now sorted by length and looks like:<br>&#8230;<br>7 cloaked<br>7 cockade<br>8 accolade<br>8 deadlock<br>10 deadlocked<br><\/p>\n\n\n\n<p>Finally, to leave us with a clean, sorted list and appease the Bee, we want to remove the numbers which awk put in.  So finally we pipe our output to cut.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep -iP \"^[adlokec]{6,}$\" \/usr\/share\/dict\/words | grep a | awk '{ print length, $0 }' | sort -n | cut -f2 -d\" \"<\/pre>\n\n\n\n<p>-d&#8221; &#8221; use a space (&#8221; &#8220;) instead of TAB as a field delimiter<br>-f 2 return the second field<\/p>\n\n\n\n<p>Callao<br>accede<br>addled<br>cackle<br>called<br>coaled<br>decade<br>doodad<br>lacked<br>ladled<br>leaded<br>leaked<br>loaded<br>locale<br>acceded<br>cackled<br>clacked<br>cloaked<br>cockade<br>accolade<br>deadlock<br>deadlocked<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The New York Times Spelling Bee is a free online word game, where players must construct as many words as possible using the letters provided in the Bee&#8217;s grid, always including the middle letter. Bonus points for using all the letters and creating a pangram. However, this is the kind of thing which computers are [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[348,10,31,15],"tags":[],"ppma_author":[507],"class_list":["post-12299","post","type-post","status-publish","format-standard","hentry","category-bash","category-groupmeetings","category-notes","category-technical"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":507,"user_id":15,"is_guest":0,"slug":"eoin","display_name":"Eoin Malins","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/e91a9cf8b77625a1bc34e56f5dc36439a1f61476804b087e5b47554425879210?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/12299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=12299"}],"version-history":[{"count":3,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/12299\/revisions"}],"predecessor-version":[{"id":12559,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/12299\/revisions\/12559"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=12299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=12299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=12299"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=12299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}