18
(Note: this is an easier spin-off of my previous challenge Find the Infinity Words!, which is a spin-off of my other previous challenge Find the Swirling Words! :) )
Definition of a Wavy Word:
- If you connect with curves all the characters of a Wavy Word on the alphabet (A-Z) you obtain the path of a wave continuously going toward right or toward left and never changing direction, like in the diagrams below.
- A Wavy Word can be:
- Raising if each consecutive character is at the right (on the alphabet) of the previous one.
- Decreasing if each consecutive character is at the left (on the alphabet) of the previous one.
- 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.
- If a word has double characters, like "SPOON", you must collapse the doubles to one character: "SPOON" > "SPON" (because if you go from O to O is zero distance).
- The Wavy Words will contain at least 3 distinct characters (even after doubles collapsing).
Here there are some examples:
Task:
Write a full program or function that will take a word from standard input and will output if it is a Wavy Word or not, and in positive case, output if it is raising or decreasing. The output can be True/False/Null
, 2/1/0
, 1/Null/0
, -1/0/1
, NO/WR/WD
, etc, you decide how to represent it.
Test cases:
WAVY WORDS:
ADEPT, BEGIN, BILL, BOSS, BOOST, CHIMP,
KNOW, SPONGE, SPOON, TROLL, WOLF
ADEPT > YES > RAISING
BEGIN > YES > RAISING
BILL > YES > RAISING
BOSS > YES > RAISING
BOOST > YES > RAISING
CHIMP > YES > RAISING
KNOW > YES > RAISING
SPONGE > YES > DECREASING
SPOON > YES > DECREASING
TROLL > YES > DECREASING
WOLF > YES > DECREASING
NOT WAVY WORDS:
WATCH, EARTH, NINON, FOO, BAR, WAVE, SELECTION,
YES, NO, DEFINITION, WATER, WINE, CODE, AAAHHHH, I, MM, ABCA
Rules:
- Shortest code wins.
Optional Task:
Find, as a list, as many Wavy Words as you can in an English dictionary, and the longest as well. You can take for example as reference the complete list of English words here.
How did you make the pictures? – Oliver Ni – 2016-10-28T16:57:51.477
@Oliver With Illustrator because I have it for work, but is possible to obtain similar results with Gimp or Inkskape, or others. – Mario – 2016-10-28T17:01:00.187
NO
andFOO
aren't valid inputs by your rules. – PurkkaKoodari – 2016-10-28T17:27:09.563@Pietu1998 Yes because of the Definition #7 – Mario – 2016-10-28T17:29:13.497
They're in the test cases though – PurkkaKoodari – 2016-10-28T17:30:17.380
1@Pietu1998 They're in the
NOT WAVY WORDS
section though, which is correct.. – Kade – 2016-10-28T17:32:07.643@Shebang The spec says
The input words will contain at least 3 distinct characters
, notWavy words will contain (...)
– PurkkaKoodari – 2016-10-28T17:32:58.333@Pietu1998 OK thanks for pointing that out, I clarified the Definition #7 – Mario – 2016-10-28T17:35:33.500
Can you add a test case like
ABCA
which would wrongly pass the test if someone just removed duplicates instead of collapsing runs? (Sorry, I'm too lazy to come up with an actual word with that property right now.) – Martin Ender – 2016-10-28T19:32:49.087Do we have to validate whether rule 5 is satisfied for a word to be wavy? "The input words are only characters in the alphabet range of A-Z, no spaces, no punctuation, or symbols." I thought this was a promise on all inputs, but it's listed under "Definition of a Wavy Word". And, rule 7 requires three distinct letters, and there's non-wavy test cases of that. – xnor – 2016-10-28T19:33:23.123
Must there be a single output for each of the three cases? – xnor – 2016-10-28T19:58:04.293
@MartinEnder I added "ABCA" to the test cases since the code was edited by others adding more nonense words :) – Mario – 2016-10-28T21:03:45.833
1@xnor #5 you can assume all the input words are as described, no need to validate. #7 this is the minimum number of letters to make a wave shape. For the rest you decide the output as you prefer. – Mario – 2016-10-28T21:13:15.847
I believe rule 6 is a bad. Instead the line should bounce. – rom016 – 2016-10-29T10:11:27.367
Can we expect that there are no words that consist of one character repeated? I.e.: Is
AA
orAAA
possible input or not? – Titus – 2016-10-30T08:04:39.590@Titus the input should be only real English words that you can find in a dictionary so I don't think that such cases exists (even though my question was edited adding nonsense words). – Mario – 2016-10-30T08:25:39.440
aa
andaaa
are in the list. No idea what they mean; but the answer to my question is No. – Titus – 2016-10-30T08:40:47.780@Titus
aa
is a type of lava found in Hawaii, I think. Not sure aboutaaa
. – FlipTack – 2017-01-31T19:47:14.100