Post Reply 
[VA] SRC #013 - Pi Day 2023 Special
03-23-2023, 12:24 AM
Post: #17
RE: [VA] SRC #013 - Pi Day 2023 Special
   
Hi, all,

Casually looking at my code for solution 1 I realized that I did overlook a small but obvious optimization, namely not trying to update the sum S if the Möbius value M(K) is zero.

The slightly modified code is now 225 bytes instead of 217, and runs about 5,4% faster:

1  DESTROY ALL @ INPUT T @ SETTIME 0 @ N=SQR(T) @ INTEGER M(N) @ MAT M=CON @ P=2 @ WHILE P<=N
2  S=P*P @ FOR K=S TO N STEP S @ M(K)=0 @ NEXT K @ FOR K=P TO N STEP P @ M(K)=-M(K) @ NEXT K
3  P=FPRIM(P+1) @ END WHILE @ S=T @ FOR K=2 TO N @ IF M(K) THEN S=S+M(K)*(T DIV (K*K))
4  NEXT K @ DISP USING "2(3DC3DC3DC3D,2X),2(Z.8D,X),5DZ.2D";T,S,SQR(6*T/S),ABS(PI-RES),TIME
          N         Count    \(\pi\) approx    |Error|     go71b  Emu71/Win  Physical
                                                     @128x    @976x     HP-71B
    ----------------------------------------------------------------------------
        12,345       7,503  3.14198205  0.00038939    0.09"    0.01"        12"
       100,000      60,794  3.14155933  0.00003333    0.27"    0.04"        35"
       567,890     345,237  3.14158684  0.00000582    0.65"    0.09"     1' 23"
     1,000,000     607,926  3.14159550  0.00000285    0.87"    0.11"     1' 51"

    10,000,000   6,079,291  3.14158749  0.00000516    2.86"    0.38"     6'  6"
    25,000,000  15,198,180  3.14159240  0.00000025    4.59"    0.60"     9' 48"
    33,000,000  20,061,593  3.14159276  0.00000011    5.29"    0.69"    11' 17"

        1E8     60,792,694  3.14159307  0.00000042    9.37"    1.23"    19' 59"
        1E9    607,927,124  3.14159260  0.00000006   30.70"    4.03"    65' 30"
V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
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 #013 - Pi Day 2023 Special - Valentin Albillo - 03-23-2023 12:24 AM



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