A343839 Semi-one numbers: Positive integers k such that exactly half of the integers 1..k have a 1 in their decimal expansion.
2, 16, 24, 160, 270, 272, 1456, 3398, 3418, 3420, 3422, 13120, 44686, 118096, 674934, 1062880
Offset: 1
Examples
16 is semi-1 because 1,10,11,12,13,14,15,16 have a 1 in them, there are 8 such numbers, and 8 is half of 16. 2 is semi-1 because 1 has a 1 in it and 2 does not.
Links
- Gary Gordon and Glen Whitney, The Playground, Math Horizons vol XXV issue 4, April 2018, Problem C21, semi-one numbers (and other semi-n).
Programs
-
Mathematica
s = {}; c = 0; Do[If[DigitCount[n, 10, 1] > 0, c++]; If[n == 2*c, AppendTo[s, n]], {n, 1, 1062880}]; s (* Amiram Eldar, May 01 2021 *) With[{nn=11*10^5},Select[Partition[Riffle[Range[nn],Accumulate[Table[If[DigitCount[n,10,1]>0,1,0],{n,nn}]]],2],#[[1]]==2#[[2]]&]][[;;,1]] (* Harvey P. Dale, Jun 23 2023 *)
-
PARI
lista(nn) = {my(va = vector(nn)); va[1] = 1; for (n=2, #va, va[n] = va[n-1] + (#select(x->(x==1), digits(n)) > 0);); for (n=1, nn, if (va[n] == n/2 , print1(n, ", ")););} \\ Michel Marcus, May 02 2021
-
Perl
for (1..10000000) { if (/1/) { $s++; } if ($_==2*$s) { print $_."\n"; } }
Comments