A small Rust program that finds solutions to 3×3 magic squares. It can solve a partially filled puzzle (with empty cells) or enumerate all valid 3×3 magic squares.
- Rust (stable) and Cargo installed
From the repository root:
cargo run -- [puzzle]If no [puzzle] is provided the program prints all valid 3×3 magic squares.
The program accepts a puzzle in one of these simple formats:
- A single 9-character string where
.0or_denote empty cells, e.g..23.7.... - Nine numbers separated by spaces, using
0for empty, e.g.0 2 3 4 0 6 7 8 0
The positions are row-major (left-to-right, top-to-bottom).
- Enumerate all valid 3×3 magic squares:
cargo run- Solve a partially filled puzzle:
cargo run -- ".23.7...."
# or
cargo run -- "0 2 3 4 0 6 7 8 0"The solver is implemented in src/main.rs. Key functions:
solve([u8; 9]) -> Vec<[u8; 9]>— returns all solutions for a given board (0 = empty).parse_arg_to_board(&str) -> Option<[u8; 9]>— parses CLI input formats.