A340258 Lexicographically earliest sequence of distinct positive terms such that for any n > 0, n + a(n) is digitally balanced.
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, 9, 8, 28, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69
Offset: 1
Examples
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
Links
Programs
-
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
Comments