All Projects → vaithak → Sudoku Generator

vaithak / Sudoku Generator

Licence: mit
A Sudoku puzzle generator written in C++ using modified and efficient backtracking algorithm.

Programming Languages

cpp
1120 projects
cplusplus
227 projects

Projects that are alternatives of or similar to Sudoku Generator

Algodeck
An Open-Source Collection of 200+ Algorithmic Flash Cards to Help you Preparing your Algorithm & Data Structure Interview 💯
Stars: ✭ 4,441 (+13357.58%)
Mutual labels:  algorithm, algorithms, recursion
Competitive Programming
📌 📚 Solution of competitive programming problems, code templates, Data Structures and Algorithms, hackathons, interviews and much more.
Stars: ✭ 496 (+1403.03%)
Mutual labels:  algorithm, algorithms
Algos
Popular Algorithms and Data Structures implemented in popular languages
Stars: ✭ 966 (+2827.27%)
Mutual labels:  algorithm, algorithms
Get better at cp in 2 months
This contains the curriculum that I will follow to get better at Competitive Programming in 2 months.
Stars: ✭ 627 (+1800%)
Mutual labels:  algorithm, algorithms
Cracking The Coding Interview
📚 C++ and Python solutions with automated tests for Cracking the Coding Interview 6th Edition.
Stars: ✭ 396 (+1100%)
Mutual labels:  algorithms, recursion
Robotopia
🤖 Introducing kids to coding with tiny virtual robots!
Stars: ✭ 478 (+1348.48%)
Mutual labels:  algorithms, puzzle
Book on python algorithms and data structure
🪐 Book on Python, Algorithms, and Data Structures. 🪐
Stars: ✭ 604 (+1730.3%)
Mutual labels:  algorithm, algorithms
Proalgos Cpp
C++ implementations of well-known (and some rare) algorithms, while following good software development practices
Stars: ✭ 369 (+1018.18%)
Mutual labels:  algorithm, algorithms
Dsa.js Data Structures Algorithms Javascript
🥞Data Structures and Algorithms explained and implemented in JavaScript + eBook
Stars: ✭ 6,251 (+18842.42%)
Mutual labels:  algorithm, algorithms
Android Notes
Android开发核心知识点笔记(不断更新中🔥)
Stars: ✭ 737 (+2133.33%)
Mutual labels:  algorithm, algorithms
Algorithm
Algorithm is a library of tools that is used to create intelligent applications.
Stars: ✭ 787 (+2284.85%)
Mutual labels:  algorithm, algorithms
Competitive coding
This repository contains some useful codes, techniques, algorithms and problem solutions helpful in Competitive Coding.
Stars: ✭ 393 (+1090.91%)
Mutual labels:  algorithm, algorithms
Algo.js
A Very Basic into Intermediate Algorithm Lesson
Stars: ✭ 11 (-66.67%)
Mutual labels:  algorithm, algorithms
Algorithms
CLRS study. Codes are written with golang.
Stars: ✭ 482 (+1360.61%)
Mutual labels:  algorithm, algorithms
Algorithms
Minimal examples of data structures and algorithms in Python
Stars: ✭ 20,123 (+60878.79%)
Mutual labels:  algorithm, algorithms
Algorithms And Data Structures In Java
Algorithms and Data Structures in Java
Stars: ✭ 498 (+1409.09%)
Mutual labels:  algorithm, algorithms
Towel
Throw in the towel.
Stars: ✭ 333 (+909.09%)
Mutual labels:  algorithm, algorithms
Ojalgo
oj! Algorithms
Stars: ✭ 336 (+918.18%)
Mutual labels:  algorithm, algorithms
Meta Typing
📚 Functions and algorithms implemented purely with TypeScript's type system
Stars: ✭ 628 (+1803.03%)
Mutual labels:  algorithms, recursion
Avax
AVAX is a small, modern and fast console application for decrypting passwords with certain options.
Stars: ✭ 19 (-42.42%)
Mutual labels:  algorithm, algorithms

Sudoku-Generator

A Sudoku puzzle generator written in C++.

Steps to Use:-

Requirements:

-> git
-> Latest version C++ compiler , (this program has been tested on g++ only)

Linux and MacOS

Type the follwing commands on your terminal (without the '$')

$ git clone https://github.com/vaithak/Sudoku-Generator
$ cd Sudoku-Generator
$ bash setup.sh

Now restart the terminal and you are good to go

To run => enter $ sudokuGen from anywhere in the terminal
You can view the svg image generated in any Browser.

Example Puzzle generated from the program

image

FlowChart

image
image

Working of Step 1 and Step 6:

Step 1

 => Empty grid is solved using the normal backtracking method only, 
    but to make the seed different every time, we will not check numbers 
    1-9 sequentially at empty position.
    
 => Rather we will shuffle the list containing numbers 1-9 and fill cell according
    to it.
    
 => This ensures every time the program is run, the seed is different.

Step 6: Difficulty estimation

  
  Estimating the difficulty of a Sudoku puzzle is a tricky problem because of the
  variety of techniques human solvers use. 
  
  A quick and easy method that correlates roughly with difficulty is to keep track of the
  branch factor at each step on the path from the root of the search tree to the solution.

  We compute a branch-difficulty score by summing (B(i) - 1)^2 at each node, 
  where Bi are the branch factors. 
  
  A solution which requires no backtracking at all would thus have a branch-difficulty score of 0.

  The final score is given by:  S = B * 100 + E
  
  Where B is the branch-difficulty score and E is the number of empty cells. 
  E is included to bias the puzzle generator in the direction of fewer clues, 
  given multiple puzzles with the same branch-difficulty.

  A puzzle which requires no backtracking ends up with a final score of less than 100. 
  
  However, this naive approach does not correlate well with actual difficulty unless 
  a modification is made to the solver algorithm.

Modified Solver

  Rather than considering the possible values for a given empty cell, we could consider
  possible positions for a given missing value in one of the rows, columns or boxes.

  We make the following modification to the solver:

    1) Choose the cell with the fewest possible candidates. If no such cell can be found, the puzzle is solved.

    2) Search sets (rows, columns and boxes) for missing values, and count the positions they could occupy.
       Identify the set and value with the fewest number of possible positions.

    3) If the set-search result gives a number of positions which is smaller than the number of candidate values
       found in step 1, then continue with step 4. Otherwise, continue with step 5.

    4) Try filling the identified value in each candidate position in the set and recursively solve. 
       If all candidate positions are exhausted, signal failure to the caller.

    5) For each candidate value in the cell identified in step 1, place the value in the cell and 
       try to recursively solve the puzzle. If all candidate values are exhausted, signal failure.

  Essentially, the algorithm is the same, except that we try the set-oriented approach 
  if it results in a smaller branch factor. 
  This means that hidden singles or tuples yield similar branch factors to their naked equivalents.

  Making this modification often changes the results of difficulty estimations drastically. 

Reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].