A125989 Sum of heights of 10's in binary expansion of n.
0, 0, 1, 0, 2, 0, 1, 0, 3, 1, 2, -1, 2, 0, 1, 0, 4, 2, 3, 0, 4, 0, 1, -2, 3, 1, 2, -1, 2, 0, 1, 0, 5, 3, 4, 1, 5, 1, 2, -1, 6, 2, 3, -2, 3, -1, 0, -3, 4, 2, 3, 0, 4, 0, 1, -2, 3, 1, 2, -1, 2, 0, 1, 0, 6, 4, 5, 2, 6, 2, 3, 0, 7, 3, 4, -1, 4, 0, 1, -2, 8, 4, 5, 0, 6, 0, 1, -4, 5, 1, 2, -3, 2, -2, -1
Offset: 0
Examples
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.
Programs
-
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))))))
Comments