# Palindromize this string! [duplicate]

Take the string.

abcde


Reverse it.

edcba


Remove the first letter.

dcba


Glue it onto the original string.

abcdedcba


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.

• There should be a hefty bonus for any code that does not use comments to fulfill the palindrome requirement. – Theo Nov 3 '16 at 2:14
• @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. – miles Nov 3 '16 at 2:25
• @miles Fair enough. Although I would love to see some creativity from the non-golfing-langs in general. – Theo Nov 3 '16 at 2:28
• – xnor Nov 3 '16 at 7:53
• Actually, it´s not an exact duplicate. You have to remove one character from the input here. – Titus Nov 3 '16 at 14:23

# 05AB1E, 1 byte

û


Try it online!

• Yep. One char is a palindrome. – JungHwan Min Nov 2 '16 at 23:11
• how do you have a built in for this – undergroundmonorail Nov 3 '16 at 7:59
• @undergroundmonorail: It is quite often useful in ascii art challenges, or really any challenge with horizontal symmetry. – Emigna Nov 3 '16 at 8:32
• @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 – undergroundmonorail Nov 3 '16 at 21:43

# Python 3, 41 bytes

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

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

# Dip, 1 byte

B


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

# Pyth - 13 bytes

It kinda looks like its crying.

+Qt_Q " Q_tQ+

• +1 for almost being Q_Q – Downgoat Nov 2 '16 at 23:22
• Hate to see a Qt crying – Aaron Nov 3 '16 at 9:58
• 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/…) – Artyer Nov 3 '16 at 18:38
• @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. – 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.

⊣,¯1↓⌽⍝⌽↓1¯,⊣


Explanation:

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


## JavaScript (ES6), 86 bytes

s=>s+[...s].reverse().slice(1).join("")//)""(nioj.)1(ecils.)(esrever.]s...[+s>=s


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

• aww you ninja'd me – dkudriavtsev Nov 2 '16 at 23:29
• You can use join instead of join("") – 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 :}.

## Usage

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


## Explanation

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()

s=>s+s.Aggregate("",(a,b)=>b+a,s=>s.Substring(1));//;))1(gnirtsbuS.s>=s,a+b>=)b,a(,""(etagerggA.s+s>=s


You can capture this lambda with

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


and call it like this

f("abcde")


## Ruby, 47 bytes

->s{s+s.reverse[1..-1]}#}[1-..1]esrever.s+s{s>-


# Mathematica, 67 bytes

f=#~Join~Rest@Reverse@#//Function;noitcnuF//#@esreveR@tseR~nioJ~#=f


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

:Lc.r
r.cL:


Try it online!

### Explanation

: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

RiXßRkΣkRßXiR


Try it online!

Explanation

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
i      # flatten list to string
R     # reverse string


## Pyke, 1 bytes

s


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

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

• 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. ;) – Kevin Cruijssen Nov 3 '16 at 8:37
• @KevinCruijssen you won.Actually i am weak with handling strings.I need to open my java book. – Numberknot Nov 3 '16 at 8:44
• 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];} – cliffroot Nov 3 '16 at 10:17

# PHP, 38+39=77 bytes

<?=($s=$argv[1]).substr(strrev($s),1);#;)1,)s$(verrts(rtsbus.)]1[vgra$=s$(=?<


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

• your 3rd character is an =, but does not come back in the end – nl-x Nov 3 '16 at 9:49
• @nl-x Typo ... the bytecount was correct ... apart from the missing $ for argv. Thanks. – 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. • init s++reverse s is shorter – Damien Nov 3 '16 at 10:44 # R, 107 bytes This is the boring solution which just uses comments to make it a palindrome. cat(x<-scan(,""),rev(strsplit(x,"")[[1]])[-1],sep="")#)""=pes,]1-[)]]1[[)"",x(tilpsrts(ver,)"",(nacs-<x(tac  # 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. %q%=function (x,y)cat(x,y,sep=e)# %p%=function (x,y)if(length(y),rev(y)[-1],x)# x=strsplit(scan(,e<-""),e)[[1]]# n=NULL e%q%x%p%n n%p%x%q%e LLUN=n #]]1[[)e,)""-<e,(nacs(tilpsrts=x #)x,]1-[)y(ver,)y(htgnel(fi)y,x( noitcnuf=%p% #)e=pes,y,x(tac)y,x( noitcnuf=%q%  # 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


Output:

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 f(char*c,char*d){char*e=c;while(*d++=*c++);c-=2;d-=2;do{*d++=*c--;}while(e<=c);}//};)c=<e(elihw};--c*=++d*{od;2=-d;2=-c;)++c*=++d*(elihw;c=e*rahc{)d*rahc,c*rahc(f  Ungolfed, unpalindromized: f(char* c,char* d){ char*e=c; while(*d++=*c++); c-=2;d-=2; do{*d++=*c--;}while(e<=c); }  c is is input string, assumes output string d has sufficient length. Usage: int main() { char a[] = "abcde"; char* b=malloc(strlen(a)*2); f(a,b); printf("%s\n",b); }  # Perl 5, 44 bytes 43 bytes, plus 1 for -pe instead of -e s#(.*).#$&.reverse$1#e#1$esrever.&$#.)*.(#s  # 𝔼𝕊𝕄𝕚𝕟, 16 chars / 20 bytes ï+ïĦ⬮Đ1//1Đ⬮Ħï+ï  Try it here (ES6 browsers only). Generated from the interpreter console using this: c.value=ï+ï${alias(String.prototype,'reverse')}⬮${alias(String.prototype,'slice')}1//1${alias(String.prototype,'slice')}⬮\${alias(String.prototype,'reverse')}ï+ï