1.0.0 • Published 4 years ago

sudoku-api v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

sudoku-api

A Sudoku Web API that allows you to generate, validate and solve a 9x9 Sudoku grid.

npm i sudoku-api
npm start

View API documentation

What can this API do

  1. Generate random valid Sudoku puzzles
  2. Solve a Sudoku puzzle
  3. Check a Sudoku puzzle to see if it's valid or not

Getting Started

Using the npm repository

  1. npm i sudoku-api
  2. npm start
  3. Navigate to http:\\localhost\api\sudoku\generate to generate a new Sudoku puzzle
  4. For more info, view the API documentation

Clone from the GitHub repository

  1. Clone this project git clone https://github.com/wiseindy/sudoku-api
  2. If not already installed, install Node.js from https://nodejs.org/en/download/.
  3. Run npm install in the root of the project.
  4. Run npm run start
  5. Open your favorite browser and navigate to http://localhost:3000/api/sudoku/generate

Algorithm:

This application uses the backtracking algorithm to find a solution to the Sudoku puzzle. 1. Find an empty location in the grid 1.1 if no empty location is found, board is solved. 1.2. if empty location is found, continue to step 2 2. pick a number from the array (1 to 9) 3. loop through these numbers one by one 3.1. check if this number is valid in this empty location. 3.2. if yes, store this number in this position in the grid 3.2.1 RECURSION call this function again which repeats steps 1 to 3 until all locations are filled 3.3. if no, continue the loop and repeat steps 3.1 to 3.3 3.4. if no number is valid at this location, it's time to backtrack. 4. Backtrack to the previous position and find the next suitable number for that position. 5. Repeat steps 1 to 5 until board is solved or all combinations are exhausted.

Note:

The default port for the API is 3000. To change this port, set the PORT environment variable on your system before running npm run start.

Mac/Linux: export PORT=8000

Windows:

  • CMD: set PORT=8000
  • PowerShell: $env:PORT=8000
1.0.1

4 years ago

1.0.0

4 years ago