# 进行数字回文

12

``````Sample Inputs
12
122
232
2323
1012121
Sample Outputs
121
1221
232
23232
101212101
``````

Computronium

1
@Computronium完成。
fR0DDY '17

4

## Ĵ，50，32 26个字符！

``````f=:{.@(,"1(-:|.)\.#|.@}:\)
``````

``````f '12'
121
f '232'
232
f '2323'
23232
f '1012121'
101212101
``````

### 工作原理（例如）

``````y =: '1012121'

[\.y   NB. Sub lists of y
1012121
012121
12121
2121
121
21
1

|.\. y  NB> Reverses of sub lists of y
1212101
121210
12121
1212
121
12
1

([\. y) -:"1 (|. \. y) NB. Which of them are equal? (those are palindromes)
NB. ( -:"1 ) checks equality item by item
0 0 1 0 1 0 1

(-:  |.)\. y NB. Shortcut of the above
0 0 1 0 1 0 1

(0 0 1 0 1 0 1) # }:\y NB. Choose (#) the palindrome prefixes (\)
10
1012
101212

y, |.'10'   NB. Reverse and append the first prefix.
101212101
``````

10

## Perl，32个字符

``````s/((.)(?1)\2|.?)\$/\$&.reverse\$`/e
``````

``````\$ perl -pe 's/((.)(?1)\2|.?)\$/\$&.reverse\$`/e' << EOT
> 12
> 232
> 2323
> 1012121
> EOT
121
232
23232
101212101
``````

``````m/
(      # paren 1 - a palindrome is either:
(.)  # paren 2 - a character
(?1) # a palindrome as defined in paren 1
\2   # the same character as in paren 2
|        # or:
.?   # a 0- or 1-character string
)
\$      # at end of string
/x
``````

5

# Brachylog 2，8字节，语言日期挑战

``````ẹ;AcB↔Bc
``````

## 说明

``````ẹ;AcB↔Bc
ẹ          Split {the input} into digits
;Ac       Append {the shortest possible} list
B↔B    to produce a palindrome
c   then concatenate the resulting list of digits back into a number
``````

3

## Python，88个字符

``````def f(x):
x,y=list(str(x)),[]
while x!=x[::-1]:y+=x.pop(0)
return''.join(y+x+y[::-1])
``````

gnibbler

2

## 巨蟒（101 96）

``````def p(n):s=str(n);r=s[::-1];l=len(s);return[int(s+r[l-i:])for i in range(l)if s[i:]==r[:l-i]][0]
``````

``````def p(n):
s=str(n);r=s[::-1];l=len(s)
for i in range(l):
if s[i:]==r[:l-i]:return int(s+r[l-i:])
``````

fR0DDY 2011年

@ fR0DDY，如果n足够大以至于需要一个长的
gnibbler

@ fR0DDY，Python不再关心int与longs。int（2346765434567875432456）在v2.6.5上返回2346765434567875432456。我看不出有什么`s=n`帮助；我需要`s`是一个字符串，才能下标获取数字范围。那里是什么原因？

@Hoa，我认为fR0DDY那里有反引号，但它们未出现在评论中
gnibbler 2011年

@Hoa是s = [tick] n [tick]。
fR0DDY 2011年

1

## Python-98个字符

``````def p(n):s=str(n);r=s[::-1];l=len(s);return next(int(s+r[l-i:])for i in range(l)if s[i:]==r[:l-i])
``````

JB

@JB，嗯，您需要python2.6 :)否则`return(...).next()`通常可以编写它，这会花费额外的字符，但是我要在后面删除空格`return`。无论如何，Hoa再次通过使用LC而不是GE

1

## Golfscript-32个字符

``````{`:s-1%:r,,{s<r+..-1%=*}%{}?~}:f
``````

1

## 哈斯克尔，85

``````import List
r=reverse
g(s,_)=s==r s
``````

``````*Main> map (f.show) [12,232,2323,1012121]
["121","232","23232","101212101"]
``````

1

## Ruby 1.9，72个字符

``````f=->x{x=x.to_s.split'';99.times{|i|x.insert~i,x[i]if x!=x.reverse};x*''}
``````

x *''代替x.join保存2个字符。
steenslag

1

1

# Ruby，70个字节

``f=->x{x=x.to_s.chars;99.times{|i|x.insert~i,x[i]if x!=x.reverse};x*''}``

1

### JavaScript（ES6），145126 个字符

`````` p=a=>{S=x=>x.split``.reverse();for(s=String(a),i=0;i<s.length;i++)if(x=s+S(s.substring(0,i)).join``,x==S(x).join``)return x}
``````

``````function palindrome(n){
s = String(n);
for(i=0;i<s.length;i++)
{
x=s+s.substring(0,i).split("").reverse().join("") //take first n characters, reverse and append to the end
if(x==x.split("").reverse().join("")) //is the number a palindrome?
return x;
}
}
``````

0

# Java，174个字节

``````x->{Function<String,String>r=t->new StringBuilder(t).reverse().toString();String y=r.apply(x),z=x;int m=x.length();while(!z.equals(r.apply(z)))z=x+y.substring(--m);return z;}
``````

``````x -> {
Function<String, String> r = t -> new StringBuilder(t).reverse().toString();
String y = r.apply(x), z=x;
int m = x.length();
while (!z.equals(r.apply(z))) z = x+y.substring(--m);
return z;
}
``````