Post Reply 
[VA] SRC #016 - Pi Day 2024 Special
03-17-2024, 05:38 PM (This post was last modified: 03-18-2024 12:05 AM by DavidM.)
Post: #15
RE: [VA] SRC #016 - Pi Day 2024 Special
(03-16-2024 03:58 PM)Gerson W. Barbosa Wrote:  P.S.: It took about one and a half hour, but I’ve finally obtained the results. Some optimizations are definitely required.

When I saw "for N=10, 100, 1000, ..., one million tries", I knew right away that I wasn't going to attempt a straight User RPL solution, mainly because I knew that it was highly unlikely to perform well enough to provide a result before I lost patience with the exercise. Even an empty (User) RPL loop of 1 million iterations takes about 21 minutes on an actual 50g. Start adding code to the loop, and the execution time grows substantially.

The following is my attempt at Appearance 2 using a System RPL/Saturn+ assembly approach. The Saturn code takes advantage of the % (MOD) operator which doesn't exist in real Saturn implementations, so this is only compatible with the ARM-based RPL systems.

!NO CODE
!RPL
::
  CK0NOLASTWD                             ( no arguments expected )
  TEN                                     ( initial N as system binary )
  SIX ZERO_DO                             ( outer loop; count: 6 ) 
    DUP UNCOERCE                          ( make copy of N, convert to real for calculations )
    ZERO                                  ( initial Count as system binary )
    3PICK ZERO_DO                         ( inner loop; count: N )
      OVER %RAN %* %CEIL                  ( first random integer )
      3PICK %RAN %* %CEIL                 ( second random integer )
      COERCE2                             ( convert both numbers to system binary )

      CODE
        GOSBVL POP2# R0=C A               % this Saturn+ code block calculates the GCD
        GOSBVL SAVPTR C=R0 A              % of two system binary numbers in SL1 and SL2      
        { ?C=0 A EXIT D=C A A=A%C A
          C=A A A=D A UP }                % the result is left in SL1 on exit      
        GOVLNG PUSH#ALOOP
      ENDCODE

      #1= IT #1+                          ( if GCD is 1 [ie. integers are coprime], increment Count )
    LOOP
    UNCOERCE %6 ROT %* SWAP %/ %SQRT      ( SQRT[6N/Count] )
    OVER #>$ >TAG                         ( tag the current result with N )
    SWAP #10*                             ( N=N*10 )
  LOOP
  DROP                                    ( N no longer needed )
;
@


Bytes: 130
Checksum: 8E9Bh

Sample output using 0.5 RDZ to seed the PRNG:

     10: 3.46410161514
    100: 3.08606699924
   1000: 3.19166997285
  10000: 3.14037146511
 100000: 3.14975602147
1000000: 3.14017791967


Time: 46.3s (Emu48 on desktop computer)
11851s (real 50g)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #016 - Pi Day 2024 Special - DavidM - 03-17-2024 05:38 PM



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