Task:
Your task is, when given three inputs:
- a numerator
n
- a denominator
d
- another integer,
x
Create a program/function that finds the x
th digit of the number after the decimal place.
Specs:
- The range of
n
andd
is between1
and2^31 - 1
, inclusive. - The range of
x
is between1
and10,000,000
, inclusive.- You may choose to use 1-based indexing or 0-based indexing for
x
. Please state in your answer which one you're using.
- You may choose to use 1-based indexing or 0-based indexing for
n
may be larger thand
.n
,d
andx
are guaranteed to be positive integers (for 1-based index version ofx
, if you choose to use 0-based indexing forx
thenx
can be0
).- You may take inputs in any reasonable way (I.e. any way that is not a standard loophole).
Rules:
- You must return the exact
x
th digit, not when rounded - so the15
th digit of1/6
, for example, is not7
, but6
. - Your program must work for all
x
under 10 million, unless your language doesn't support decimals to 10 million places.
Example I/O:
The example input uses 0-based indexing, which means x
will go from 0
to 9,999,999
. As well as that, the "input" is written as a string with spaces separating the numbers.
1 2 3: 0
5 6 0: 8
5 6 1: 3
1 6 15: 6 (not 7, as it's not rounded)
1 11 2: 0
1 10000 9999999: 0
11 7 1: 7