OFFSET
0,4
LINKS
FORMULA
EXAMPLE
a(56) = 9, because 56 in binary is written 111000 giving the run lengths 3,3 and 3x3 = 9.
a(99) = 12, because 99 in binary is written 1100011 giving the run lengths 2,3,2, and 2x3x2 = 12.
MATHEMATICA
Table[ Times @@ (Length /@ Split[IntegerDigits[n, 2]]), {n, 0, 100}](* Olivier GĂ©rard, Jul 05 2013 *)
PROG
(Scheme)
(define (A167489 n) (apply * (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)))))))
;; Antti Karttunen, Jul 05 2013
(Haskell)
import Data.List (group)
a167489 = product . map length . group . a030308_row
-- Reinhard Zumkeller, Jul 05 2013
(Python)
def A167489(n):
'''Product of run lengths in binary representation of n.'''
p = 1
b = n%2
i = 0
while (n != 0):
n >>= 1
i += 1
if ((n%2) != b):
p *= i
i = 0
b = n%2
return(p)
# Antti Karttunen, Jul 24 2013 (Cf. Python program for A227184).
(PARI) a(n) = {my(p=1, b=n%2, i=0); while(n!=0, n=n>>1; i=i+1; if((n%2)!=b, p=p*i; i=0; b=n%2)); p} \\ Indranil Ghosh, Apr 17 2017, after the Python Program by Antti Karttunen
CROSSREFS
Cf. A167490 (smallest number with binary run length product = n).
KEYWORD
nonn,base
AUTHOR
Andrew Weimholt, Nov 05 2009
STATUS
approved