(inspired by this post over on Puzzling. CAUTION: SPOILERS FOR THAT PUZZLE ARE BELOW.)
The standard telephone keypad correlates letters to numbers as follows:
1 -> 2 -> ABC 3 -> DEF 4 -> GHI 5 -> JKL 6 -> MNO 7 -> PQRS 8 -> TUV 9 -> WXYZ 0 ->
A given input word is defined to be an Ordered Word if, when translated to keypad presses using the above, the resulting number is either non-decreasing or non-increasing. In other words, the resultant number cannot both increase and decrease.
For example, the word
CAT translates to
228, which is non-decreasing, and thus an Ordered Word. However, the word
364, which both increases and decreases, and thus is not an Ordered Word.
Given a word, output whether or not it's Ordered.
- A word (not necessarily a dictionary word) consisting of ASCII alphabet (
[a-z]) letters only, in any suitable format.
- Your choice if the input is all uppercase or all lowercase, but it must be consistent.
- The word will be at least 3 characters in length.
A consistent truthy/falsey value for whether the input word is Ordered (truthy) or not Ordered (falsey).
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Here are some Ordered Words (i.e., truthy), and there are more on the linked Puzzling puzzle.
CAT TAC AAA DEMONS SKID LKJONMSRQP ABCDEFGHIJKLMNOPQRSTUVWXYZ
Here are some non-Ordered Words (i.e., falsey)
DOG GOD ROSE COFFEE JKLMNOGHI