开发者

Graphing calculator logical test error

I tried making the following program and it worked fine at first.

Label 1
Input "n=", Q
If Q≤0
...Then
Goto 1
Else
Label 2
((Q-2int(Q/2))(3Q+1)+(1-Q+2int(Q/2))(Q/2))->Q
Display Q
If Q≠1
Then
Goto 2
Else
Goto 1

What this is supposed to do is I put in a starting number, and if its an even number, it does Q/2. if its odd, it does 3Q+1 and stores the result back into Q. This is the Collatz Conjecture, which states that if this iteration is followed through, no matter what number you start out with, it will always come down to 1. some starting numbers take more steps to reach while some take fewer steps.

The problem:

Sometimes after the program goes through a large number of iterations, it s开发者_如何转开发hows up ERROR, and when I press debug, it takes my cursor over the Q in if Q≠1.

Do you know why this keeps happening? Thanks.


The hurdle that most people have to overcome when doing this puzzle is the overflow caused by huge numbers -- I think that it happens at a number somewhere around 23, IIRC. That might be the case, but I can't see why it would take your cursor over the Q.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜