How to resolve the algorithm Hofstadter Q sequence step by step in the MAD programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hofstadter Q sequence step by step in the MAD 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 MAD programming language
Source code in the mad programming language
NORMAL MODE IS INTEGER
VECTOR VALUES FMT = $2HQ(,I4,3H) =,I4*$
DIMENSION Q(1000)
Q(1) = 1
Q(2) = 1
THROUGH FILL, FOR N=3, 1, N.G.1000
FILL Q(N) = Q(N-Q(N-1)) + Q(N-Q(N-2))
THROUGH SHOW, FOR N=1, 1, N.G.10
SHOW PRINT FORMAT FMT, N, Q(N)
PRINT FORMAT FMT, 1000, Q(1000)
END OF PROGRAM
You may also check:How to resolve the algorithm Munching squares step by step in the C programming language
You may also check:How to resolve the algorithm Sailors, coconuts and a monkey problem step by step in the AWK programming language
You may also check:How to resolve the algorithm Minesweeper game step by step in the VBA programming language
You may also check:How to resolve the algorithm Send email step by step in the C programming language
You may also check:How to resolve the algorithm Jensen's Device step by step in the Rascal programming language