# Calculate pi to 5 decimals [closed]

"Given that Pi can be estimated using the function $$\4 \times (1 - 1/3 + 1/5 - 1/7 + \cdots)\$$ with more terms giving greater accuracy, write a function that calculates Pi to an accuracy of 5 decimal places."

• Note, the estimation must be done by calculating the sequence given above.
• You should probably add some more rules, otherwise you will get answers like (python) p=lambda:3.14159
– Matt
Commented Aug 29, 2012 at 15:44
• Have you seen codegolf.stackexchange.com/questions/506/… , which is very similar? At the very least, trig functions should be banned for this problem because they allow for trivial solutions such as this QBASIC program: ?INT(4E5*ATN(1))/1E5 Commented Aug 29, 2012 at 17:30
• I think you should require that the algorithm be one of successive approximation: the longer you compute, the closer you get to pi. Commented Aug 29, 2012 at 22:59
• Dupe, but it's so old it's not here: stackoverflow.com/q/407518/12274
– J B
Commented Sep 1, 2012 at 21:42
• I’m voting to close this question because use of a specific algorithm is impossible to objectively validate Commented Jul 20, 2023 at 3:51

# CJam, 20 bytes

V4e5{4T2*)d/WT#*+}fT


Try it online!

One byte shorter than aditsu's answer. ;)

## Alternate 20-byter

4_e5,f{_2*)W@#*d/}:+


Try it online!

Does the same thing, but I like this better for some reason.