Teacup rim text

Revision as of 09:33, 4 August 2019 by rosettacode>Axtens (Created page with "{{draft task|Teacup rim text}} On a set of coasters we have, there's a picture of a teacup. On the rim of the teacup the word "TEA" appears a number of times separated by bul...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

On a set of coasters we have, there's a picture of a teacup. On the rim of the teacup the word "TEA" appears a number of times separated by bullet characters. It occurred to me that if the bullet were removed and the words run together, you could start at any letter and still end up with a meaningful three-letter word. So start at the "T" and read "TEA". Start at the "E" and read "EAT", or start at the "A" and read "ATE".

Teacup rim text is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

That got me thinking that maybe there are other words that could be used rather that "TEA". And that's just English. What about Italian or Greek or ... um ... Telugu.

So here's the task: from a web accessible or locally accessible word source, iterate through each word. With each word, peel off the first letter and put it at the end. Check if the word exists. If it does, keep going with the next letter, repeating the process for as many letters as there are minus one. If all of the words exist store the original word. List the words that survive the process at the end. Optionally list all their variants.

Lychen

Lychen is V8 JavaScript wrapped in C#, exposing C# into JavaScript.

<lang javascript> const wc = new CS.System.Net.WebClient(); const lines = wc.DownloadString("https://raw.githubusercontent.com/dwyl/english-words/master/words.txt"); const words = lines.split(/\n/g); const collection = {}; words.filter(word => word.length > 2).forEach(word => {

 const theword = word.toLowerCase();
 let allok = true;
 let newword = theword;
 for (let i = 0; i < word.length - 1; i++) {
   newword = newword.substr(1) + newword.substr(0, 1);
   if (!words.includes(newword)) {
     allok = false;
     break;
   }
 }
 if (allok) {
   var key = theword.split("").sort().join("");
   if (!collection[key]) {
     collection[key] = [theword];
   } else {
     if (!collections[key].includes(theword)) {
       collection[key].push(theword);
     }
   }
 }

}); Object.keys(collection) .filter(key => collection[key].length > 1) .forEach(key => console.log("%s", collection[key].join(", "))); </lang>

arar, rara
ary, yar, rya
ate, eat, tea
eth, het, the, the