The brainiacs at New Scientist tweeted this morning that "The word STABLE has the neat property that you can cycle the first letter to the end to make a new word: TABLES. And you can do it again to make ABLEST." (https://twitter.com/newscientist/status/1379751396271124480)
This is of course correct. It is not, however, unique. Let us demonstrate that we can use computational force to match their linguistic cleverness.
You are to write a program that generates two sets of outputs based on the dictionary words revealed when rotating the letters of another dictionary word. Using the dictionary at https://gist.githubusercontent.com/wchargin/8927565/raw/d9783627c731268fb2935a731a618aa8e95cf465/words,
- find all the dictionary words with more than two characters for which every possible rotation yields another dictionary word. Show only one example of each rotation set (so, for example, show only one of "car", "arc", and "rca").
- find the words for which the largest number of valid rotations exist. You should find multiple words that tie with the same number of valid rotations. As above, show only one member of each set.
You can assume that the dictionary has been downloaded outside your code, and can be passed to your code as input or in a variable.
If you need to process the word list to put it in a format more natural for your programming language (a list for example), you may exclude this code from your byte count. However this process should not remove any words; any bytes associated with, for example, removing two-letter and one-letter words from the dictionary must be included in your byte total.
Anything in the words list counts as a word, even if we know it's really an acronym, or contains punctuation marks, or is not English (e.g. "AOL" or "Abdul's"). Treat all characters as letters.
Treat all letters as identically cased (so "India" and "india" are the same, and "eAt" is a valid word).
No shortcuts based on already knowing the answer, or knowing the maximum number of rotations. Your code needs to actually solve for that.
Using these rules and some ungolfed Wolfram Language, I found four completely rotateable words and 15 words tied at the level of maximum rotateability. This is a code golf challenge, and I imagine it won't be hard to do it more concisely than I did. I plan to call out any particularly creative solutions as well, regardless of length.
Intended output (assuming I coded it correctly)
completely rotatable words: aol, arc, asp, eat (each of these words can be presented with the letters in any rotation)
maximum rotatable words: all of the words above, plus ablest, alan, ales, anal, ankh, aver, emit, ernst, errant, evan, evil (each of this latter group also has two valid rotations)