Hofstadter’s Q-Sequence in Code Coach | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

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?

30th Mar 2020, 5:17 PM
JaScript
JaScript - avatar
7 Answers
+ 5
Are you using recursion? If yes, try to use for loop.
30th Mar 2020, 5:44 PM
Denise Roßberg
Denise Roßberg - avatar
+ 5
I did it in C by storing the former results in an array instead of recreating them over and over recursively.
30th Mar 2020, 5:55 PM
HonFu
HonFu - avatar
+ 5
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.
30th Mar 2020, 7:09 PM
JaScript
JaScript - avatar
+ 5
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.
1st Apr 2020, 4:46 PM
JaScript
JaScript - avatar
30th Mar 2020, 6:04 PM
Mihai Apostol
Mihai Apostol - avatar
0
Cómo ASER que tú página salga ala red
14th Aug 2021, 7:21 PM
BRAYAN VLADIMIR RIVERA COTO
0
Y
14th Aug 2021, 7:26 PM
BRAYAN VLADIMIR RIVERA COTO