/calculator-game

A toy solver for 'Calculator: The Game' in Rust

Primary LanguageRust

Calculator: The Game Solver

This is a solver for Calculator: The Game, written as an exercise to learn Rust.

The object of the game is to reach a goal number from a given target number, using a limited number of operations. These include simple mathematical operations such as adding and subtracting constants, as well as reversing numbers and 'backspacing' (removing the least significant digit).

The solver itself is very simple. To find a solution, it runs a depth-first search from the starting number, to the depth specified in the problem definition. The state object holds the current value and (for simplicity when printing a solution) a list of previously applied operations. Successor states are generated by mapping the list of available operations over the current state.

The problem definition is specified in TOML:

start = 314
goal = 1138
moves = 1

# Implemented operations:
#   Add n
#   Subtract n
#   Multiply n
#   Divide n
#   Insert n (n becomes the most significant digit)
#   Replace n m
#   Exponent n
#   Negate
#   Backspace (removes the least significant digit)
ops = [
    { type = "[type]", ... arguments },
]

To run the solver:

$ cargo run problem_definition_file.toml