Introduction
For the ones who don't know, a palindrome is when a string is equal to the string backwards (with exception to interpunction, spaces, etc.). An example of a palindrome is:
abcdcba
If you reverse this, you will end up with:
abcdcba
Which is the same. Therefore, we call this a palindrome. To palindromize things, let's take a look at an example of a string:
adbcb
This is not a palindrome. To palindromize this, we need to merge the reversed string into the initial string at the right of the initial string, leaving both versions intact. The shorter, the better.
The first thing we can try is the following:
adbcb
bcbda
^^ ^^
Not all characters match, so this is not the right position for the reversed string. We go one step to the right:
adbcb
bcbda
^^^^
This also doesn't match all characters. We go another step to the right:
adbcb
bcbda
This time, all characters match. We can merge both string leaving the intact. The final result is:
adbcbda
This is the palindromized string.
The Task
Given a string (with at least one character) containing only lowercase letters (or uppercase, if that fits better), output the palindromized string.
Test cases
Input Output
abcb abcba
hello hellolleh
bonobo bonobonob
radar radar
hex hexeh
This is code-golf, so the submission with the least amount of bytes wins!
obonobo
would be a better solution to the test case. \$\endgroup\$bono b o nob
is an entire sentence. What's the difference between God and Bono? God doesn't wander round Dublin pretending to be Bono ;-) \$\endgroup\$