Post Reply 
[VA] SRC #012a - Then and Now: Probability
10-16-2022, 09:20 AM
Post: #42
RE: [VA] SRC #012a - Then and Now: Probability
Here is optimized C.Ret version, without "neighbor hunting" 2 inner loops.
I also remove INTEGER declaration, for some speedup (J-F Garnier, thanks for the tip!)

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


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

From this thread so far, this is the most elegant code, and the fastest! Smile
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-16-2022 09:20 AM



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