Post Reply 
[VA] SRC #012a - Then and Now: Probability
10-17-2022, 05:12 PM
Post: #57
RE: [VA] SRC #012a - Then and Now: Probability
Sharp PC-1403H version of Valentin's 71B program (I didn't really have to change much, aside from minor syntactic/keyword differences):

10 CLEAR:INPUT "ROWS?";M:INPUT "STEPS?";N:DIM A(M,M):DIM B(M,M)
15 A(1,1)=1:W=M-1:FOR I=1 TO N:GOSUB 100
20 P=A(1,1)/2:IF P LET B(2,1)=B(2,1)+P:B(2,2)=B(2,2)+P
25 P=A(M,1)/2:IF P LET B(W,1)=B(W,1)+P:B(M,2)=B(M,2)+P
30 P=A(M,M)/2:IF P LET B(W,W)=B(W,W)+P:B(M,W)=B(M,W)+P
35 FOR X=2 TO W:U=X-1:V=X+1:P=A(X,1)/4:Q=A(X,X)/4:R=A(M,X)/4
40 IF P LET B(U,1)=B(U,1)+P:B(V,1)=B(V,1)+P:B(X,2)=B(X,2)+P:B(V,2)=B(V,2)+P
45 IF Q LET B(U,U)=B(U,U)+Q:B(V,V)=B(V,V)+Q:B(X,U)=B(X,U)+Q:B(V,X)=B(V,X)+Q
50 IF R LET B(M,U)=B(M,U)+R:B(M,V)=B(M,V)+R:B(W,U)=B(W,U)+R:B(W,X)=B(W,X)+R
55 NEXT X:FOR X=3 TO W:U=X-1:V=X+1:FOR Y=2 TO U:R=Y-1:S=Y+1:P=A(X,Y)/6
60 IF P LET B(U,R)=B(U,R)+P:B(U,Y)=B(U,Y)+P:B(X,R)=B(X,R)+P
65 IF P LET B(X,S)=B(X,S)+P:B(V,Y)=B(V,Y)+P:B(V,S)=B(V,S)+P
70 NEXT Y:NEXT X:GOSUB 200:NEXT I:P=0:FOR Y=1 TO M:P=P+A(M,Y):NEXT Y:BEEP 3: PRINT P:END
100 FOR J=1 TO M:FOR K=1 TO J:B(J,K)=0:NEXT K:NEXT J:RETURN
200 FOR J=1 TO M:FOR K=1 TO J:A(J,K)=B(J,K):NEXT K:NEXT J:RETURN
300 "A"S=0:FOR I=1 TO M:FOR J=1 TO I:S=S+A(I,J):NEXT J:NEXT I:PRINT S:END


This model takes about 4 hours to run for the 30, 60 case, and uses about 15 KB RAM for the program + data. After the program finishes, you can press DEF A to calculate the total probability for the whole map (should be extremely close to 1). One could easily tack on some more lines with user-key labels for performing other calculations on the finished matrix (probability of ending in the starting position, on any edge, at specific coordinates, etc.).

I believe this model has some machine-code matrix routines that can be invoked from within BASIC. I'll have to see if those can be used to speed up any of the matrix copying.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #012a - Then and Now: Probability - Dave Britten - 10-17-2022 05:12 PM



User(s) browsing this thread: 1 Guest(s)