integer_complexity
This module contains functions for computing the complexity of an integer, and a corrisponding mathematical expression that uses only ones, addition, and multiplication to reach that integer.
Types
A cache used to store already-computed integer complexities. See: integer_complexity.new_cache()
.
pub opaque type ComplexitiesCache
Functions
pub fn get_complexities_up_to(
cache: ComplexitiesCache,
integer: Int,
) -> Result(#(ComplexitiesCache, List(Int)), Nil)
Returns a list of integer complexities from 1 up to the specified integer.
Returns Error(Nil)
if the specified integer is less than 1.
pub fn get_complexity(
cache cache: ComplexitiesCache,
of integer: Int,
) -> #(ComplexitiesCache, Int)
Returns the integer complexity of the (absoulte value of the) specified integer.
pub fn get_expression(
cache cache: ComplexitiesCache,
of integer: Int,
) -> Result(#(ComplexitiesCache, Expression), Nil)
Returns a valid expression following the rules of integer complexity of the (absoulte value of the) specified integer.
Note that there can be multiple valid expressions for an integer, but this function only
generates a single expression.
Returns Error(Nil)
if the specified integer is 0
.
pub fn get_expressions_up_to(
cache: ComplexitiesCache,
integer: Int,
) -> Result(#(ComplexitiesCache, List(Expression)), Nil)
Returns a list of integer complexity expressins (one per integer) from 1 up to the specified integer.
Returns Error(Nil)
if the specified integer is less than 1.