masterBB
2012-09-25 18:01:35
Well, title says it all. Who can calculate the first 1000 digits of pi the fastest with simba? You don't have to write the algorithm itself. Here is one I found.
source: http://www.mathpropress.com/stan/bibliography/spigot.pdf
edited by me
On my old slow laptop I got the following results:
lape
[INDENT]took 936 ms[/INDENT]
pascalscript
[INDENT]took 65723 ms[/INDENT]
source: http://www.mathpropress.com/stan/bibliography/spigot.pdf
edited by me
Program Pi_Spigot;
const
n = 1000;
len = 10*n div 3;
var
i, j, k, q, x, nines, predigit: integer;
tm: integer;
a: array[1..len] of longint;
res: String;
begin
tm := getSystemTime;
for j := 1 to len do
a[j] := 2; {Start with 2s}
nines := 0;
predigit := 0; {First predigit is a 0}
for j := 1 to n do
begin
q := 0;
for i := len downto 1 do {Work backwards}
begin
x := 10*a[i] + q*i;
a[i] := x mod (2*i - 1);
q := x div (2*i - 1);
end;
a[1] := q mod 10;
q := q div 10;
if q = 9 then
nines := nines + 1
else
if q = 10 then
begin
res := res + ToStr(predigit+1);
for k := 1 to nines do
res := res + ToStr(0); {zeros}
predigit := 0;
nines := 0
end
else
begin
res := res + ToStr(predigit);
predigit := q;
if nines <> 0 then
begin
for k := 1 to nines do
res := res + ToStr(9);
nines := 0
end
end
end;
res := res + ToStr(predigit);
writeln('took ' + ToStr(getSystemTime- tm) + ' ms');
writeln(res);
end.On my old slow laptop I got the following results:
lape
[INDENT]took 936 ms[/INDENT]
pascalscript
[INDENT]took 65723 ms[/INDENT]


< Cuda * 2GB