Skip to content

A multithreaded cryptarithmetic/cryptarithm solver written completely in Rust. The solver reads an equation that has its digits represented by letters and computes the letters using a simple DFS.

Notifications You must be signed in to change notification settings

AKil47/cryptarithmetic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cryptarithmetic

A multithreaded tool written in Rust to solve Cryptarithmetic Problems.

Also known as Verbal Arithmetic or Cryptarithms, these are puzzles where mathematical equations have had their digits replaced with numbers. For example the equation SEND+MORE=MONEY can be rewritten as 9567 + 1085 = 10652. Notice how each letter represented a digit and that the same digit appears in every place where its corresponding letter was. Wikipedia Article: Verbal Arithmetic

The program takes the equation as a string input and generates every possible solution to the problem based on the variables given. It then allocates these possible solutions to a worker thread(s) that check if these solutions are in fact valid. This project was created to help me learn about Rust and its features.

Installation

The easiest way to use the program is to just clone the git repo. Afterwards, you can use cargo to build an executable.

git clone [Github URL]
cd cryptarithmetic
cargo build --release
cargo run --release

Library Usage

The main.rs file is a simple front end that makes use of the logic. At its core, the solver can be invoked by calling cryptarithmetic::solve_problems(input, thread_count) where input is a String and thread_count is a usize. The function will return an Option. If there are any solutions, they will be represented as a hashmap, connecting each letter to a value. Since there are multiple possibilities for a given problem, the solver will return a vector that contains each solution(s).

let input = String::from("ODD+ODD=EVEN");
let thread_count: usize = 5;

//Call the solver
use cryptarithmetic::solve_problems;
let answers = solve_problems(input, thread_count);

//Go through each answer and print it (if there are any)
match solve_problem(input, thread_count) {
    None => println!("No solution found"),
    Some(answers) => {
        for answer in answers {
            println!("{:?}", answer);
        }
    }
}

Contributing

Pull requests are always welcome! There is a brief todo list of things that I would like to implement.

This project was mainly created to help me understand all of Rust's features. Please do not add any new crates that do not come with the standard installation of Rust. For right now, I would only like to use what the standard library provides so that I can get a better grasp of the language.

To Dos:

  1. Add comments that integrate with rustdoc R
  2. Allow user to specify if they want output as dictionary (O: 8, D: 5, ...) or as filled equation (855+855) with flags or env vars
  3. Refactor code so that each function only achieves a single purpose. (This could mean creating other files)
  4. Add CLI input for number of threads
  5. Add unit tests
  6. Add support for other operations (^, !, %, etc.)

About

A multithreaded cryptarithmetic/cryptarithm solver written completely in Rust. The solver reads an equation that has its digits represented by letters and computes the letters using a simple DFS.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages