This is a mirror:
|. I just found out that you can stick a mirror in the middle of a string if the string can be mirrored on itself! For example, the string
abccba. If you cut it in half the two halves are mirror images of each other:
abc <--> cba
So, we can stick a mirror in the middle of the string, and our new string is
abc|cba. Sometimes, only part of the string can be mirrored on itself. For example, the string "mirror". The two r's are mirrored, but the rest of the string isn't. That's OK, we'll just remove the parts of the string that don't mirror each other, and we get the following string:
Some strings could be mirrored in multiple places. For example, "Hello World, xyzzyx". I like having a lot of text reflected in my mirror, so you need to find the best place to put my mirror. In this case, you should output the longer mirrored string and just like our last example, remove everything else. This string becomes:
Some strings look like they can be mirrored, but actually can not. If a string cannot be mirrored anywhere, you should output nothing.
Given a string containing only printable-ascii, find the best place to put my mirror. In other words,
Find the largest even-length palindromic substring, then output it with a pipe character '|' in the middle of it.
The input will be 1-50 characters long.
You can assume that the input will not contain mirrors
| or newlines. Beyond that, all printable-ascii characters are fair game. If the longest mirrored substring is tied between two substrings, you can choose which one to output. For example, for the string "abba ollo", you must output "ab|ba" or "ol|lo", but it doesn't matter which one you output. Strings are case-sensitive, e.g. "ABba" should not output "AB|ba", it should output the empty string.
"Hello World" --> "l|l" "Programming Puzzles and Code-Golf" --> Either "m|m" or "z|z" "abcba" --> "" "Hulluh" --> "ul|lu" "abcdefggfedcba" --> "abcdefg|gfedcba" "abcdefggfabc" --> "fg|gf" "AbbA" --> "Ab|bA" "This input is a lot like the last one, but with more characters that don't change the output. AbbA" --> "Ab|bA"
As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!