How to resolve the algorithm Look-and-say sequence step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Look-and-say sequence step by step in the zkl 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 zkl programming language
Source code in the zkl programming language
fcn lookAndSay(seed){ // numeric String --> numeric String
len,c:=[1..seed.len()-1].reduce(fcn([(len,c)]lc,index,s,sb){
if(c!=s[index]) { sb.write(len); sb.write(c); lc.clear(1,s[index]) }
else lc.clear(len+1,c);
},L(1,seed[0]), seed,sb:=Sink(String));
sb.write(len); sb.write(c);
sb.close();
}
You may also check:How to resolve the algorithm MD5 step by step in the Neko programming language
You may also check:How to resolve the algorithm Maze generation step by step in the Nim programming language
You may also check:How to resolve the algorithm Factorial step by step in the Frink programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Action! programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Ruby programming language