Qbasic Version of Msdn code

by qbguy

Although the Wald-Wolfowitz test applies only to patterns with just two symbol types, you can often map arbitrary patterns to a Wald-Wolfowitz form. For example, if you have a sequence of integers such as {7, 9, 3, 4, 1, 6}, you can compute their average (5.0) and then map the sequence to symbols H and L, where H represents a number higher than the average and L is a number lower than the average: H H L L L H.

X$ = "XOOOXXXXOXXXXXXXOOOOXXXXXXXXXX"
K1$ = LEFT$(X$, 1)
K2$ = LEFT$(X$, 1)
FOR I = 1 TO LEN(X$)
  IF MID$(X$, I, 1) <> K1$ THEN K2$ = MID$(X$, I, 1)
NEXT
IF K1$ = K2$ THEN PRINT "STRING MUST HAVE 2 DIFFERENT TYPES": STOP
FOR I = 1 TO LEN(X$)
  IF MID$(X$, I, 1) <> K1$ AND MID$(X$, I, 1) <> K2$ THEN
    PRINT "STRING MAY ONLY HAVE 2 TYPES": STOP
  END IF
NEXT
N1 = 0
N2 = 0
RUNS = 1
FOR I = 1 TO LEN(X$) - 1
  IF MID$(X$, I, 1) = K1$ THEN N1 = N1 + 1 ELSE N2 = N2 + 1
  IF MID$(X$, I + 1, 1) <> MID$(X$, I, 1) THEN RUNS = RUNS + 1
NEXT

Posted on Mar 19, 2008, 11:15 AM
from IP address 75.9.218.72

Respond to this message   

Goto Forum Home


Response TitleAuthor and Date
Version with a function to convert array to string as described in Articleqbguy on Mar 19
Ahhh, now we're getting somewhere. on Mar 20