How to resolve the algorithm Look-and-say sequence step by step in the LiveCode programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Look-and-say sequence step by step in the LiveCode 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 LiveCode programming language
Source code in the livecode programming language
function lookAndSay S
put 0 into C
put char 1 of S into lastChar
repeat with i = 2 to length(S)
add 1 to C
if char i of S is lastChar then next repeat
put C & lastChar after R
put 0 into C
put char i of S into lastChar
end repeat
return R & C + 1 & lastChar
end lookAndSay
on demoLookAndSay
put 1 into x
repeat 10
put x & cr after message
put lookAndSay(x) into x
end repeat
put x after message
end demoLookAndSay
You may also check:How to resolve the algorithm Rot-13 step by step in the CLU programming language
You may also check:How to resolve the algorithm Determine if two triangles overlap step by step in the Raku programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the smart BASIC programming language
You may also check:How to resolve the algorithm Knuth's algorithm S step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the Scheme programming language