Code: Select all

```
10 P=1
20 FOR I=1 TO 5
30 P=P+SIN(P)
40 PRINT P
50 NEXT
>RUN
1.84147099
2.80506171
3.13527633
3.14159261
3.14159265
```

Now, it does use SIN, but as noted in the thread, that's not inherently using pi to calculate pi, and it might even be computationally efficient. Even better, the accuracy [*] doubles [+] at each step, and at each step you only need a suitably (in)accurate calculation of SIN.

Here's a much much slower one, and also very much more obscure:

Code: Select all

```
10 FOR K=1 TO 7
20 N%=10^K
30 S%=0
40 FOR I=1 TO N%
50 S%=S%+INT(RND(1)/RND(1)+.5)MOD2
60 NEXT
70 PRINT N%,1+4*S%/N%
80 NEXT
```

10000 iterations is as much as I'd like to run on a 2MHz 6502, and that only gives us a couple of digits of accuracy. I can run deeper on a faster platform, but it doesn't help accuracy much! Note that the actual results will differ from run to run.

Code: Select all

```
>RUN
10 2.2
100 3.2
1000 3.216
10000 3.164
100000 3.13984
1000000 3.139792
10000000 3.1409552
```

Calculating digits of Pi in Basic

Computing pi in a very unusual way

[*] Edit - oops, as noted below, I should have said number of digits, or bits

[+] Edit - oops, as noted below, it triples rather than doubles