Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magic Squares (3x3) Solver

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.

Requirements

  • Rust (stable) and Cargo installed

Build & Run

From the repository root:

cargo run -- [puzzle]

If no [puzzle] is provided the program prints all valid 3×3 magic squares.

Input formats

The program accepts a puzzle in one of these simple formats:

  • A single 9-character string where . 0 or _ denote empty cells, e.g. .23.7....
  • Nine numbers separated by spaces, using 0 for empty, e.g. 0 2 3 4 0 6 7 8 0

The positions are row-major (left-to-right, top-to-bottom).

Examples

  • 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"

Program API

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.

About

Rust program that solves and enumerates 3×3 magic squares from partial inputs.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages