Print the n-th digit of pi Task

Given an input n, calculate the n-th decimal digit of pi

Rules


Answer can be a full program or a function.
Input must be taken from stdin or from function arguments.
Output must be either sent to stdout, the return value of a function, or written to a file.
all n values between 0 and 20000 must be supported (can be between 1 and 20001 for 1-indexed languages).
Built-ins to calculate pi cannot be used. This includes pi constants (e.g. math.pi in Python) and built-in functions that return either the value of pi, or the n-th digit of pi. This means that an algorithm which calculates pi, or the n-th digit of pi must be implemented in your answer.
Digits must be calculated at runtime.


First digit (0-th or 1-th, depending on the language) is 3.

This is code-golf, so shortest code in bytes wins.

EDIT:

This is not a duplicate of 'Find the n-th decimal of pi', since that challenge allowed built-ins. This one is focused around actually implementing an algorithm to find the digits, rather than relying on built-ins.
Python 2, 182 65 bytes



a=p=2*10**20004
i=3
while a:a=i/2*a/i;p+=a;i+=2
print`p`[input()]


repl.it

Uses the Leibniz formula to calculate 20000 correct digits (plus a handful to allow the algorithm to maintain accuracy) then prints the requested digit.



Previous (182):
"The Spigot Algorithm For Pi" of Stanley Rabinowitz and Stan Wagon has the added bonus that it will work for any n when implemented as a generator

p=lambda n,r=3,a=0,b=1,c=1,d=1,e=3,f=3,i=0:i&gt;n and r or p(n,e,*[((2*b+a)*f,b*d,c*f,d+1,(b*(7*d)+2+(a*f))/(c*f),f+2,i),(10*(a-e*c),10*b,c,d,((10*(3*b+a))/c)-10*e,f,i+1)][4*b+a-c&lt;e*c])


repl.it Reaches Python's default recursion limit for the 117th digit.

Here is a non-recursive version for 198 bytes:

def p(n):
 a=i=0;b=c=d=1;e=f=3
 while i&lt;=n:
     r=e
     if 4*b+a-c&lt;e*c:g=10*(a-e*c);e=((10*(3*b+a))/c)-10*e;b*=10;i+=1
     else:g=(2*b+a)*f;h=(b*(7*d)+2+(a*f))/(c*f);b*=d;c*=f;f+=2;d+=1;e=h
     a=g
 print r


repl.it

(first indent space, second indent tab), the digits could, of course, be generated by yielding e at the start of the if clause instead of tracking the last digit with r.