login
Least number k such that half of the numbers from 0 to k inclusive contain the digit n.
2

%I #40 Jun 21 2021 03:17:34

%S 1,1,2915,39365,472391,590489,6377291,7440173,8503055,9565937

%N Least number k such that half of the numbers from 0 to k inclusive contain the digit n.

%C "Half-numbers" are those for which half of the numbers including and preceding it contain a specific digit.

%C For each digit there are a finite number of nonnegative integers k such that exactly half of the numbers from 0 to k contain the digit. This sequence gives the first of these.

%D Andrew Hilton, 101 Puzzles to Solve on your Microcomputer, 1984, HARRAP, page 57.

%F a(n) == 1457 (mod 1458) for n >= 2. - _Hugo Pfoertner_, May 25 2021

%e a(0)=1 since among the numbers 0,1 exactly half contain a digit "0" and 1 is the smallest number where this occurs.

%e a(1)=1 since among the numbers 0,1 exactly half contain a digit "1" and 1 is the smallest number where this occurs.

%e a(2)=2915 since among the numbers 0,1,2,...,2915 exactly half contain a digit "2" and 2915 is the smallest number where this occurs.

%e a(3)=39365 since among the numbers 0,1,2,...,39365 exactly half contain a digit "3" and 39365 is the smallest number where this occurs.

%o (Python 3)

%o for z in range (0, 10):

%o z_s = str(z)

%o counts=0

%o for x in range (0,1000000000):

%o x_s = str(x)

%o if z_s in x_s:

%o counts += 1

%o if counts / (x+1) == 0.5:

%o print(x)

%o break

%o (PARI) a(n)={if(n>=1&&n<10, my(k=0); while(n*(2*9^k-10^k)>10^k, k++); 2*9^k*n - 1, n==0)} \\ _Andrew Howroyd_, May 25 2021

%Y Cf. A016189, A344634 (half-zero sequence), A344636 (half-one sequence).

%K nonn,base,fini,full,easy

%O 0,3

%A _Glen Gilchrist_, May 20 2021