Module beetle_collatz::rules

source ·
Expand description

Contains functions that apply the rules of the collatz conjecture in more performant ways

Functions

  • Applies the rules of the collatz conjecture to a number N, and returns the result. If N is ODD: returns 3n + 1, If N is EVEN: returns n / 2. All other functions in this module are faster than this one. Should only be used when benchmarking other functions in this module.
  • Returns n / 2. This should never panic in the contexts where it’s used.
  • Same as the basic function, except if N is odd, it also divides it by 2 before returning it. for use with the fall function Do not use if the precise number of steps needed to reach 1 is important.
  • Returns 3 * n + 1. If there is an overflow, this returns None.
  • In theory faster than halve_odds
  • same as rules::trailing_zeros, but we know for sure that N is EVEN
  • same as rules::trailing_zeros, but we know for sure that N is ODD.