How to resolve the algorithm Fusc sequence step by step in the CLU programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fusc sequence step by step in the CLU 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 CLU programming language
Source code in the clu programming language
fusc = iter () yields (int)
q: array[int] := array[int]$[1]
yield(0)
yield(1)
while true do
x: int := array[int]$reml(q)
array[int]$addh(q,x)
yield(x)
x := x + array[int]$bottom(q)
array[int]$addh(q,x)
yield(x)
end
end fusc
longest_fusc = iter () yields (int,int)
sofar: int := 0
count: int := 0
for f: int in fusc() do
if f >= sofar then
yield (count,f)
sofar := 10*sofar
if sofar=0 then sofar:=10 end
end
count := count + 1
end
end longest_fusc
start_up = proc ()
po: stream := stream$primary_output()
stream$putl(po, "First 61:")
n: int := 0
for f: int in fusc() do
stream$puts(po, int$unparse(f) || " ")
n := n + 1
if n = 61 then break end
end
stream$putl(po, "\nLength records:")
n := 0
for i, f: int in longest_fusc() do
stream$putl(po, "fusc(" || int$unparse(i) || ") = " || int$unparse(f))
n := n + 1
if n = 5 then break end
end
end start_up
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Groovy programming language
You may also check:How to resolve the algorithm User input/Text step by step in the Haskell programming language
You may also check:How to resolve the algorithm Exponentiation order step by step in the D programming language
You may also check:How to resolve the algorithm Thue-Morse step by step in the zkl programming language
You may also check:How to resolve the algorithm Host introspection step by step in the Ada programming language