A word game

A friend had trouble with a word game, so I wrote a programmatic solution.

Is it cheating if you model the problem with your brain and then code the solution? 🤔

The rules are simple:

  • The word must contain the letter R.
  • The word may contain letters from LGTVUIAY.
  • No other letters are allowed.
  • No duplicate letters.
  • At least 4 letters long.

Step 1: I downloaded a dictionary with 466,550 English words. The number sounds preposterous and probably includes many variations (plurals, British/American, archaic forms…), but it’s a solid starting point.

Step 2: I made everything uppercase for simplicity.

Step 3: I scanned the words one by one, applying the rules:

  • Discard if shorter than 4 letters.
  • Discard if it doesn’t contain R.
  • Discard if it contains a letter not in RLGTVUIAY.
  • Discard if a letter appears more than once in the word.

Step 4: I converted everything to lowercase and printed the words separated by commas.

#!/bin/bash

mandatory=R
letters=LGTVUIAY

allowed="${mandatory}${letters}"

cat words.txt | tr '[:lower:]' '[:upper:]' | awk -v m="$mandatory" -v a="$allowed" '
{
    word = $0
    if(length(word) < 4) next

    if(index(word, m) == 0) next

    split("", seen)
    valid = 1
    for(i=1; i<=length(word); i++) {
        c = substr(word,i,1)
        if(index(a,c)==0) { valid=0; break }
        if(seen[c]) { valid=0; break }
        seen[c]=1
    }
    if(valid) print word
}' | tr '[:upper:]' '[:lower:]' | paste -sd ',' -

In the end the result is:

airy,airt,aivr,alru,alur,argil,aril,aryl,arly,arty,artily,artly,arui,arvy,atry,auryl,autry,avril,avrit,gair,gari,gary,gart,garv,garvy,gaur,gauri,gyral,gyri,girl,girly,girt,glair,glairy,glar,glary,glaur,glaury,gray,grail,grat,grati,grav,gravy,gravity,grit,guar,guary,guitar,guitry,gular,guria,gurl,gurly,gurt,yair,yarl,yaru,iatry,iyar,yuri,yuria,yurt,yurta,ivar,ivray,lair,lairy,largy,lari,latry,laur,lauri,laury,liar,lyart,lira,lyra,litra,liturgy,ltvr,lugar,lura,luray,lurg,luri,lutra,ragi,raguly,rail,raul,rauli,ravi,rial,ryal,rialty,riga,riyal,rita,ritual,riva,rival,rivy,ruga,rugal,ruly,ruta,rutyl,tayir,tari,taur,tauri,tauryl,tavr,tiar,tigr,tylari,tyra,tirl,trag,tragi,tray,trail,traily,trav,trial,trig,triga,trigla,trigly,trug,trula,truly,tura,turgy,turi,turvy,uart,ugarit,ular,ultra,ural,urali,urga,urgy,uria,urial,urita,urva,vair,vairy,valry,vari,vary,varl,vira,viral,virg,virga,virgal,virgy,virgula,virl,virtu,virtual,vitra,vitry,vitular,vitulary,vril,vrita,vulgar,vulgarity

Since it looked a list of fake words, I checked those I didn’t recognise:

  • airt means “compass point”
  • aivr stands for “Accelerated IdioVentricular Rhythm”
  • alru is “Automatic Line Record Update”
  • Alur is a population in Uganda
  • aril is a a fleshy, usually brightly colored cover of a seed, usually arising from the funiculus (ok…!)
  • aryl is a chemical compound
  • Arly is a French river (does it count as an English word?)
  • artily means “related to arts”
  • artly mean “with art”
  • arui is a wild african sheep
  • Arvy is a boys’ name
  • atry is a nautical term for trying
  • Autry is another boys’ name
  • Avrit is a girls’ name
  • gair is a strip of fertile grass

I spot-checked more words at random and they all exist. As expected, some are obscure terms or variations (or both). For example “tragi,” is the plural of “tragus” (a part of the ear) and Ugarit was a city in Syria between the neolithic period and the bronze age.

It looks like I may have found all the possible solutions!


Photo by Merrilee Schultz on Unsplash

audit pixel