This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A340258 #12 Jan 03 2021 09:53:54 %S A340258 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 A340258 9,8,28,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89, %U A340258 88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69 %N A340258 Lexicographically earliest sequence of distinct positive terms such that for any n > 0, n + a(n) is digitally balanced. %C A340258 Digitally balanced numbers correspond to A031443. %C A340258 This sequence is a self-inverse permutation of the natural numbers. %H A340258 Rémy Sigrist, <a href="/A340258/b340258.txt">Table of n, a(n) for n = 1..10000</a> %H A340258 Rémy Sigrist, <a href="/A340258/a340258.gp.txt">PARI program for A340258</a> %H A340258 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a> %e A340258 The first terms, alongside the binary representation of n + a(n), are: %e A340258 n a(n) bin(n + a(n)) %e A340258 -- ---- ------------- %e A340258 1 1 10 %e A340258 2 7 1001 %e A340258 3 6 1001 %e A340258 4 5 1001 %e A340258 5 4 1001 %e A340258 6 3 1001 %e A340258 7 2 1001 %e A340258 8 27 100011 %e A340258 9 26 100011 %e A340258 10 25 100011 %e A340258 11 24 100011 %e A340258 12 23 100011 %e A340258 13 22 100011 %o A340258 (PARI) See Links section. %o A340258 (Python) %o A340258 def aupto(n): %o A340258 alst, aset = [], set() %o A340258 for k in range(1, n+1): %o A340258 ak = 1 %o A340258 while True: %o A340258 while ak in aset: ak += 1 %o A340258 binakplusk = bin(ak+k)[2:] %o A340258 if binakplusk.count("0")==binakplusk.count("1"): break %o A340258 ak += 1 %o A340258 alst.append(ak) %o A340258 aset.add(ak) %o A340258 return alst %o A340258 print(aupto(66)) # _Michael S. Branicky_, Jan 02 2021 %Y A340258 Cf. A031443, A306993 (multiplicative variant). %K A340258 nonn,base %O A340258 1,2 %A A340258 _Rémy Sigrist_, Jan 02 2021