Skip to main content

collatz_next

Function collatz_next 

Source
pub const fn collatz_next(n: u64) -> Option<u64>
Expand description

Returns the next value in the Collatz trajectory for a positive integer.

Returns None when n == 0 or when the checked odd step 3 * n + 1 overflows u64.

ยงExamples

use use_collatz::collatz_next;

assert_eq!(collatz_next(1), Some(4));
assert_eq!(collatz_next(2), Some(1));
assert_eq!(collatz_next(3), Some(10));
assert_eq!(collatz_next(0), None);