Check out this challenge:
https://www.hackerrank.com/codesprint4/challenges/leibniz
(The competition has already ended, so I'm just curious about the Python solution, which the organizers refused to reveal, so this is not cheating in any way.)
Modified from that page:
In Calculus, the Leibniz formula for \$\pi\$ is given by:
$$\sum_{n=0}^\infty \dfrac{\left(-1\right)^n}{2n+1}$$
You will be given an integer \$n\$. Your task is to print the summation of the Leibniz formula up to the \$n\$th term of the series correct to 15 decimal places.
That is given \$n\$ calculate:
$$\sum_{k=0}^n \dfrac{\left(-1\right)^k}{2k+1}$$
with the first 15 decimal places correct.
Input Format
The first line contains the number of test cases (\$T\$) which is less than 100. Each additional line is a test case for a positive integer value less than 10^7.
Output Format
Output \$T\$ lines each containing the calculated result for the corresponding line of the input.
Scoring
This is code-golf.
I only managed to solve the challenge in 77 characters. (Talking only about Python here.) However, one adr2370 managed to solve the challenge in 66 characters!
Please help me find the 66-character solution! I'm very very curious because I had to work really hard to bring mine down to 77, and I'm amazed as to how someone came up with a 66-character solution.
For reference, my solution:
for j in'x'*input():print'%.15f'%sum((-1)**i/(2.*i+1)for i in range(input()))