Make a program to calculate pi to the n'th decimal. Input the variable at runtime. Program In the language of you choice. (and none of the print"3.1415" crap.)
series n = s / (2 * n + 1)
where s | even n = 1
| odd n = -1
pi-aproximations = map series [0.0..]
accurate nth (a,b) = abs (a - b) < 10 ^^ (-1 * nth)
pi nth = head (filter (accurate nth) (zip pi-aproximations (tail pi-aproximations)))
lol noone is smart enough to do it. good challenge
Name:
Anonymous2007-09-14 1:37 ID:Ieoi1S0b
(defun pi () (/ 22 7))
Nice challenge, lol.
Name:
Anonymous2007-09-14 2:17 ID:L/6D3QNO
#include <stdlib.h>
#include <stdio.h>
void ComputePi(int numdigits, char* pi)
{
int alength = 10 * numdigits / 3;
int* a = (int*) malloc(alength * sizeof(int));
int piLength = 0;
int nines = 0;
int predigit = 0;
int i, j;
for(i = 0; i < alength; ++i)
a[i] = 2;
for (j = 0; j < numdigits; ++j)
{
int q = 0;
int p = 2 * alength - 1;
for (i = alength; --i >= 0; )
{
int x = 10*a[i] + q*(i+1);
a[i] = x % p;
q = x / p;
p -= 2;
}
>>14
I remember an episode of "Jim'll Fix It" in the late 80s where a nerdy young girl wrote in asking him if he could fix it for her to calculate the value of Pi. So they brought her in the studio and had her calcuate 22/7 to about 50 decimal places. I lol'd.
You need to end your input with an EOF (usually ^D or ^Z, depends on your implementation and OS). Also, if your implementation is slow it can take a while.
>>39
your code in that link does not work
Error: value at [4] smaller than 0
I'm using my own implementation, i typed 3^D and i got 85714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714
etc etc, is that supposed to be the output of `3'?
Please mention if the memory can be looped (eg < is the last cell) and what value the cell has if EOF is read
My implementation allows < (or > in the end) and EOF = 0