OFFSET
0,5
COMMENTS
The 'height' of the digits in the binary expansion of n is here defined by the algorithm where, starting from the least significant bit and the height=0 and proceeding leftwards, all encountered 1-bits decrease the height by one and all 0-bits increase it by one. The sequence gives the sums of heights at the positions where 0 changes to 1 when scanning the binary expansion from right to left. This sequence is used for computing A126302.
EXAMPLE
E.g. the lattice path /\/\ is encoded by 10 as 1010 in binary and both peaks occur at height=1, thus a(10)=2.
In comparison, 11 is 1011 in binary, so the only peak '10' occurs at height -1:
.../
/\/
thus a(11)=-1.
PROG
(Scheme:) (define (A125989 n) (let loop ((n n) (s 0) (h 0)) (cond ((zero? n) s) ((= 2 (modulo n 4)) (loop (/ (- n 2) 4) (+ s h 1) h)) ((odd? n) (loop (/ (- n 1) 2) s (- h 1))) (else (loop (/ n 2) s (+ 1 h))))))
CROSSREFS
KEYWORD
sign,base
AUTHOR
Antti Karttunen, Jan 02 2007
STATUS
approved