Don't ask me how or why but while coding on a project I noticed that the characters of a couple of words had a particular pattern referred to the alphabet, I connected each character of the words with the pencil on the alphabet and I obtained two spirals, then I noticed that the first spiral was clockwise and the other was counterclockwise, and other characteristics... so I named them Swirling Words!
A Swirling Word can be:
- clockwise or counterclockwise
- centripetal or centrifugal
Here there are some examples of Swirling Words:
Task 1:
Write a full program or function that will take a word from standard input and will output if is a Swirling Word and it's characteristics, in a readable format, extended text, 3 characters, flags, etc.
Test cases and example outputs for different words (but you can decide how to represent the results):
EARTH, GROUP > NO // NOT A SWIRLING WORD
OPERA, STAY, IRIS > SW,CF,CW // SWIRLING WORD, CENTRIFUGAL, CLOCKWISE
MINER, TAX, PLUG, META > SW,CF,CC // SWIRLING WORD, CENTRIFUGAL, COUNTERCLOCKWISE
AXIOM, AXIS, COOK > SW,CP,CW // SWIRLING WORD, CENTRIPETAL, CLOCKWISE
WATCH, YETI, PILL > SW,CP,CC // SWIRLING WORD, CENTRIPETAL, COUNTERCLOCKWISE
MORE EXAMPLES OF FALSE TEST CASES (NOT SWIRLING WORDS):
EARTH, GROUP, OUTPUT, WORD, CONNECTION, ODD, MOM, DAD,
CHARACTER, EXAMPLE, QUESTION, NEWSLETTER, OTHER
Rules:
- The connection between the first two characters must be up (like in the graphics), all the even connection must be down, all the odd connections must be up.
- You can ignore upper/lowercase or consider/convert all to upper case or all to lower case.
- The input words are only characters in the alphabet range of A-Z, no spaces, no punctuation, etc.
- If a word has double characters, like "GROOVE", you must collapse the doubles to one character: "GROOVE" > "GROVE".
- The input words will contain at least 3 distinct characters. Words like "MOM", "DAD", "LOL" are not valid words.
- It's possible to pass multiple times in the same character, like "IRIS".
- Shortest code wins.
Task 2:
To obtain more reputation, find the longest Swirling Words, and it's characteristics, that you can find in the english dictionary, following the above rules. You can take for example as reference the complete list of the english words here.
Happy coding!
PILL
→PIL
). That kind of thing is generally Not Fun, and I think this challenge would have been better overall if there were fewer tricky edge cases to deal with (maybe a guarantee that there will be no duplicate letters in the input at all, not even words likeIRIS
, would have been nice.) \$\endgroup\$