How to resolve the algorithm Look-and-say sequence step by step in the E programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Look-and-say sequence step by step in the E 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 E programming language
Source code in the e programming language
def lookAndSayNext(number :int) {
var seen := null
var count := 0
var result := ""
def put() {
if (seen != null) {
result += count.toString(10) + E.toString(seen)
}
}
for ch in number.toString(10) {
if (ch != seen) {
put()
seen := ch
count := 0
}
count += 1
}
put()
return __makeInt(result, 10)
}
var number := 1
for _ in 1..20 {
println(number)
number := lookAndSayNext(number)
}
You may also check:How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the Elena programming language
You may also check:How to resolve the algorithm Gapful numbers step by step in the Frink programming language
You may also check:How to resolve the algorithm Hash from two arrays step by step in the D programming language
You may also check:How to resolve the algorithm Quine step by step in the BQN programming language
You may also check:How to resolve the algorithm Sorting algorithms/Selection sort step by step in the Arturo programming language