A257806 a(n) = A257808(n) - A257807(n).
0, -1, 0, 1, 0, 1, 2, 1, 2, 1, 2, 3, 2, 3, 4, 5, 6, 5, 4, 5, 6, 5, 6, 5, 4, 3, 4, 3, 4, 5, 4, 5, 6, 7, 6, 5, 6, 7, 6, 7, 8, 7, 6, 7, 8, 9, 10, 11, 12, 11, 12, 13, 12, 11, 10, 9, 10, 9, 10, 11, 10, 11, 12, 13, 12, 11, 12, 13, 12, 13, 12, 13, 14, 13, 12, 11, 10, 9, 10, 11, 12, 11, 10, 9, 10, 11, 12, 13, 14, 15, 14, 15, 16, 15, 16, 15, 14
Offset: 0
Examples
We consider 0 to have no nonleading zeros, so first we get to 0 -> 0+1+0 = 1, and 1 is odd, so we go one step down from the starting value a(0)=0, and thus a(1) = -1. 1 has no nonleading zeros, so we get 1 -> 1+1+0 = 2, and 2 is even, so we go one step up, and thus a(2) = 0. 2 has one nonleading zero in binary "10", so we get 2 -> 2+1+1 = 4, and 4 is also even, so we go one step up, and thus a(3) = 1. 4 has two nonleading zeros in binary "100", so we get 4 -> 4+2+1 = 7, 7 is odd, so we go one step down, and thus a(4) = 0.
Links
- Antti Karttunen, Table of n, a(n) for n = 0..8727
- Hans Havermann, Graph of 2*10^9 terms
- Hans Havermann, Detail graph of the eventual crossover to negative terms and a listing of its associated zeros
- Wikipedia, Blancmange curve
Crossrefs
Programs
-
PARI
A070939 = n->#binary(n)+!n; \\ From M. F. Hasler A080791 = n->if(n<1,0,(A070939(n)-hammingweight(n))); A233272 = n->(n + A080791(n) + 1); A257806_write_bfile(up_to_n) = { my(n,a_n=0,b_n=0); for(n=0, up_to_n, write("b257806.txt", n, " ", a_n); b_n = A233272(b_n); a_n += ((-1)^b_n)); }; A257806_write_bfile(8727);
-
Python
def A257806_print_upto(n): a = 0 b = 0 for n in range(n): print(b, end=", ") ta = a c0 = 0 while ta>0: c0 += 1-(ta&1) ta >>= 1 a += 1 + c0 b += ((2*(1-(a&1))) - 1) # By Antti Karttunen after Alex Ratushnyak's Python-code for A216431.
-
Scheme
(define (A257806 n) (- (A257808 n) (A257807 n)))
-
Scheme
;; Using memoizing definec-macro. (definec (A257806 n) (if (zero? n) n (+ (expt -1 (A233271 n)) (A257806 (- n 1)))))
Comments