login
Numbers whose sum of their decimal digits is less than or equal to the sum of the digits of their binary representation.
2

%I #28 Oct 11 2021 04:21:02

%S 0,1,10,11,20,21,30,31,100,101,102,103,110,111,120,121,122,123,200,

%T 201,202,203,210,211,220,221,222,223,230,231,300,301,302,303,310,311,

%U 410,411,500,501,502,503,510,511,1000,1001,1002,1003,1004,1005,1006,1007

%N Numbers whose sum of their decimal digits is less than or equal to the sum of the digits of their binary representation.

%H Alois P. Heinz, <a href="/A325483/b325483.txt">Table of n, a(n) for n = 1..10000</a>

%F { A037308 } union { A108580 }.

%p q:= n-> (f-> is(f(n, 10)<=f(n, 2)))((x, b)

%p -> add(i, i=convert(x, base, b))):

%p select(q, [$0..1500])[]; # _Alois P. Heinz_, Sep 06 2019

%t Select[Range[0,1007], Total[IntegerDigits[#]]<=Total[IntegerDigits[#,2]]&] (* _Metin Sariyar_, Sep 14 2019 *)

%o (Python)

%o x=0

%o #Adjust the inequality below to generate more numbers of the sequence

%o while(x<100):

%o x = x+1

%o Number = int(bin(x)[2:])

%o Bin_Sum = 0

%o while(Number > 0):

%o Reminder = Number % 10

%o Bin_Sum = Bin_Sum + Reminder

%o Number = Number //10

%o Number = x

%o Sum = 0

%o while(Number > 0):

%o Reminder = Number % 10

%o Sum = Sum + Reminder

%o Number = Number //10

%o if (Sum <= Bin_Sum):

%o print(x)

%o (Python)

%o def ok(n): return sum(map(int, str(n))) <= bin(n).count('1')

%o print(list(filter(ok, range(1008)))) # _Michael S. Branicky_, Oct 11 2021

%o (PARI) isok(n) = sumdigits(n, 10) <= sumdigits(n, 2); \\ _Michel Marcus_, Sep 07 2019

%Y Supersequence of A037308 and A108580.

%Y Cf. A000120, A007953.

%K nonn,base

%O 1,3

%A _Frederick John Bernet III_, Sep 06 2019