BEGIN SEQ (n)
IF (n <= 3) THEN
RETURN n * 2
ELSE
RETURN SEQ (n - 3) + SEQ (n - 1)
ENDIF
END
For instance, for n = 8, I ran it in a compiler and the final return value is 38.
I tried tracing it in the program printing the value of n out but it was very confusing.
My compiler trace output:
/////////////////
Pre 8, Pre 5, Satisfied at 2
Pre 4, Satisfied at 1
Satisfied at 3
Pre 7, Pre 4, Satisfied at 1
Satisfied at 3
Pre 6, Satisfied at 3
Pre 5, Satisfied at 2
Pre 4, Satisfied at 1
Satisfied at 3
Final answer: 38
/////////////////
Satisfied values are the return n values before they were multiplied by 2.
Pre values are the ELSE recursive n values before they get returned.
This is very confusing for me and Ive been at it for hours, please don't be vague and try to let me figure it out myself, simple direct explanations would be really awesome at this point. Thanks.