Background
Inspired by I'm a palindrome. Are you?, where it is presented the shocking fact that “()()
is not a palindrome, but ())(
”, I asked myself what instead is ()()
and the answer is simply: it is a string with a vertical symmetry axis!
The task
Write a program or function that takes a string S (or the appropriate equivalent in your language) as input, checks for symmetry along the vertical axis, and returns a truthy or falsy value accordingly. You can use any reasonable means to take the input and provide the output.
Reflectional symmetry
Reflectional symmetry around a vertical axis (or left-right symmetry) means that if you put a mirror vertically at the exact center of the string, the reflected image of the first half of the string is identical to the second half of the string.
For example, the following strings are reflectional symmetric around a vertical axis:
()()
()()()
[A + A]
WOW ! WOW
OH-AH_wx'xw_HA-HO
(<<[[[T*T]]]>>)
(:)
)-(
())(()
qpqp
while the following are not:
())(
((B))
11
+-*+-
WOW ! wow
(;)
qppq
Rules of the contest
• Your program or function will receive only printable ASCII characters. You can include or not the empty string, (which is symmetric, of course!) as legal input, which is better for you.
• The ASCII characters that can be considered symmetric with respect to the vertical axes are the following (note the initial space, and the difference between uppercase and lowercase letters):
!"'+*-.:=AHIMOTUVWXY^_ovwx|
The ASCII characters that can be considered “mirrored” and their corresponding characters are:
()<>[]{}qpbd/\
Note that, since they are mirrored, you can have both ()
as well as )(
, /\
and \/
, etc.
All the other ASCII printable characters must be considered asymmetric and without a mirrored corresponding character.
• This is a code-golf challenge: the shorter your program is, measured in bytes, the better, in any programming language.
• Kudos to people that will produce a symmetric program!
Note: this question is not a duplicate of "Convenient Palindrome”, that requires to check for palindromic strings in which parentheses are flipped. This question is different for two reasons:
1) it is a restriction of the other question for what concerns non-parentheses characters, since only symmetric characters can appear in reverse order.
2) Since it is based on the concept of symmetry, and not on a concept of “convenient palindrome”, mirrored characters can appear in both order, i.e. []
and ][
, and this makes the program to solve it different from programs that solve the other problem.
8
considered "symmetric"? \$\endgroup\$