Code Monkey home page Code Monkey logo

sudoku-generator's Introduction

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

sudoku-generator's People

Contributors

dudozermaks avatar vaithak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sudoku-generator's Issues

Unable to run on macOS

hello @vaithak this is really awesome, loved it . although i am unable to run it on macOS
returns the following error

sudokuGen
zsh: command not found: sudokuGen

this is what i have in my bash_profile

alias 'sudokuGen'='/Users/ashish/Sudoku-Generator/sudokuGen'

is it possible to create 12x12 & 16x16 sudokus may be also 4x4 & 6x6 ? to be honest i am trying to build a game based on this generator.
one more thing how can we define the sudoku difficulty ?

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.