공리, 900 바이트
R(x)==>return x;p(r,a)==(n:=#(a::String);if r<0 then(a=0=>R a;n=1 or a=10^(n-1)=>R(a-1);a=10^(n-1)+1=>R(a-2));if r>0 then(n=1 and a<9=>R(a+1);a=10^n-1=>R(a+2));r=0 and n=1=>1;v:=a quo 10^(n quo 2);repeat(c:=v;w:=(n rem 2>0=>v quo 10;v);repeat(c:=10*c+w rem 10;w:=w quo 10;w=0=>break);r<0=>(c<a=>R c;v:=v-1);r>0=>(c>a=>R c;v:=v+1);R(c=a=>1;0));c)
b:List INT:=[];o:INT:=0
f(a:NNI):List INT==(free b,o;o:=p(-1,o);w:=0;c:=#b;if c>0 then w:=b.1;e:=a-o;e>10000000=>R[];if w<e then repeat(w:=p(1,w);w>e=>break;b:=cons(w,b));g:List INT:=[];for i in #b..1 by-1 repeat(b.i>e=>break;g:=cons(b.i,g));if o>e then g:=cons(o,g);n:=#g;for i in 1..n repeat(x:=g.i;x=a=>R[x];3*x<a=>break;for j in i..n repeat(y:=g.j;t:=x+y;t>a=>iterate;t=a=>R[x,y];t+y<a=>break;for k in j..n repeat(z:=t+g.k;z=a=>R[x,y,g.k];z<a=>break)));[])
D(a:NNI):List INT==(free o;p(0,a)=1=>[a];o:=a;for j in 1..10 repeat(t:=f(a);#t>0=>R t);[])
테스트 코드
--Lista random di n elmenti, casuali compresi tra "a" e "b"
randList(n:PI,a:INT,b:INT):List INT==
r:List INT:=[]
a>b =>r
d:=1+b-a
for i in 1..n repeat
r:=concat(r,a+random(d)$INT)
r
test()==
a:=randList(20,1,12345678901234)
[[i,D(i)] for i in a]
이 코드가 1,2,3 회문에서 숫자 X를 분해해야하는 경우,이 코드의 기능은 회문 N <X 근처에서 시도하고 2 회 회문에서 XN을 분해합니다. XN의 이러한 분해가 성공 회귀 3 개를 발견하면; 실패하면 이전 palindrome G <N <X를 시도하고 2 개의 palindrome 등에서 XG를 분해하십시오. Ungolf code (그러나 버그가 발생할 수 있습니다)
R(x)==>return x
-- se 'r'=0 ritorna 1 se 'a' e' palindrome altrimenti ritorna 0
-- se 'r'>0 ritorna la prossima palindrome >'a'
-- se 'r'<0 ritorna la prossima palindrome <'a'
p(r,a)==(n:=#(a::String);if r<0 then(a=0=>R a;n=1 or a=10^(n-1)=>R(a-1);a=10^(n-1)+1=>R(a-2));if r>0 then(n=1 and a<9=>R(a+1);a=10^n-1=>R(a+2));r=0 and n=1=>1;v:=a quo 10^(n quo 2);repeat(c:=v;w:=(n rem 2>0=>v quo 10;v);repeat(c:=10*c+w rem 10;w:=w quo 10;w=0=>break);r<0=>(c<a=>R c;v:=v-1);r>0=>(c>a=>R c;v:=v+1);R(c=a=>1;0));c)
b:List INT:=[] -- the list of palindrome
o:INT:=0 -- the start value for search the first is a
--Decompose 'a' in 1 or 2 or 3 palindrome beginning with prev palindrome of o
--if error or fail return []
f(a:NNI):List INT==
free b,o
-- aggiustamento di o, come palindrome piu' piccola di o
o:=p(-1,o)
-- aggiustamento di b come l'insieme delle palindromi tra 1..a-o compresa
w:=0;c:=#b
if c>0 then w:=b.1 --in w la massima palindrome presente in b
e:=a-o
output["e=",e,"w=",w,"o=",o,"#b=",#b]
e>10000000=>R[] --impongo che la palindrome massima e' 10000000-1
if w<e then --se w<a-o aggiungere a b tutte le palindromi tra w+1..a-o
repeat(w:=p(1,w);w>e=>break;b:=cons(w,b))
-- g e' l'insieme dei b palindromi tra 1..a-o,o
g:List INT:=[];for i in #b..1 by-1 repeat(b.i>e=>break;g:=cons(b.i,g))
if o>e then g:=cons(o,g)
--output["g=",g,b]
n:=#g
for i in 1..n repeat
x:=g.i
x=a =>R[x]
3*x<a=>break
for j in i..n repeat
y:=g.j;t:=x+y
t>a =>iterate
t=a =>R[x,y]
t+y<a =>break
for k in j..n repeat
z:=t+g.k
z=a =>R[x,y,g.k]
z<a =>break
[]
--Decompose 'a' in 1 or 2 or 3 palindrome
--if error or fail return []
dPal(a:NNI):List INT==
free o
p(0,a)=1=>[a]
o:=a -- at start it is o=a
for j in 1..10 repeat -- try 10 start values only
t:=f(a)
#t>0=>R t
[]
결과 :
(7) -> [[i,D(i)] for i in [5,15,21,42,132,345,1022,9265] ]
(7)
[[5,[5]], [15,[11,4]], [21,[11,9,1]], [42,[33,9]], [132,[131,1]],
[345,[343,2]], [1022,[999,22,1]], [9265,[9229,33,3]]]
Type: List List Any
Time: 0.02 (IN) + 0.02 (OT) = 0.03 sec
(8) -> test()
(8)
[[7497277417019,[7497276727947,624426,64646]],
[11535896626131,[11535888853511,7738377,34243]],
[2001104243257,[2001104011002,184481,47774]],
[3218562606454,[3218561658123,927729,20602]],
[6849377785598,[6849377739486,45254,858]],
[375391595873,[375391193573,324423,77877]],
[5358975936064,[5358975798535,136631,898]],
[7167932760123,[7167932397617,324423,38083]],
[11779002607051,[11779000097711,2420242,89098]],
[320101573620,[320101101023,472274,323]],
[5022244189542,[5022242422205,1766671,666]],
[5182865851215,[5182864682815,1158511,9889]],
[346627181013,[346626626643,485584,68786]],
[9697093443342,[9697092907969,443344,92029]],
[1885502599457,[1885502055881,542245,1331]], [10995589034484,[]],
[1089930852241,[1089930399801,375573,76867]],
[7614518487477,[7614518154167,246642,86668]],
[11859876865045,[11859866895811,9968699,535]],
[2309879870924,[2309879789032,81418,474]]]
Type: List List Any
Time: 0.25 (IN) + 115.17 (EV) + 0.13 (OT) + 28.83 (GC) = 144.38 sec