Look-and-say sequence: Difference between revisions

Content deleted Content added
Thundergnat (talk | contribs)
m Regularize non-standard header markup
No edit summary
Line 2,174:
define(`v',las(v))')dnl
v</lang>
 
=={{header|Maple}}==
<lang Maple>generate_seq := proc(s)
local times, output, i;
times := 1;
output := "";
for i from 2 to StringTools:-Length(s) do
if (s[i] <> s[i-1]) then
output := cat(output, times, s[i-1]);
times := 1; # re-assign
else
times ++;
end if;
end do;
cat(output, times, s[i - 1]);
end proc:
 
Look_and_Say :=proc(n)
local value, i;
value := "1";
print(value);
for i from 2 to n do
value := generate_seq(value);
print(value);
end do;
end proc:
 
#Test:
Look_and_Say(10);</lang>
 
{{out}}
<pre>
"1"
"11"
"21"
"1211"
"111221"
"312211"
"13112221"
"1113213211"
"31131211131221"
"13211311123113112211"
</pre>
 
 
=={{header|Mathematica}}==