Post Reply 
[VA] SRC #012a - Then and Now: Probability
10-17-2022, 08:16 PM
Post: #62
RE: [VA] SRC #012a - Then and Now: Probability
(10-17-2022 06:29 PM)Dave Britten Wrote:  I'll have to take a look at Albert's program and see if that might be usable (and possibly faster) here.

My flattened array code use little memory, and fast (fastest so far, without using symmetry)

The code use MAT Q=P, but it is not necessary.
All it need is to swap the name of 2 arrays. Sadly, VARSWAP P, Q does not work.

Here is a version that simulate swapping of array name.

Array P of x ≡ A(P, x)
Array Q of x ≡ A(Q, X)

Note: P, Q are now numbers 0 or 1, P+Q=1, not the array itself.

10 DESTROY ALL @ INPUT "[VA]SRC012A R,S= ";R,S @ SETTIME 0
20 OPTION BASE 0 @ REAL A(1,(R+1)*(R+4)/2) @ P=0
30 A(P,2)=1 @ M=2
40 FOR K=1 TO S
50 Q=P @ P=1-P @ A(Q,2)=A(Q,2)*3 @ T=3 ! BUILD Q
60 FOR I=2 TO M-(M=R) @ X=T+1 @ A(Q,X)=A(Q,X)*1.5 @ X=T+I @ A(Q,X)=A(Q,X)*1.5 @ T=X+1 @ NEXT I
70 IF M<>R THEN 100
80 FOR X=T+2 TO T+R-1 @ A(Q,X)=A(Q,X)*1.5 @ NEXT X
90 T=T+1 @ A(Q,T)=A(Q,T)*3 @ A(Q,X)=A(Q,X)*3
100 T=1 @ FOR I=1 TO M @ FOR X=T+1 TO T+I ! BUILD P
110 A(P,X)=A(Q,X-I-1)+A(Q,X-I)+A(Q,X-1)+A(Q,X+1)+A(Q,X+I+1)+A(Q,X+I+2)
120 NEXT X @ T=X @ NEXT I
130 M=M+(M<R)
140 DISP K;TIME
150 NEXT K
160 T=0 @ K=R*(R+1)/2 @ FOR X=K+1 TO K+R @ T=T+A(P,X) @ NEXT X
170 DISP TIME;R;S;T/6^S


>RUN
[VA]SRC012A R,S= 30,60
...
91.38      30 60      9.51234350205E-6

Not as good as original flattened array version (83.1 sec), but not too bad.
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 - Albert Chan - 10-17-2022 08:16 PM



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