How to resolve the algorithm Hofstadter Q sequence step by step in the FreeBASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hofstadter Q sequence step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
It is defined like the Fibonacci sequence, but whereas the next term in the Fibonacci sequence is the sum of the previous two terms, in the Q sequence the previous two terms tell you how far to go back in the Q sequence to find the two numbers to sum to make the next term of the sequence.
(This point is to ensure that caching and/or recursion limits, if it is a concern, is correctly handled).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Hofstadter Q sequence step by step in the FreeBASIC programming language
Source code in the freebasic programming language
Const limite = 100000
Dim As Long Q(limite), i, cont = 0
Q(1) = 1
Q(2) = 1
For i = 3 To limite
Q(i) = Q(i-Q(i-1)) + Q(i-Q(i-2))
If Q(i) < Q(i-1) Then cont += 1
Next i
Print "Primeros 10 terminos: ";
For i = 1 To 10
Print Q(i) &" ";
Next i
Print
Print "Termino numero 1000: "; Q(1000)
Print "Terminos menores que los anteriores: " &cont
End
You may also check:How to resolve the algorithm Levenshtein distance step by step in the Io programming language
You may also check:How to resolve the algorithm HTTPS/Client-authenticated step by step in the C# programming language
You may also check:How to resolve the algorithm Pythagorean triples step by step in the Pascal programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the BASIC programming language