Mountain range number
A number is a mountain range number if the inequalities satisfied by their consecutive digits alternate. In a way, looking at the number's digits should exhibit a /\/\/\...
or a \/\/\/...
pattern.
More formally, if our number n
has \$k\$ digits
$$n = d_1d_2d_3\cdots d_k$$
then n
is a mountain range number if
$$\begin{cases}d_1 > d_2 \\ d_2 < d_3 \\ d_3 > d_4 \\ \cdots \end{cases} \vee \begin{cases}d_1 < d_2 \\ d_2 > d_3 \\ d_3 < d_4 \\ \cdots \end{cases}$$
Your task
Given an integer with 3 or more digits, output a Truthy value if the number is a mountain range number or Falsy otherwise.
Input
A positive integer n
with 3 or more digits, in any reasonable format, e.g.
- Integer
- String
- List of digits
Test cases
Truthy
1324 -> Truthy
9191 -> Truthy
12121 -> Truthy
121212 -> Truthy
1212121 -> Truthy
19898 -> Truthy
Falsy
(Added another Falsy test case as per the comments, some answers might not cover the 4422 test case)
123 -> Falsy
321 -> Falsy
4103 -> Falsy
2232 -> Falsy
1919199 -> Falsy
4422 -> Falsy
This is code-golf so shortest answer in bytes wins! Standard loopholes are forbidden.
k>=3
); also the other challenge is so old that many of the answers there wouldn't be close to competitive on this one; I'd actually rather remove the old one as a dupe of this. \$\endgroup\$