OFFSET
0,3
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..10000
EXAMPLE
a(0) = 0 (by definition), and 0 is also '0' in binary we consider it to contain a single run of length one.
For n = 1, we see that in a(0) there is one run of length 1, which is total number of runs of length 1 so far in terms a(0) .. a(n-1), thus a(1) = 1.
For n = 2, we see that the only and thus also the longest run of a(1) = 1 ('1' also in binary) has occurred two times in total (once in a(0) and a(1)), thus a(2) = 2.
For n = 3, we see that there are two runs in a(2) = 2 ('10' in binary), both one bit long, and so far there has occurred four such runs in total (namely once in a(0) and a(1), twice in a(2)), thus a(3) = 4.
For n = 4, we see that the longest run of a(3) = 4 ('100' in binary) is two bits long, and it is so far the first and only two-bit run in the sequence, thus a(4) = 1.
For n = 5, we see that the longest run of a(4) = 1 ('1' in binary) is one bit long, and so far there has occurred 6 such one-bit runs in terms a(0) .. a(4), thus a(5) = 6.
For n = 6, we see that the longest run of a(5) = 6 ('110' in binary) is two bits long, and so far there has occurred 2 such two bit runs (once in terms a(3) and a(5)), thus a(6) = 2.
PROG
(MIT/GNU Scheme with memoizing definec-macro from Antti Karttunen's IntSeq-library)
(definec (A249146 n) (if (< n 2) n (vector-ref (A249146aux_runlen_counts (- n 1)) (-1+ (A043276 (A249146 (- n 1)))))))
;; For binexp->runcount1list see for example A129594.
(definec (A249146aux_runlen_counts n) (cond ((zero? n) (vector 1)) (else (let* ((a_n (A249146 n)) (copy-of-prevec (vector-copy (A249146aux_runlen_counts (- n 1)))) (newsize (max (vector-length copy-of-prevec) (A043276 a_n))) (lencounts-for-n (vector-grow copy-of-prevec newsize))) (let loop ((runlens (binexp->runcount1list a_n))) (cond ((null? runlens) lencounts-for-n) (else (vector-set! lencounts-for-n (- (car runlens) 1) (+ 1 (or (vector-ref lencounts-for-n (- (car runlens) 1)) 0))) (loop (cdr runlens)))))))))
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Oct 22 2014
STATUS
approved