Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Look-and-say-sequence/Maple/look-and-say-sequence.maple
Normal file
27
Task/Look-and-say-sequence/Maple/look-and-say-sequence.maple
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue