OFFSET
0,3
LINKS
EXAMPLE
By definition a(0)=0 and a(1)=1.
a(2)=2, as 2 = 10 in binary, thus its run counts are (1 1), which reversed yields the same (1 1), from which we collect a binary number 10, i.e. 2 in decimal.
a(4)=6, as 4 = 100 in binary, thus its run counts are (1 2), which reversed and each element mapped through a itself yields (2 1), which are run counts of binary number 110, i.e. 6 in decimal.
a(16)=126, as 16 = 10000 in binary, thus its run counts are (1 4), which reversed yields (4 1) and a(4)=6 and a(1)=1, thus we find that the run counts (6 1) form a binary 1111110 i.e. 126 in decimal.
PROG
(Scheme): (define (A105726 n) (cond ((< n 2) n) (else (runcount1list->binexp (map A105726 (reverse! (binexp->runcount1list n))))))) (define (binexp->runcount1list n) (if (zero? n) (list) (let loop ((n n) (rc (list)) (count 0) (prev-bit (modulo n 2))) (if (zero? n) (cons count rc) (if (eq? (modulo n 2) prev-bit) (loop (floor->exact (/ n 2)) rc (1+ count) (modulo n 2)) (loop (floor->exact (/ n 2)) (cons count rc) 1 (modulo n 2))))))) (define (runcount1list->binexp lista) (let loop ((lista lista) (s 0) (state 1)) (cond ((null? lista) s) (else (loop (cdr lista) (+ (* s (expt 2 (car lista))) (* state (- (expt 2 (car lista)) 1))) (- 1 state))))))
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Antti Karttunen, Apr 18 2005
STATUS
approved