OFFSET
1,2
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..45 (terms 1..25 from Michael S. Branicky, terms 26..35 from Chai Wah Wu)
EXAMPLE
a(2) = 1152 which in binary is 10010000000. Both representations contain exactly 2 1's. And there is no smaller number satisfying this constraint.
MATHEMATICA
Join[{1}, Table[t=0; While[!IntegerQ[k=Min@Flatten[Select[FromDigits/@Select[Permutations[#], First@#!=0&], Count[IntegerDigits[#, 2], 1]==n&]&/@(Join[Table[1, n], #]&/@Tuples[Join[{0}, Range[2, 9]], ++t])]]]; k, {n, 2, 12}]] (* Giorgos Kalogeropoulos, Jan 13 2022 *)
PROG
(Python)
numbers = [0, 2, 3, 4, 5, 6, 7, 8, 9]
terms = []
for ones in range(1, 13):
if ones == 3: # needs more than 2 digits differing from "1"
terms.append(131081)
else:
x = 1
min_solution = 999999999999999999
for i in range(ones+1):
x += 10 ** (i + 1)
for i in range(ones+2):
for j in numbers:
candidatej = x + (j - 1) * 10**i
for k in range(i+1, ones+2):
for l in numbers:
candidate = candidatej + (l - 1) * 10 ** k
if bin(candidate)[2:].count('1') == ones:
if candidate < min_solution:
min_solution = candidate
terms.append(min_solution)
(Python)
from itertools import count
def A350691_helper(n, m): # generator in order of numbers with n decimal digits and m 1's. Leading zeros are allowed.
if n >= m:
if n == 1:
if m == 1:
yield 1
else:
yield 0
yield from range(2, 10)
elif n == m:
yield (10**m-1)//9
else:
for b in A350691_helper(n-1, m):
yield b
r = 10**(n-1)
for b in A350691_helper(n-1, m-1):
yield r+b
for a in range(2, 10):
k = a*r
for b in A350691_helper(n-1, m):
yield k+b
def A350691(n):
for l in count(n):
r = 10**(l-1)
for a in range(1, 10):
n2 = n-1 if a == 1 else n
k = a*r
for s in A350691_helper(l-1, n2):
m = k+s
if bin(m)[2:].count('1') == n:
return m # Chai Wah Wu, Jan 13 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Ruediger Jehn, Jan 12 2022
EXTENSIONS
a(13)-a(18) from Michael S. Branicky, Jan 12 2022
STATUS
approved