25 lines
658 B
Text
25 lines
658 B
Text
ciphers(n):=block(makelist(floor(mod(n, 10^(k+1)) / 10^k), k, 0,floor(log(n)/log(10))),reverse(%%));
|
|
|
|
collect(a) := block(
|
|
[n: length(ciphers(a)), b: [ ], x: ciphers(a)[1], m: 1],
|
|
for i from 2 thru n do
|
|
(if ciphers(a)[i] = x then m: m + 1 else (b: endcons([x, m], b), x: ciphers(a)[i], m: 1)),
|
|
b: endcons([x, m], b),
|
|
map(reverse,%%),
|
|
flatten(%%),
|
|
at(sum((part(%%,k))*y^(length(%%)-k),k,1,length(%%)),y=10)
|
|
)$
|
|
|
|
block(i:1,append([i],makelist(i:collect(i),9)),table_form(%%));
|
|
/* matrix(
|
|
[1],
|
|
[11],
|
|
[21],
|
|
[1211],
|
|
[111221],
|
|
[312211],
|
|
[13112221],
|
|
[1113213211],
|
|
[31131211131221],
|
|
[13211311123113112211]
|
|
) */
|