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. testing the products

Constants

pub const new_cache: fn(fn(Set(a, b)) -> c) -> c

Create a new cache used to store computed integer complexities.

Functions

pub fn get_complexities_up_to(
  cache: Set(Int, ComplexityData),
  integer: Int,
) -> Result(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: Set(Int, ComplexityData),
  of integer: Int,
) -> Int

Returns the integer complexity of the (absoulte value of the) specified integer.

pub fn get_expression(
  cache cache: Set(Int, ComplexityData),
  of integer: Int,
) -> Result(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: Set(Int, ComplexityData),
  integer: Int,
) -> Result(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.

Search Document