Consider the digital expansion of this duodecimal fraction:
(4)12
--------
(19)12
Determine the (419)
12th duodecimal digit to the right of the duodecimal point.
My result confirms Charlie's solution. The desired digit is 5.
The base 12 result is 0.2(35186A), with the part in parentheses repeating every 6.
My routine made a list with the first element being a 0, which as it happens works out nicely in Python, since the list indices are zero based.
to print out the first 19 duodecimal places, I need "places" to be one more than 19:
div12(4,19,12,20)
returns:
[0, 2, 3, 5, 1, 8, 6, 10, 3, 5, 1, 8, 6, 10, 3, 5, 1, 8, 6, 10]
def div12(x,y,base,places):
""" Divide x by y where both are in base "base", out to n_places places
with the result showing in base base. Make output a list and use 'digits'
such as 10, 11, 12 etc instead of A, B, C
Have x be less than y, so that there is nothing before the 'decimal' point """
num = base2base(x,base,10)
den = base2base(y,base,10)
ans = []
divd = num
for i in range(places):
digit = divd//den
remain = divd%den
ans.append(digit)
divd = (remain)*12
return ans
x = base2base(419,12,10) # which evaluates to 597
answerList = div12(4,19,12,x+1)
print(answerList[x])
prints out:
5
|
Posted by Larry
on 2023-03-11 10:09:14 |