GithubHelp home page GithubHelp logo

franciscollobet / sudoku-solver Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 114 KB

Simple Sudoku Solver Engine

License: MIT License

CMake 1.98% C++ 43.69% C 51.48% Python 1.31% Gherkin 1.54%
sudoku sudoku-solver behave gherking

sudoku-solver's Introduction

Sudoku Solver

CMake

A C++ library for solving Sudoku puzzles using a pruning and backtracking algorithm.

Features

  • C++ library for solving Sudoku puzzles
  • Efficient pruning and backtracking algorithm
  • Public API methods for managing and solving Sudoku puzzles
  • Get statistics about the solving process (maximum recursion level, number of recursive calls)

Cloning the Repository

To clone the repository, use the following command:

git clone https://github.com/FranciscoLlobet/sudoku-solver.git

Example Usage

Following could be the content for your main.cc:

#include "sudoku.hh"

int main()
{
    std::string puzzle = "003020600900305001001806400008102900700000008006708200002609500800203009005010300";

    SudokuPuzzle sudoku(puzzle);

    if (sudoku.Solve() == SUDOKU_RC_SUCCESS)
    {
        sudoku.Print();
    }
    else
    {
        std::cout << "Failed to solve the Sudoku puzzle." << std::endl;
    }

    return 0;
}

This example initializes a SudokuPuzzle object with a given puzzle string, solves the puzzle, and prints the solved puzzle to the console.

How to Compile

Compile the library using clang:

clang++ -std=c++11 -o sudoku_solver main.cc sudoku.cc -I/path/to/headers

This command will compile the main.cc and sudoku.cc files, including the headers from the specified path, using the C++11 standard, and output the executable named sudoku_solver.

Public API Method Reference

@startuml
class SudokuPuzzle {
  -puzzle: SudokuPuzzle_P

  +operator=(other: const SudokuPuzzle&): SudokuPuzzle&
  +SudokuPuzzle(): void
  +SudokuPuzzle(p: const std::string&): void
  +SudokuPuzzle(other: const SudokuPuzzle&): void
  +~SudokuPuzzle(): void
  +InitializePuzzle(): Sudoku_RC_T
  +InitializePuzzle(p: const std::string&): Sudoku_RC_T
  +InitializePuzzle(p: const SudokuPuzzle&): Sudoku_RC_T
  +Print(): Sudoku_RC_T
  +SetValue(row: Sudoku_Row_Index_T, col: Sudoku_Column_Index_T, val: Sudoku_Values_T): SudokuPuzzle*
  +GetValue(row: Sudoku_Row_Index_T, col: Sudoku_Column_Index_T): Sudoku_Values_T
  +Solve(): Sudoku_RC_T
  +GetPuzzle(): std::string

  -SudokuPuzzle(p: SudokuPuzzle_P): void
  -InitializePuzzle(p: SudokuPuzzle_P): Sudoku_RC_T
  -InitializePuzzle(p: const SudokuPuzzle*): Sudoku_RC_T
  -SetValue(row: Sudoku_Row_Index_T, col: Sudoku_Column_Index_T, val: Sudoku_BitValues_T): SudokuPuzzle*
  -Solve(level: unsigned int): Sudoku_RC_T
}

@enduml

Here is an overview of the public methods provided by the SudokuPuzzle class:

  • SudokuPuzzle(): Default constructor that creates a blank Sudoku puzzle.
  • SudokuPuzzle(const std::string &p): Constructor that initializes a Sudoku puzzle with a given string.
  • SudokuPuzzle(SudokuPuzzle_P p): Constructor that initializes a Sudoku puzzle with a given pointer to a puzzle.
  • SudokuPuzzle(const SudokuPuzzle &p): Copy constructor.
  • operator=(const SudokuPuzzle &p): Assignment operator.
  • InitializePuzzle(): Initialize a blank Sudoku puzzle.
  • InitializePuzzle(const std::string &p): Initialize a Sudoku puzzle with a given string.
  • InitializePuzzle(SudokuPuzzle_P p): Initialize a Sudoku puzzle with a given pointer to a puzzle.
  • InitializePuzzle(const SudokuPuzzle *p): Initialize a Sudoku puzzle with a given pointer to a SudokuPuzzle object.
  • InitializePuzzle(const SudokuPuzzle &p): Initialize a Sudoku puzzle with a given reference to a SudokuPuzzle object.
  • Print(): Print the Sudoku puzzle.
  • SetValue(Sudoku_Row_Index_T row, Sudoku_Column_Index_T col, Sudoku_Values_T val): Set the value of a cell in the puzzle.
  • SetValue(Sudoku_Row_Index_T row, Sudoku_Column_Index_T col, Sudoku_BitValues_T val): Set the value of a cell in the puzzle using a bitmask.
  • GetValue(Sudoku_Row_Index_T row, Sudoku_Column_Index_T col): Get the value of a cell in the puzzle.
  • Solve(): Solve the Sudoku puzzle.

License

This project is licensed as indicated in the LICENSE file

sudoku-solver's People

Contributors

franciscollobet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.