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

Published on 12 May 2024 09:40 PM

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

Source code in the erre programming language

PROGRAM LOOK

PROCEDURE LOOK_AND_SAY(N$->N$)
      LOCAL I%,J%,C$,O$
      I%=1
      REPEAT
        C$=MID$(N$,I%,1)
        J%=I%+1
        WHILE MID$(N$,J%,1)=C$ DO
          J%+=1
        END WHILE
        O$+=MID$(STR$(J%-I%),2)+C$
        I%=J%
      UNTIL I%>LEN(N$)
      N$=O$
END PROCEDURE

BEGIN
      NUMBER$="1"
      FOR I%=1 TO 10 DO
        LOOK_AND_SAY(NUMBER$->NUMBER$)
        PRINT(NUMBER$)
      END FOR
END PROGRAM


  

You may also check:How to resolve the algorithm Empty directory step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Barnsley fern step by step in the C# programming language
You may also check:How to resolve the algorithm Factorial step by step in the Nu programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the PHP programming language
You may also check:How to resolve the algorithm Longest string challenge step by step in the XQuery programming language