OFFSET
1,2
COMMENTS
Digitally balanced numbers correspond to A031443.
This sequence is a self-inverse permutation of the natural numbers.
LINKS
EXAMPLE
The first terms, alongside the binary representation of n + a(n), are:
n a(n) bin(n + a(n))
-- ---- -------------
1 1 10
2 7 1001
3 6 1001
4 5 1001
5 4 1001
6 3 1001
7 2 1001
8 27 100011
9 26 100011
10 25 100011
11 24 100011
12 23 100011
13 22 100011
PROG
(PARI) See Links section.
(Python)
def aupto(n):
alst, aset = [], set()
for k in range(1, n+1):
ak = 1
while True:
while ak in aset: ak += 1
binakplusk = bin(ak+k)[2:]
if binakplusk.count("0")==binakplusk.count("1"): break
ak += 1
alst.append(ak)
aset.add(ak)
return alst
print(aupto(66)) # Michael S. Branicky, Jan 02 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Jan 02 2021
STATUS
approved