Parenthetical names
Your challenge is to build a program that puts parentheses around the 'title' part of names. For example, Sonic the Hedgehog
is converted to Sonic (the Hedgehog)
.
Rules:
- Around every
the
that passes the following rules, an opening parentheses will be added before thethe
and a corresponding closing parentheses will be added at the end of the string. - Inputs will only contain words (uppercase/lowercase letters and spaces).
- Trailing
the
s are ignored. - With more than one
the
s in a row, every otherthe
is parenthesized. (Sopig the the the hog hog hog
turns intopig (the the (the hog hog hog))
.) - Remaining
the
s are skipped unless surrounded by spaces. For example, thethe
intheir
would not be parenthesized.
I know this may seem lacking in detail. However, it's hard to get one set of really specific guidelines working- just follow the above rules and you're good.
Inspired by this xkcd comic: https://xkcd.com/2252/
This is code-golf
, so least number of bytes wins.
the the the pig the the the
is unchanged, since all of thethe
s are leading and trailing? \$\endgroup\$