Hofstadter’s Q-Sequence in Code Coach | SoloLearn: Learn to code for FREE!


Hofstadter’s Q-Sequence in Code Coach

Only the first two checks Hofstadter’s Q-Sequence are passing with my code. Did anyone pass the full exercise with C# or att all?

3/30/2020 5:17:45 PM

Ja Play

5 Answers

New Answer


Are you using recursion? If yes, try to use for loop.


I did it in C by storing the former results in an array instead of recreating them over and over recursively.


Yes, I use the Recursive Algorithm. The results are correct, but from n=43 on the calculation time is obviously exceeded. So I will therefore use a different method. Thanks for your tips.


Guys, I made it. I taken a list and calculated the Q(n) in a "for" loop - as Denise Roßberg and HonFu mentioned, step by step for one "n", using the two results Q(n-1) and Q(n-2), that were in the list before. This algorithm is super fast. Now it calculates here for millions. For example Q(50,000,000) = 25,371,105. And that was not even the biggest (n) here. Thanks.