How to resolve the algorithm Fusc sequence step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fusc sequence step by step in the FreeBASIC 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 FreeBASIC programming language
Source code in the freebasic programming language
' version 01-03-2019
' compile with: fbc -s console
#Define max 20000000
Dim Shared As UInteger f(max)
Sub fusc
f(0) = 0
f(1) = 1
For n As UInteger = 2 To max
If n And 1 Then
f(n) = f((n -1) \ 2) + f((n +1) \ 2)
Else
f(n) = f(n \ 2)
End If
Next
End Sub
' ------=< MAIN >=------
Dim As UInteger i, d
Dim As String fs
fusc
For i = 0 To 60
Print f(i); " ";
Next
Print : Print
Print " Index Value"
For i = 0 To max
If f(i) >= d Then
Print Using "###########," ; i; f(i)
If d = 0 Then d = 1
d *= 10
End If
Next
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End
You may also check:How to resolve the algorithm Documentation step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Bitwise operations step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Sorting Algorithms/Circle Sort step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Closures/Value capture step by step in the FreeBASIC programming language