I got it!

March 10 2003 at 12:20 PM
Forum Owner

Response to strange.

In my subroutine DoIt is the following:
IF y0 = kp(u) THEN RETURN
u = 0

Assume the repeating sequence is
1 4 6 8 8 3 9 1 2 1 4 6 8 8 3 9 1 2 1 4 6 8 8 3 9 1 2
and I keep the following in kp()
1 4 6 8
then the following happens
...
9 sets u=0
1 y0=kp(1) so u=1 stays
2 y0<>kp(2) so sets u=0
1 y0=kp(1) so u=1 stays
4 y0=kp(2) so u=2 stays
6 y0=kp(3) so u=3 stays
8 y0=kp(4) so u=4 stays
...

That is the normal (good) case.

My bug is for a sequence like this:
1 4 6 8 8 3 9 2 1 1 4 6 8 8 3 9 2 1 1 4 6 8 8 3 9 2 1
where kp() still has 1 4 6 8
now see what happens:
...
9 sets u=0 as before
2 sets u=0
1 y0=kp(1) so u=1 stays
1 y0<>kp(2) so set u=0
4 y0<>kp(1)!!! That is because u=0 above is an error.
...

So I will never find 1 4 6 8 in the sequence above, even though it appears many times.

The solution is to use this code
IF y0 = kp(u) THEN RETURN
if y0=kp(1) then u=1 else u = 0

Mac

 Respond to this message
 Response Title Author and Date ok :) Yeah, the more complicated and less-known your algorithm (View Thread) agamemnnus on Mar 10

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums