
-----------------------------------
AtoZ
Sat Jan 31, 2009 5:51 pm

Finding the value of pi=3.141592653589793238...
-----------------------------------
This program find the value of pi to some number of digits using the method to find an accurate value. Unfortunately, household computers are not very powerful and neither is the turing environment, therefore, it only calculates to 6 digits quickly. For my computer, with a speed of around 1.3mil loops/sec, it takes 25 seconds to get 7 digits, but only 3 seconds to get 6 digits. 

Also, it calculates pi to 49 digits (which is the max in turing i think), but the correct digits are only limited to maybe 5-7. 

If you have time or a very fast and powerful computer, run it for maybe 8-10 digits, and let me know if it works properly.

This program also finds your computer speed and your processor number and operating system.

If you post about the run time of the program, plz also post ur computer speed with it.

Oh btw, i copied the method to find the computer speed from a turing submission by Zren from this link:http://compsci.ca/v3/viewtopic.php?t=19986. So, sorry for copying, but it is not a major part of the program.


% 4(1-1/3+1/5-1/7+...)= pi
/*
 Running time in ms     Number of digits (after the decimal) of pi you want.
 12                     0
 12                     1
 12                     2
 13                     3
 35                     4
 265                    5
 2550                   6
 25600                  7
 
 These times are for a computer with a speed of 
 around 1.3 million loops/second.
*/

var correctdigits : int := 0

locate (20, 1)
put "~~~ Note: Any value higher than 6 will take very long to process.~~~"
locate (21, 1)
put "For 6 digits, it takes approximately 2500 ms."
put "After which the processing time increases by 10 times."
locate (1, 1)
put "Hello!"
put "To how many correct digits of pi would you like to see: " ..
get correctdigits

const CONST := (10 ** correctdigits)
const digits := 49


var x : array 1 .. CONST of real
var y : array 1 .. CONST of real
var answer1 : real
var answer2 : real
var total : real
var pi : real

for i : 1 .. CONST
    x (i) := 1 / (-1 * (i * 4 - 1))
end for

for i : 1 .. CONST
    y (i) := 1 / (i * 4 - 3)
end for

answer1 := 0
for i : 1 .. CONST
    answer1 := answer1 + x (i)
end for

answer2 := 0
for i : 1 .. CONST
    answer2 := answer2 + y (i)
end for

total := answer2 + answer1
pi := 4 * total

put ""
put "The value of pi to the calculated digits: "
put pi : 0 : digits
put ""
put "The value of pi to the correct digits: " ..
put pi : 0 : correctdigits


var speed : int := 0

function compSpeed : int
    var tstart : int := Time.Sec
    var t, cycle : int := 0
    loop
        t := Time.Sec
        exit when t > tstart + 1
        cycle += 1
    end loop
    result cycle
end compSpeed

speed := compSpeed
put ""
put ""
put "Your compter speed: " ..
put speed, " (loops/sec)"

put ""
put "Operating System: ", Config.Machine (cmOS)
put "Processor Number: ", Config.Machine (cmProcessor)

MOD EDIT: Remember the code tags!

-----------------------------------
Ultrahex
Sat Jan 31, 2009 11:08 pm

Re: Finding the value of pi=3.141592653589793238...
-----------------------------------
Using your code:

var a :=1.0
var a2:=a
var b:=1.0/sqrt(2.0)
var t:=1.0/4
var p:=1

for i : 1 .. 3
    a2 := (a+b)/2
    b := sqrt(a*b)
    t := t-p*(a-a2)**2
    p := 2*p
    a := a2;
end for
var pi := (a+b)**2/(4*t)
put pi:0:14
put "Time: ", Time.Elapsed () / 1000, " seconds"


-----------------------------------
The_Bean
Sun Feb 01, 2009 9:26 am

Re: Finding the value of pi=3.141592653589793238...
-----------------------------------
I would have to say memorizing the number of digits you want is a lot faster.  Sure it might take 2 months for 155 decimal places, but then it only takes roughly 30 seconds to type it in.  You can also use random sections from it for passwords.


View.Set ("graphics:500,500,nobuttonbar,position:center,center")
var pi : string := "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111"
var timeStart : int
var input : char
Text.Colour (42)
Text.ColourBack (7)
cls
put "Enter Pi to 155 decimal places!"
loop
    exit when hasch
end loop
timeStart := Time.Elapsed
for i : 1 .. 157
    input := getchar
    if input = pi (i) then
        put input ..
    else
        put "E"
        put "You messed up at the number: ", i - 2, " decimal place."
        exit
    end if
end for
put ""
put "That took: ", (Time.Elapsed - timeStart) / 1000


-----------------------------------
michaelp
Sun Feb 01, 2009 10:27 am

RE:Finding the value of pi=3.141592653589793238...
-----------------------------------
http://www.gamedev.net/community/forums/topic.asp?topic_id=418236
:D
