integer_complexity/expression

Types

A tree representing an expression.

pub type Expression {
  Add(lhs: Expression, rhs: Expression)
  Multiply(lhs: Expression, rhs: Expression)
  One
}

Constructors

  • Add(lhs: Expression, rhs: Expression)
  • Multiply(lhs: Expression, rhs: Expression)
  • One

Formatting options for expression.to_string

pub opaque type FormatOptions(
  padding_defined,
  add_defined,
  multiply_defined,
  left_paren_defined,
  right_paren_defined,
  digits_defined,
)

Functions

pub fn default_format_options() -> FormatOptions(a, b, c, d, e, f)

Returns preset formatting options for expression.to_string.

pub fn evaluate_expression(expression: Expression) -> Int

Evaluate an expression.

pub fn to_string(
  expression: Expression,
  options: FormatOptions(a, b, c, d, e, f),
) -> String

Convert an Expression to a string with the specified formatting options.

pub fn with_addition_sign(
  options: FormatOptions(a, AddSignNotDefined, b, c, d, e),
  sign: String,
) -> FormatOptions(a, AddSignDefined, b, c, d, e)

Specifies the string to use for the addition sign. default: "+"

pub fn with_digits(
  options: FormatOptions(a, b, c, d, e, DigitsNotDefined),
  digits: List(String),
) -> FormatOptions(a, b, c, d, e, DigitsDefined)

Specifies the digits to use. Digits must be ordered from least to greatest. The (Bijective) base that will be used will be the length of the array. default: ["1"]

pub fn with_left_bracket(
  options: FormatOptions(a, b, c, LeftBracketNotDefined, d, e),
  left_bracket: String,
) -> FormatOptions(a, b, c, LeftBracketDefined, d, e)

Specifies the string to use for the left bracket. default: "("

pub fn with_multiplication_sign(
  options: FormatOptions(a, b, MultiplySignNotDefined, c, d, e),
  sign: String,
) -> FormatOptions(a, b, MultiplySignDefined, c, d, e)

Specifies the string to use for the multiplication sign. default: "*"

pub fn with_padding(
  options: FormatOptions(PaddingNotDefined, a, b, c, d, e),
  padding: String,
) -> FormatOptions(PaddingDefined, a, b, c, d, e)

Specifies the string to use for padding (spaces). default: " "

pub fn with_right_bracket(
  options: FormatOptions(a, b, c, d, RightBracketNotDefined, e),
  right_bracket: String,
) -> FormatOptions(a, b, c, d, RightBracketDefined, e)

Specifies the string to use for the right bracket. default: ")"

Search Document