# Challenge

For this challenge, a mountainous string is one that conforms to the grammar rule M: x(Mx)* where at each production, the all x's are the same character. When indented, a mountainous string might look something like this:

A
B
C
D
C
E
F
E
C
B
A

As you can see, it looks a bit like a mountain from the side.

# Formal Definition

• Any single character a is mountainous.
• If S is a mountainous string and a is a character, then aSa is mountainous, where juxtaposition represents string concatenation.
• If aSa and aTa are mountainous strings, then aSaTa is a mountainous string. Note that this rule implies that this pattern holds for any number of repetitions. (i.e. aSaTaUa, aSaTaUaVa, aSaTaUaVaWa... are all mountainous.)

# Examples

All odd-length palindromes are mountainous, for instance:

t
a
c
o
c
a
t

qwertytrasdfdgdsarewqjklkjq is a less trivial example:

q
w
e
r
t
y
t
r
a
s
d
f
d
g
d
s
a
r
e
w
q
j
k
l
k
j
q

# Example Outputs

a                           ==> true
aaa                         ==> true
mom                         ==> true
tacocat                     ==> true
qwertytrasdfdgdsarewqjklkjq ==> true
wasitacaroraratisaw         ==> true
abcbcbcbcba                 ==> true
aaaaabcbbba                 ==> true

<empty string>              ==> false
aa                          ==> false
pie                         ==> false
toohottohoot                ==> false
asdfdghgfdsa                ==> false
myhovercraftisfullofeels    ==> false

# Rules

• This is a decision problem, so any representation of true or false is valid output as long as it is correct, consistent, unambiguous, and the program terminates in a finite amount of time. Be sure to state your output convention with your solution.
• It should be trivial to determine whether the output indicates true or false without having to know what the input string is. Note that this does not mean the truthy or falsy outputs have to be constant, however the convention of "print a mountainous string if the string is mountainous and a non-mountainous string if not mountainous" is a banned loophole for obvious reasons.
• On the other hand, a convention like "throws an exception for false and exits silently for true" would be fine, as well as "prints a single character for true and anything else for false"
• This is code golf, so the shortest program wins.
• Standard loopholes are banned.
• A test case like aaa would be good, where the same character needs to be used on multiple levels. Feb 3, 2018 at 23:13
• Are you sure about wasitacaroraratisaw ? It seems mountanous to me Feb 3, 2018 at 23:50
• wasitacaroraratisaw is indeed mountainous AFAICT Feb 4, 2018 at 0:14
• So it is. I guess I was just trying to find an 'almost palindrome', but I found a mountainous string by accident. Feb 4, 2018 at 0:29
• I thought this would be easy to solve by splitting the string on its first character, but cases like aaa make that not work.
– xnor
Feb 4, 2018 at 1:03

e/.).\1/_g
¥g

Test it online!

# Clean, 948987 80 bytes

import StdEnv
?[a,b,c:s]=[a: ?if(a==c)s[b,c:s]]
?l=l

Try it online!

# JavaScript (Node.js), 72 bytes

Less trivial one, but much longer.

s=>[...s].reduce((a,x)=>(a[a.length-2]==x?a.pop():a.push(x),a),[])==s[0]

Try it online!