28 lines
481 B
Plaintext
28 lines
481 B
Plaintext
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);
|