Up for the count def counting_series(n): The Champernowne word 12345678910111213 XXXXXXXXXX... is an infinitely long string of digits made up of all positive integers written in ascending order...


Up for the count


def counting_series(n):


The Champernowne word 1234567891011121314151617181920212223... is an infinitely long string of digits made up of all positive integers written in ascending order without any separators between the individual numbers. This function should return the integer digit that lies in the position n of the Champernowne word, position count again starting from zero as usual.
Of course, the automated tester will give your function values of n large enough that anybody trying to solve this problem by explicitly constructing the series as a string would run out of time and space long before receiving the answer. Instead, you should observe that the structure of this infinite sequence is quite straightforward, as it starts with 9 single-digit numbers, followed by 90 two-digit numbers, followed by 900 three-digit numbers, and so on. Such a predictably self-similar structure allows you to skip over prefixes of this series in exponentially widening leaps and bounds, until you reach the position n and find out the digit that is waiting for you there.

























nExpected result
01
1005
100007
10**1006


Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here