• Please review our updated Terms and Rules here

Pi Day

Here is my homage:

Code:
* Program to compute PI using Monte Carlo method
      PROGRAM monte_pi
    
      INTEGER niter, i, j, cont, sem
      DOUBLE PRECISION x, y, pi(100), z, RAND

* Initialize random numbers
      sem = 35791246
      CALL SRAND(sem)
      DO 1,j = 1, 100
        niter = niter + 100
        cont = 0
        DO 2,i = 1, niter
          x = RAND()
          y = RAND()
          z = x*x + y*y
          IF (z .LE. 1) cont = cont + 1
2       CONTINUE
        pi(j) = DBLE(cont) / DBLE(niter) * 4.0
        WRITE(*,100) niter, pi(j)
1     CONTINUE
100   FORMAT(1X,'Number of tries: ', I5,' PI estimate: ', F8.6)
      END

*     ******************************************************************
      SUBROUTINE SRAND(iseed)

      INTEGER iseed
      COMMON /SEED/ jseed, ifrst

      jseed = iseed
      ifrst = 0
      END

*     ******************************************************************
      DOUBLE PRECISION FUNCTION RAND()

      INTEGER mplier, modlus, mobymp, momdmp
      PARAMETER (mplier=16807, modlus=2147483647, mobymp=127773,
     &           momdmp=2836)
      COMMON  /SEED/ jseed, ifrst
      INTEGER hvlue, lvlue, testv, nextn
      SAVE nextn

      IF (ifrst .EQ. 0) THEN
        nextn = jseed
        ifrst = 1
      END IF
      hvlue = nextn / mobymp
      lvlue = MOD(nextn, mobymp)
      testv = mplier * lvlue - momdmp * hvlue
      IF (testv .GT. 0) THEN
        nextn = testv
      ELSE
        nextn = testv + modlus
      END IF
      RAND = DBLE(nextn) / DBLE(modlus)
      END

Compiled and tested on a 12Mhz 286 + 8Mhz 287 using RM/FORTRAN 2.43
 
This is what I can still remember from the 200 digits of PI I memorized in 6th grade - at least I can still recall 55 digits correctly!

3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209
 
Everyone please report back how long it took to run it on your various systems :)

My low end Windows desktop did it in
TotalSeconds : 11.4026988
 
You memorized 200 digits of Pi in 6th grade?!

Yep, I had to recite them perfectly and without one single error or it was a fail. Students could choose amounts from 25 to 200 and would get a specific number of A assignments depending on their choice. I got 8 A's for it!
 
This is what I can still remember from the 200 digits of PI I memorized in 6th grade - at least I can still recall 55 digits correctly!

3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209
You did much better than my program 😀 and, probably, faster too :ROFLMAO::ROFLMAO:
It took 6 min. 56 secs. on the 286 @ 12Mhz and the last estimated value was 3.138400
 
Last edited:
I went through bootcamp...

With that said, that seems like some kind of psychological torture the likes I cant even comprehend!

It was a DOD teacher on a military base. The funny thing to me is how much it has stuck with me over the years as that was the 80s.
 
Here's a few more for your tally:
  • HP Elite Mini Desktop [i3]: 13.23 sec
  • Main Desktop [i9]: 3.37 sec
Sadly, I don't have FORTRAN running on any vintage machines to test out the alternate code. I'll be better prepared next Pi Day. :)
 
MicroPython v1.1 board (stm32F405 @168 MHz.
Wall clock elapsed time: 17 minutes
Code:
The approximate value of pi is: 3.16411
Not exactly spectacular for a 32 bit pipelined MCU.
 
Back
Top