All the positive integers from 1 (base ten) to 2011 (base ten) are expressed alternately in base ten and base 12 and, written successively without commas and spaces resulting in this string.
123456789A1110131215141716.......11B4200911B62011
(I) Reading left to right, what is the 2011th digit in the above string?
(II) Reading right to left, what is the 2011th digit in the above string?
CLS
FOR i = 1 TO 2011
IF i MOD 2 = 1 THEN
newstr$ = LTRIM$(STR$(i))
ELSE
newstr$ = ""
n = i
WHILE n > 0
d = n MOD 12
newstr$ = MID$("0123456789AB", d + 1, 1) + newstr$
n = n \ 12
WEND
END IF
prevlen = totlen
totlen = totlen + LEN(newstr$)
IF totlen >= 2011 AND prevlen < 2011 THEN PRINT newstr$, 2011 - prevlen, i
NEXT
PRINT totlen
goal = totlen + 1 - 2011
PRINT goal
totlen = 0
FOR i = 1 TO 2011
IF i MOD 2 = 1 THEN
newstr$ = LTRIM$(STR$(i))
ELSE
newstr$ = ""
n = i
WHILE n > 0
d = n MOD 12
newstr$ = MID$("0123456789AB", d + 1, 1) + newstr$
n = n \ 12
WEND
END IF
prevlen = totlen
totlen = totlen + LEN(newstr$)
IF totlen >= goal AND prevlen < goal THEN PRINT newstr$, goal - prevlen, i
NEXT
PRINT totlen
finds
4B6 3 714
6550
4540
A32 1 1478
6550
which means:
I: The 2011th digit in the string is 6, as that is the third digit of 4B6, which is the base-12 representation of 714, which is where the 2011th digit happens to fall.
II: The total length of the string is 6550, decimal, and so the 2011th digit from the right is the 4540th digit from the left. Further, that is the first digit of A32, which is the base-12 representation of 1478. Thus A is the answer to part II.
|
Posted by Charlie
on 2011-06-19 13:53:26 |