Look-and-say sequence: Difference between revisions
Content deleted Content added
Added Applesoft BASIC, Chipmunk Basic, GW-BASIC, MSX BASIC and True BASIC |
imported>Maxima enthusiast |
||
Line 3,202: | Line 3,202: | ||
"31131211131221" |
"31131211131221" |
||
"13211311123113112211" */</syntaxhighlight> |
"13211311123113112211" */</syntaxhighlight> |
||
Implementation treating the sequence as numbers |
|||
<syntaxhighlight lang="maxima"> |
|||
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,makelist(i:collect(i),10),table_form(%%)); |
|||
/* matrix( |
|||
[11], |
|||
[21], |
|||
[1211], |
|||
[111221], |
|||
[312211], |
|||
[13112221], |
|||
[1113213211], |
|||
[31131211131221], |
|||
[13211311123113112211], |
|||
[11131221133112132113212221] |
|||
) */ |
|||
</syntaxhighlight> |
|||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== |