Function malachite_base::num::iterators::ruler_sequence

source ·
pub const fn ruler_sequence<T: ExactFrom<u32>>() -> RulerSequence<T> 
Expand description

Returns the ruler sequence.

The ruler sequence (https://oeis.org/A007814) is the number of times that 2 divides the numbers $1, 2, 3, \ldots$.

$(x_i)_{i=1}^\infty = t_i$, where for each $i$, $i = (2k_i+1)2^{t_i}$ for some $k_i\in \mathbb{Z}$.

The $n$th term of this sequence is no greater than $\log_2(n + 1)$. Every number occurs infinitely many times, and any number’s first occurrence is after all smaller numbers have occured.

The output length is infinite.

§Complexity per iteration

Constant time and additional memory.

§Examples

use malachite_base::iterators::prefix_to_string;
use malachite_base::num::iterators::ruler_sequence;

assert_eq!(
    prefix_to_string(ruler_sequence::<u32>(), 20),
    "[0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4, 0, 1, 0, 2, ...]"
);