cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A209640 Global ranking function for restricted totally balanced binary strings given in A209641.

Original entry on oeis.org

0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Offset: 0

Views

Author

Antti Karttunen, Mar 24 2012

Keywords

Comments

The given Scheme-program implements a ranking function for the terms of A209641, using Khayyam's triangle A007318.

Examples

			a(12)=3, as 12 occurs as the 3rd term (zero-based) in A209641.
a(14)=0, as 14 doesn't occur in A209641.
		

Crossrefs

This is an inverse function for A209641 in the sense that a(A209641(n)) = n for all n. The beginning of sequence coincides with A080300, because A209641 is a subsequence of A014486. Used to compute the permutation A209861.

Programs

  • Scheme
    (define (A209640 n) (if (or (zero? n) (not (member_of_A209641? n))) 0 (let* ((w (/ (binwidth n) 2))) (let loop ((rank 0) (row 1) (u (- w 1)) (n (- n (A053644 n))) (i (/ (A053644 n) 2)) (first_0_found? #f)) (cond ((or (zero? row) (zero? u) (zero? n)) (+ (expt 2 (-1+ w)) rank)) ((> i n) (loop rank (- row 1) u n (/ i 2) #t)) (else (loop (+ rank (if first_0_found? (A007318tr (- (+ row u) 1) (- row 1)) (A007318tr (- w 1) (- row 1)))) (+ row 1) (- u 1) (- n i) (/ i 2) first_0_found?)))))))
    (define (binwidth n) (let loop ((n n) (i 0)) (if (zero? n) i (loop (floor->exact (/ n 2)) (1+ i)))))