Your task is to palindromize a string as follows:

Take the string.


Reverse it.


Remove the first letter.


Glue it onto the original string.


But here's the catch: since this challenge is about palindromes, your code itself also has to be a palindrome.

Remember, this is , so the code with the smallest number of bytes wins.

  • 1
    \$\begingroup\$ There should be a hefty bonus for any code that does not use comments to fulfill the palindrome requirement. \$\endgroup\$ – Theo Nov 3 '16 at 2:14
  • \$\begingroup\$ @Theo Then it would go straight to the golf-langs with the palindrome builtin. I don't really see the need for it, and doing it without a comment is more of a personal challenge. \$\endgroup\$ – miles Nov 3 '16 at 2:25
  • \$\begingroup\$ @miles Fair enough. Although I would love to see some creativity from the non-golfing-langs in general. \$\endgroup\$ – Theo Nov 3 '16 at 2:28
  • \$\begingroup\$ Related. \$\endgroup\$ – xnor Nov 3 '16 at 7:53
  • 8
    \$\begingroup\$ Actually, it´s not an exact duplicate. You have to remove one character from the input here. \$\endgroup\$ – Titus Nov 3 '16 at 14:23

23 Answers 23


05AB1E, 1 byte


Try it online!

  • 10
    \$\begingroup\$ Yep. One char is a palindrome. \$\endgroup\$ – JungHwan Min Nov 2 '16 at 23:11
  • 3
    \$\begingroup\$ how do you have a built in for this \$\endgroup\$ – undergroundmonorail Nov 3 '16 at 7:59
  • 2
    \$\begingroup\$ @undergroundmonorail: It is quite often useful in ascii art challenges, or really any challenge with horizontal symmetry. \$\endgroup\$ – Emigna Nov 3 '16 at 8:32
  • 2
    \$\begingroup\$ @Emigna I guess that's fair. I thought "I wonder what function is being horribly abused because it happens to generate this output" but no, I checked the docs and sure enough it's called "palindromize" haha \$\endgroup\$ – undergroundmonorail Nov 3 '16 at 21:43

Python 3, 41 bytes

lambda t:t+t[-2::-1]#]1-::2-[t+t:t adbmal

Try it here.

  • 1
    \$\begingroup\$ My first Python answer \$\endgroup\$ – Luis Mendo Nov 2 '16 at 23:42
  • 1
    \$\begingroup\$ Not that it matters, but one of your reversed brackets is the wrong direction. \$\endgroup\$ – xnor Nov 3 '16 at 0:19
  • 1
    \$\begingroup\$ @xnor Thank you! Corrected \$\endgroup\$ – Luis Mendo Nov 3 '16 at 0:22
  • 1
    \$\begingroup\$ I think he means the other one \$\endgroup\$ – WorldSEnder Nov 3 '16 at 13:29

Dip, 1 byte


Body must be at least 30 characters; you entered 13.


Pyth - 13 bytes

It kinda looks like its crying.

+Qt_Q " Q_tQ+

Try it online here.

  • \$\begingroup\$ +1 for almost being Q_Q \$\endgroup\$ – Downgoat Nov 2 '16 at 23:22
  • 6
    \$\begingroup\$ Hate to see a Qt crying \$\endgroup\$ – Aaron Nov 3 '16 at 9:58
  • \$\begingroup\$ You can use z instead of Q to not need quotes in the input (Which I think you need to add 2 bytes for the required chars in input (pyth.herokuapp.com/…) \$\endgroup\$ – Artyer Nov 3 '16 at 18:38
  • \$\begingroup\$ @Artyer actually, I don't need to add 2 bytes for the " because it is such a common and standard input format. I could have used z, but I was expecting to use the implicit input feature of Q, but ended up not using it, and didn't go back and change it. \$\endgroup\$ – Maltysen Nov 3 '16 at 18:57

아희(Aheui), 149 137 bytes (47 chars + 2 newlines)


Due to the nature of the Aheui language, the input must end in a double quotation mark (") (gets ignored).

Try it here! (copy and paste the code)

Bonus (each line is palindromic), 131 bytes (42 chars + 5 newlines)


APL -- 13 bytes.



     ⌽ Reverse the argument.
  ¯1↓  Drop the last character.
⊣,     Concatenate the original to the result.

JavaScript (ES6), 86 bytes


I tried a smarter solution but it's still longer :/ even abusing [,...a]=s didn't seem to save bytes

  • \$\begingroup\$ aww you ninja'd me \$\endgroup\$ – dkudriavtsev Nov 2 '16 at 23:29
  • 1
    \$\begingroup\$ You can use join`` instead of join("") \$\endgroup\$ – Huntro Nov 3 '16 at 0:55

J, 17 bytes

}:,|.NB. .BN.|,:}

Takes the easy way out by using a comment to mirror the code. In J, NB. starts a line comment. I do hope to find a method that doesn't involve a comment but the digrams in J probably do make it harder.

Also forms two smileys, }: and :}.


   f =: }:,|.NB. .BN.|,:}
   f 'abcde'


Comment part removed since it is just filler.

}:,|.  Input: string S
   |.  Reverse S
}:     Curtail, get S with its last char removed
  ,    Join them and return

C#, (51 50 + 1)*2 = 104 102 bytes

saved 2 bytes to the use of .Aggregate()


You can capture this lambda with

Func<string,string> f = <lambda here>

and call it like this


Ruby, 47 bytes


Mathematica, 67 bytes


Defines a named function f that takes a list of characters as input and returns the appropriate palindromized list as output. The bit after the semicolon (is fortunately syntactically valid and) gives a second, way more complicated name to this same function.

It was fun trying to make Mathematica make sense without any brackets!


Brachylog, 11 bytes


Try it online!


:Lc.         Input concatenated with a string L results in the Output
   .r(.)     The Output reversed is still the Output

The second line is a new predicate declaration that never gets called in that code.


Actually, 14 13 bytes


Try it online!


R          # reverse input
 i         # flatten
  X        # discard top of stack
   ßR      # push reversed input
     kΣ    # concatenate each
k          # wrap in list
 R         # reverse
  ß        # push input
   X       # discard it
    i      # flatten list to string
     R     # reverse string

Pyke, 1 bytes


Try it here!

Yes, this is the same builtin as the digital root one. This time it takes a sting and turns it into a palindrome. Added with this commit (actually on the same day as the digital root question)


Java 7, 146 bytes

(Enter is added for readibility and not part of the code.)

String c(String s){return s+new StringBuffer(s).reverse().substring(1);}/
/};)1(gnirtsbus.)(esrever.)s(reffuBgnirtS wen+s nruter{)s gnirtS(c gnirtS

Java 7, 152 bytes

String c(char[]s,int i){return s.length==i+1?s[i]+"":s[i]+c(s,++i)+s[i-1];}//};]1-i[s+)i++,s(c+]i[s:""+]i[s?1+i==htgnel.s nruter{)i tni,s][rahc(c gnirtS
  • \$\begingroup\$ Beat ya to it with a shorter answer few seconds before you. I like the manual recursive approach instead of new StringBuffer(s).reverse() though. Unfortunately I don't see anything to make it shorter this time. ;) \$\endgroup\$ – Kevin Cruijssen Nov 3 '16 at 8:37
  • \$\begingroup\$ @KevinCruijssen you won.Actually i am weak with handling strings.I need to open my java book. \$\endgroup\$ – Numberknot Nov 3 '16 at 8:44
  • \$\begingroup\$ Seems like this makes it even String c(char[]s,int i){return s.length<i+2?s[i]+"":s[i]+c(s,i+1)+s[i];} \$\endgroup\$ – cliffroot Nov 3 '16 at 10:17

PHP, 38+39=77 bytes


stupid restriction ... for non-eso languages :)

  • \$\begingroup\$ your 3rd character is an =, but does not come back in the end \$\endgroup\$ – nl-x Nov 3 '16 at 9:49
  • \$\begingroup\$ @nl-x Typo ... the bytecount was correct ... apart from the missing $ for argv. Thanks. \$\endgroup\$ – Titus Nov 3 '16 at 9:51

Haskell, 46 44 bytes

p s=init s++reverse s--s esrever++s tini=s p

Try it on Ideone. Saved 2 bytes thanks to Damien.

Straight forward solution. init takes everything but the last character of a string (or last element of a list). -- enables a single line comment.

  • 1
    \$\begingroup\$ init s++reverse s is shorter \$\endgroup\$ – Damien Nov 3 '16 at 10:44

R, 107 bytes

This is the boring solution which just uses comments to make it a palindrome.


R with few comments, 271 bytes

While this code is longer, only 89 of the bytes (33%) are comments, rather than the 50% in the above code. R relies extensively on parentheses for function application, so this was rather difficult.


WinDbg, 142 287 bytes

db$t0 L1;.for(r$t1=@$t0;@$p;r$t1=@$t1+1){db$t1 L1};r$t3=@$t1-1;.for(r$t1=@$t1-3;@$t1>=@$t0;r$t1=@$t1-1;r$t3=@$t3+1){m$t1 L1 $t3};eb$t3 0;da$t0;*;0t$ad;0 3t$be;}3t$ 1L 1t$m{)1+3t$@=3t$r;1-1t$@=1t$r;0t$@=>1t$@;3-1t$@=1t$r(rof.;1-1t$@=3t$r;}1L 1t$bd{)1+1t$@=1t$r;p$@;0t$@=1t$r(rof.;1L 0t$bd

+145 bytes to make it a palindrome, nearly missed that requirement...

Input is passed in via an address in psuedo-register $t0. For example:

eza 2000000 "abcde"           * Write string "abcde" into memory at 0x02000000
r $t0 = 33554432              * Set $t0 = 0x02000000
* Edit: Something got messed up in my WinDB session, of course r $t0 = 2000000 should work
* not that crazy 33554432.

This may be more golfable, for example I feel like there should be an easier way to convert a memory address in a register to the value at that address.

It works by concatenating the chars from the second-to-last to the first to the end of the string.

db $t0 L1;                                      * Set $p = memory-at($t0)
.for (r $t1 = @$t0; @$p; r $t1 = @$t1 + 1)      * Set $t1 = $t0 and increment until $p == 0
    db $t1 L1                                   * Set $p = memory-at($t1)
r $t3 = @$t1 - 1;                               * Point $t3 at end of string

* From the second-to-last char, reverse through the string with $t1 back to the start ($t0)
* and continue to increment $t3 as chars are appended to the string.
.for (r $t1 = @$t1 - 3; @$t1 >= @$t0; r $t1 = @$t1 - 1; r $t3 = @$t3 + 1)
    m $t1 L1 $t3                                * Copy char at $t1 to end of string ($t3)
eb $t3 0;                                       * Null terminate the new string
da $t0;                                         * Print the palindrome string

* Comment of the previous code in reverse, making the whole thing a palindrome
*;0t$ad;0 3t$be;}3t$ 1L 1t$m{)1+3t$@=3t$r;1-1t$@=1t$r;0t$@=>1t$@;3-1t$@=1t$r(rof.;1-1t$@=3t$r;}1L 1t$bd{)1+1t$@=1t$r;p$@;0t$@=1t$r(rof.;1L 0t$bd


0:000> eza 2000000 "abcde"
0:000> r $t0 = 33554432
0:000> db$t0 L1;.for(r$t1=@$t0;@$p;r$t1=@$t1+1){db$t1 L1};r$t3=@$t1-1;.for(r$t1=@$t1-3;@$t1>=@$t0;r$t1=@$t1-1;r$t3=@$t3+1){m$t1 L1 $t3};eb$t3 0;da$t0;*;0t$ad;0 3t$be;}3t$ 1L 1t$m{)1+3t$@=3t$r;1-1t$@=1t$r;0t$@=>1t$@;3-1t$@=1t$r(rof.;1-1t$@=3t$r;}1L 1t$bd{)1+1t$@=1t$r;p$@;0t$@=1t$r(rof.;1L 0t$bd
02000000  61                                               a
02000000  61                                               a
02000001  62                                               b
02000002  63                                               c
02000003  64                                               d
02000004  65                                               e
02000005  00                                               .
02000000  "abcdedcba"

C, 162 bytes


Ungolfed, unpalindromized:

f(char* c,char* d){

c is is input string, assumes output string d has sufficient length.


int main() {
 char a[] = "abcde";
 char* b=malloc(strlen(a)*2);

Perl 5, 44 bytes

43 bytes, plus 1 for -pe instead of -e


𝔼𝕊𝕄𝕚𝕟, 16 chars / 20 bytes


Try it here (ES6 browsers only).

Generated from the interpreter console using this:


Not the answer you're looking for? Browse other questions tagged or ask your own question.