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

Published on 12 May 2024 09:40 PM

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

Source code in the miniscript programming language

// Look and Say Sequence
repeats = function(digit, string)
	count = 0
	for c in string
		if c != digit then break
		count = count + 1
	end for
	return str(count)
end function
 
numbers = "1"
print numbers
for i in range(1,10) // warning, loop size > 15 gets long numbers very quickly
	number = ""
	position = 0
	while position < numbers.len
		repeatCount = repeats(numbers[position], numbers[position:])
		number = number + repeatCount + numbers[position]
		position = position + repeatCount.val
	end while
	print number
	numbers = number
end for


  

You may also check:How to resolve the algorithm Hunt the Wumpus step by step in the Perl programming language
You may also check:How to resolve the algorithm Function composition step by step in the NewLISP programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the D programming language
You may also check:How to resolve the algorithm GUI enabling/disabling of controls step by step in the Nim programming language
You may also check:How to resolve the algorithm Numeric error propagation step by step in the Perl programming language