How to resolve the algorithm Look-and-say sequence step by step in the Sather programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Look-and-say sequence step by step in the Sather 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 Sather programming language

Source code in the sather programming language

class MAIN is
   look_and_say!: STR is
      current ::= "1";
      loop
         yield current;
         buf ::= #FSTR;
         last ::= current[0];
         count ::= 0;
         loop
            ch ::= current.elt!;
            if ch /= last then
               buf := buf + count + last;
               last := ch; count := 1;
            else
               count := count + 1;
            end;
         end;
         current := (buf + count + last).str;
      end;
   end;

   main is
      loop 12.times!;
         #OUT+ look_and_say! + "\n";
      end;
   end;
end;

  

You may also check:How to resolve the algorithm Hailstone sequence step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm String length step by step in the BQN programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Show the epoch step by step in the PHP programming language
You may also check:How to resolve the algorithm Parameterized SQL statement step by step in the Arturo programming language