Skip to content

Instantly share code, notes, and snippets.

@davidawad
Created August 16, 2014 19:33
Show Gist options
  • Save davidawad/7cbc863b9f111321d0da to your computer and use it in GitHub Desktop.
Save davidawad/7cbc863b9f111321d0da to your computer and use it in GitHub Desktop.
Solutions for the Leibniz Challenge on Hackerrank
exec"print'%.15g'%sum((-1.)**i/(i-~i)for i in range(input()));"*input()
##python 2
from decimal import *
for x in range (0,int(input())):
s,n=Decimal('0'),int(input())
for i in range(0,n):
s+= Decimal(str(((-1)**i)/((2*i)+1)))
print (s)
##python 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment