There are already 30 challenges dedicated to pi but not a single one asks you to find the nth decimal, so...
Challenge
For any integer in the range of 0 <= n <= 10000 display the nth decimal of pi.
Rules
- Decimals are every number after
3. - Your program may be a function, or a full program
- You must output the result in base 10
- You may get
nfrom any suitable input method (stdin, input(), function parameters, ...), but not hardcoded - You may use 1-based indexing if that's native to your language of choice
- You don't have to deal with invalid input (
n == -1,n == 'a'orn == 1.5) - Builtins are allowed, if they support up to at least 10k decimals
- Runtime doesn't matter, since this is about the shortest code and not the fastest code
- This is code-golf, shortest code in bytes wins
Test cases
f(0) == 1 f(1) == 4 // for 1-indexed languages f(1) == 1 f(2) == 1 // for 1-indexed languages f(2) == 4 f(3) == 5 f(10) == 8 f(100) == 8 f(599) == 2 f(760) == 4 f(1000) == 3 f(10000) == 5 For reference, here are the first 100k digits of pi.
str(pi())[n+2]\$\endgroup\$