How to resolve the algorithm Fusc sequence step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fusc sequence step by step in the zkl programming language
Table of Contents
Problem Statement
The fusc integer sequence is defined as:
Note that MathWorld's definition starts with unity, not zero. This task will be using the OEIS' version (above).
where A is some non-negative integer expressed in binary, and where B is the binary value of A reversed.
Fusc numbers are also known as:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fusc sequence step by step in the zkl programming language
Source code in the zkl programming language
fuscs:=List.createLong(1_000_000, 0); fuscs[1]=1; // we'll just use a big count
foreach n in ([2..fuscs.len()-1]){ // and generate
fuscs[n]=( if(n.isEven()) fuscs[n/2] else fuscs[(n-1)/2] + fuscs[(n+1)/2] )
}
println("First 61 terms of the Stern-Brocot sequence:");
fuscs[0,61].concat(" ").println();
println("\nIndex and value for first term longer than any previous:");
println(" Index : Value");
prevMax:=-1;
foreach n in (fuscs.len()){
f,fd := fuscs[n], f.numDigits;
if(fd>prevMax){ println("%15,d : %,d".fmt(n,f)); prevMax=fd }
}
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Clipper programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Haskell programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Rust programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the PowerShell programming language