1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//! For checking how many steps a number takes to decrease.

use beetle_nonzero::NonZeroUnchecked;
use no_panic::no_panic;

use crate::{rules, Collatz};

/// Returns how many steps 'n' takes to decreaseb below its starting value
#[no_panic]
pub fn alpha<T: Collatz>(mut n: NonZeroUnchecked<T>) -> Option<u32> {
    let starting_value = n.value;

    let mut steps = 0;
    while n.value >= starting_value {
        n = rules::basic(n)?;
        steps += 1;
    }

    Some(steps)
}