How to resolve the algorithm Look-and-say sequence step by step in the ALGOL-M programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Look-and-say sequence step by step in the ALGOL-M programming language
Table of Contents
Problem Statement
The Look and say sequence is a recursively defined sequence of numbers studied most notably by John Conway.
The look-and-say sequence is also known as the Morris Number Sequence, after cryptographer Robert Morris, and the puzzle What is the next number in the sequence 1, 11, 21, 1211, 111221? is sometimes referred to as the Cuckoo's Egg, from a description of Morris in Clifford Stoll's book The Cuckoo's Egg.
Sequence Definition
An example:
Write a program to generate successive members of the look-and-say sequence.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Look-and-say sequence step by step in the ALGOL-M programming language
Source code in the algol-m programming language
begin
string(1) function digit(n);
integer n;
case n of begin
digit := "0"; digit := "1"; digit := "2";
digit := "3"; digit := "4"; digit := "5";
digit := "6"; digit := "7"; digit := "8";
digit := "9";
end;
string(1) array cur[1:128];
string(1) array next[1:128];
integer curlen, i, cnt, j, n;
cur[1] := "1";
curlen := 1;
for n := 1 step 1 until 15 do begin
write("");
for i := 1 step 1 until curlen do
writeon(cur[i]);
i := j := 1;
while i <= curlen do begin
cnt := 1;
while cur[i + cnt] = cur[i] do
cnt := cnt + 1;
next[j] := digit(cnt);
next[j + 1] := cur[i];
j := j + 2;
i := i + cnt;
end;
for i := 1 step 1 until j-1 do
cur[i] := next[i];
curlen := j - 1;
end;
end
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Raku programming language
You may also check:How to resolve the algorithm Discordian date step by step in the Perl programming language
You may also check:How to resolve the algorithm Sequence: nth number with exactly n divisors step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Secure temporary file step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Sparkline in unicode step by step in the Tcl programming language