+ -
当前位置:首页 → 问答吧 → Sharing How to caculate pi upto long-digits

Sharing How to caculate pi upto long-digits

时间:2014-03-17

来源:互联网

A Program (32 years ago) showing how to calculate pi up to very long digits .

10 KEY OFF:CLSRINT "Enter digits of ";CHR$(227);" do you want to compute ";
15 INPUT"",SZ:CLS
20 TE=10:IF SZ>200 THEN 30
25 TE=100:SZ=(SZ+1)/2
30 DEF SEG=&HB800O=4096:TR=PO*2:RE=PO*3
35 CO(1)=25:CO(2)=239
40 '
45 FOR PA = 1 TO 2
50 FOR PL = 0 TO SZOKE PO+PL,0OKE TR+PL,0
55 IF PA=1 THEN POKE RE+PL,0
60 NEXT PLOKE PO,16/PA^2
65 IF PA=1 THEN DV=5:GOTO 75
70 DV=239
75 PT=PO:GOSUB 165:EX=1:SI=3-2*PA
80 '
85 FOR PL = 0 TO SZ :POKE TR+PL,PEEK(PO+PL):NEXT PL
90 PT=TRV=EX:GOSUB 165
95 IF SI>0 THEN GOSUB 190
100 IF SI<0 THEN GOSUB 230
105 EX=EX+2:SI=-SI:PT=POV=CO(PA):GOSUB 165
110 IF PA=2 THEN GOSUB 165
115 IF ZE <>0 THEN GOSUB 125:GOTO 85
120 NEXT PA:GOSUB 125:END
125 '
130 LOCATE 10,6:PRINT
135 PRINT"The value of ";CHR$(227);" up to ";(TE/100+1)*SZ;" decimal place :"RINT:PRINT"3.";
140 FOR PL=RE+1 TO RE+SZ: IF TE=10 THEN 150
145 IF PEEK(PL)<10 THEN PRINT"0";
150 FOR K= 1 TO LEN(STR$(PEEK(PL))):PRINT MID$(STR$(PEEK(PL)),K+1,1);:NEXT K,PL:PRINT
155 RETURN
160 '
165 DI=0:ZE=0
170 FOR PL = PT TO PT +SZ
175 DI=DI+PEEK(PL)U=INT(DI/DV):RU=DI-QU*DV:ZE=-(ZE OR (QU+RU)):POKE PL,QUI=TE*RU:NEXT PL
180 RETURN
185 '
190 CA=0
195 FOR PL = SZ TO 0 STEP -1
200 SU=PEEK(RE+PL)+PEEK(TR+PL)+CA:CA=0
205 IF SU<TE THEN 215
210 SU=SU-TE:CA=1
215 POKE RE+PL,SU:NEXT PL
220 RETURN
225 '
230 LO=0
235 FOR PL = SZ TO 0 STEP -1
240 DF =PEEK (RE+PL)-PEEK(TR+PL)-LOO=0
245 IF DF >=0 THEN 255
250 DF =DF +TEO =1
255 POKE RE+PL,DF :NEXT PL
260 RETURN




[ 本帖最后由 西营盘旧街坊 於 2014-3-1 08:26 AM 编辑 ]

作者: 西营盘旧街坊   发布时间: 2014-03-17

One more classic program Tetris Written in GWbasic, 1980 IBM PC

作者: 西营盘旧街坊   发布时间: 2014-03-17

哈哈! 唔会脑退化啦, 对多些旧嘢

作者: 西营盘旧街坊   发布时间: 2014-03-17

https://www.youtube.com/watch?v=V65mtR08fH0&feature=youtu.be

作者: me888   发布时间: 2014-03-17

引用:原帖由 me888 於 2014-3-1 03:27 PM 发表
https://www.youtube.com/watch?v=V65mtR08fH0&feature=youtu.be

我相信这类短片的人其实都不是即时想到如何写,而是一早写好了,再在拍短片时把已写好的 code (分段)打上去。

作者: xianrenb   发布时间: 2014-03-17

C++ 无 Interpreter mode , 只有 Compiler mode. 作者只系 show off 啫

作者: me888   发布时间: 2014-03-17

just for fun, my 1000 digits find_pi
复制内容到剪贴板代码:import sys
from decimal import Decimal, getcontext

sys.setrecursionlimit(5000)
getcontext().prec = 1500

def find_pi(i, n):
while i<n:
return 1 + i / (Decimal(2.0) * i + 1) * find_pi(i + 1, n)
else:
return 0

print (str(find_pi(Decimal(1), Decimal(3400))*2)[0:1002])

作者: form5   发布时间: 2014-03-17

后生仔高招!用了recursive function call. 好耐无写program, 记得当年写咗个用 recursive call 来显 file/folder explorer 当年系用 Delphi (Pascal) 写嘅

[ 本帖最后由 me888 於 2014-3-3 10:03 PM 使用 编辑 ]

作者: me888   发布时间: 2014-03-17

引用:原帖由 me888 於 2014-3-3 09:50 PM 发表
后生仔高招!用了recursive function call. 好耐无写program, 记得当年写咗个用 recursive call 来显 file/folder explorer 当年系用 Delphi (Pascal) 写嘅

today, people are still using the recursive function to get directory information internally, but adding an iterator outside, so that it looks like a iterative function.

the following C# code is from "mono" library, "Directory.cs"
复制内容到剪贴板代码: ...
public static string [] GetDirectories (string path, string searchPattern, SearchOption searchOption)
{
if (searchOption == SearchOption.TopDirectoryOnly)
return GetDirectories (path, searchPattern);
var all = new List<string> ();
GetDirectoriesRecurse (path, searchPattern, all);
return all.ToArray ();
}

static void GetDirectoriesRecurse (string path, string searchPattern, List<string> all)
{
all.AddRange (GetDirectories (path, searchPattern));
foreach (string dir in GetDirectories (path))
GetDirectoriesRecurse (dir, searchPattern, all);
}
...

作者: form5   发布时间: 2014-03-17

Google 一下,找到了计算 Pi 这类数值可用 Spigot algorithm :
http://en.wikipedia.org/wiki/Spigot_algorithm
http://www.mathpropress.com/stan/bibliography/spigot.pdf

在以下网页找到好多种电脑语言产生 Pi 数值的方法:
http://rosettacode.org/wiki/Pi

作者: xianrenb   发布时间: 2014-03-17

very good

作者: me888   发布时间: 2014-03-17