login
Lexicographically earliest sequence of distinct positive terms such that for any n > 0, n + a(n) is digitally balanced.
1

%I #12 Jan 03 2021 09:53:54

%S 1,7,6,5,4,3,2,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,

%T 9,8,28,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,

%U 88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69

%N Lexicographically earliest sequence of distinct positive terms such that for any n > 0, n + a(n) is digitally balanced.

%C Digitally balanced numbers correspond to A031443.

%C This sequence is a self-inverse permutation of the natural numbers.

%H Rémy Sigrist, <a href="/A340258/b340258.txt">Table of n, a(n) for n = 1..10000</a>

%H Rémy Sigrist, <a href="/A340258/a340258.gp.txt">PARI program for A340258</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%e The first terms, alongside the binary representation of n + a(n), are:

%e n a(n) bin(n + a(n))

%e -- ---- -------------

%e 1 1 10

%e 2 7 1001

%e 3 6 1001

%e 4 5 1001

%e 5 4 1001

%e 6 3 1001

%e 7 2 1001

%e 8 27 100011

%e 9 26 100011

%e 10 25 100011

%e 11 24 100011

%e 12 23 100011

%e 13 22 100011

%o (PARI) See Links section.

%o (Python)

%o def aupto(n):

%o alst, aset = [], set()

%o for k in range(1, n+1):

%o ak = 1

%o while True:

%o while ak in aset: ak += 1

%o binakplusk = bin(ak+k)[2:]

%o if binakplusk.count("0")==binakplusk.count("1"): break

%o ak += 1

%o alst.append(ak)

%o aset.add(ak)

%o return alst

%o print(aupto(66)) # _Michael S. Branicky_, Jan 02 2021

%Y Cf. A031443, A306993 (multiplicative variant).

%K nonn,base

%O 1,2

%A _Rémy Sigrist_, Jan 02 2021