[VA] SRC #012a - Then and Now: Probability
|
10-17-2022, 12:13 AM
Post: #51
|
|||
|
|||
RE: [VA] SRC #012a - Then and Now: Probability
(10-16-2022 05:52 PM)Valentin Albillo Wrote: Another pretty obvious optimization would be to take advantage of the symmetry, as the man's starting location is at the top corner; this would cut running time and required RAM roughly in half but it loses generality, i.e.: arbitrary non-symmetrically placed starting positions (one or more) would not run at all, and it would complicate the coding somewhat; also, for a one-time program which already runs suitably fast it's really a moot point. Here is my code, removed symmetry for generality. For other starting positions, edit LINE 30, with M = first empty row. Tips: we can *still* use symmetry, by rotation for the smallest starting M 10 DESTROY ALL @ INPUT "[VA]SRC012A R,S= ";R,S @ SETTIME 0 20 OPTION BASE 0 @ T=R+1 @ REAL P(T,T),Q(T,T) 30 P(1,1)=1 @ M=2 40 FOR K=1 TO S 50 MAT Q=P @ Q(1,1)=Q(1,1)*3 ! BUILD Q 60 FOR I=2 TO M-(M=R) @ Q(I,1)=Q(I,1)*1.5 @ Q(I,I)=Q(I,I)*1.5 @ NEXT I 70 IF M<>R THEN 100 80 FOR J=2 TO R-1 @ Q(R,J)=Q(R,J)*1.5 @ NEXT J 90 Q(R,1)=Q(R,1)*3 @ Q(R,R)=Q(R,R)*3 100 FOR I=1 TO M @ FOR J=1 TO I ! BUILD P 110 P(I,J)=Q(I+1,J)+Q(I+1,J+1)+Q(I,J-1)+Q(I,J+1)+Q(I-1,J-1)+Q(I-1,J) 120 NEXT J @ NEXT I 130 M=M+(M<R) 140 DISP K;TIME 150 NEXT K 160 T=0 @ FOR J=1 TO R @ T=T+P(R,J) @ NEXT J 170 DISP TIME;R;S;T/6^S >RUN [VA]SRC012A R,S= 30,60 ... 87.6 30 60 9.51234350205E-6 As expected, without symmetry, speed almost cut in half. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 12 Guest(s)