36
4
(Note: This is a spin-off of my previous challenge Find the Swirling Words!)
Definition of Infinity Word:
- If you connect with curves all the characters of an Infinity Word on the alphabet (A-Z) you obtain the infinity symbol ∞ like in the diagrams below.
- 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, or symbols.
- Each word must be exactly 5 characters. Words > 5 or < 5 are not valid.
- If a word has double consecutive characters, the word is not valid, like "FLOOD" or "QUEEN".
- All the Infinity Words start and end with the same character.
Here there are some examples:
Task:
Write a full program or function that will take a word from standard input and will output if is an Infinity Word or not. The output can be true/false, 1/0, 1/Null, etc.
Test cases:
Infinity Words:
ALPHA, EAGLE, HARSH, NINON, PINUP, RULER, THEFT, WIDOW
NOT Infinity Words:
CUBIC, ERASE, FLUFF, LABEL, MODEM, RADAR, RIVER, SWISS, TRUST,
KNEES, QUEEN, GROOVE, ONLY, CHARACTER, OFF, IT, ORTHO
Rules:
- Shortest code wins.
Optional Task:
Find, as a list, as many Infinity Words as you can in an English dictionary. You can take for example as reference the complete list of English words here.
Can we assume the input is always of length 5? You have defined rule 5: "Each word must be exactly 5 characters. Words > 5 or < 5 are not valid.", but no NOT Infinity Words containing less or more than 5 characters. – Kevin Cruijssen – 2016-10-17T13:48:33.757
4Pretty funny that ALPHA makes that pattern – Fatalize – 2016-10-17T13:49:24.470
@KevinCruijssen You must check that the word respect the definition, I updated the false cases. – Mario – 2016-10-17T13:56:24.643
Also, one more thing I noticed. At your picture you have
ORTHO NO
, but at the Test Cases,ORTHO
is at the truthy cases instead of falsey. – Kevin Cruijssen – 2016-10-17T13:59:07.090@KevinCruijssen My mistake! :) I updated it – Mario – 2016-10-17T14:00:12.570
IMO, a word such as
AAAAA
should be considered as a valid singularity, which is currently not the case because of rule #6. Does that make sense? – Arnauld – 2016-10-17T16:06:20.5071@Arnauld five "A"'s connects to themselves (or doesen't move at all) creating a single point, it doesen't draw the infinity symbol, so I don't think it's a positive case. – Mario – 2016-10-17T16:25:22.503
@Mario FYI there is no test case that fails if I perform only my rotation test without checking last letter equals first. How about adding "RULES"? – Jonathan Allan – 2016-10-17T17:30:47.780
@JonathanAllan I'm not sure I understood well your last comment, but the word "RULES" doesen't draw a closed infinity symbol, so I think it should be considered as false case. The path should be closed and with no ending anywhere. – Mario – 2016-10-18T07:03:20.320
Yes it is Falsely, but if one performs the test I described in my answer but without checking first==last all test cases work. – Jonathan Allan – 2016-10-18T07:15:09.660
3
I have decided to tackle the Optional Task: "Find, as a list, as many Infinity Words as you can in an English dictionary..." I used this source and Kevin Cruijssen's answer, to produce this list of 278 Infinity Words.
– Thomas Quinn Kelly – 2016-10-18T22:16:07.643