How to resolve the algorithm Hofstadter Q sequence step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hofstadter Q sequence step by step in the Ring 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 Ring programming language
Source code in the ring programming language
n = 20
aList = list(n)
aList[1] = 1
aList[2] = 1
for i = 1 to n
if i >= 3 aList[i] = ( aList[i - aList[i-1]] + aList[i - aList[i-2]] ) ok
if i <= 20 see "n = " + string(i) + " : "+ aList[i] + nl ok
next
You may also check:How to resolve the algorithm Associative array/Creation step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Wieferich primes step by step in the Quackery programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the Processing programming language
You may also check:How to resolve the algorithm Zebra puzzle step by step in the Java programming language
You may also check:How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the M2000 Interpreter programming language