mmax:= 10: # to get all terms < 10^mmax
Res:= NULL:
score:= (c, p) -> add(c[i+1]*(i+i^p), i=0..9):
for m from 2 to mmax do
comps:= convert(map(`-`, combinat:-composition(10+m, 10), [1$10]), list):
for c in comps do
cL:= [seq(i$c[i+1], i=0..9)];
if max(c[3..-1]) = 0 then slim:= 0 else slim:= 10^m fi;
for p from 1 do
s:= score(c, p);
L:= sort(convert(s, base, 10));
if L = cL then Res:= Res, s; break fi;
if s >= slim then break fi;
od:
od:
od: