Skip to content

duruyao/sudoku-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku Algorithm & Demo

64x64_sudoku_img.png

Directory

.
├── bin
│   └── demo
├── data
│   ├── 4x4_err.txt
│   ├── 4x4_mult.txt
│   ├── input.txt
│   └── output.txt
├── img
│   └── 64x64_sudoku_img.png
├── Makefile
├── obj
│   ├── demo.o
│   └── sudoku.o
├── README.md
├── run
└── src
    ├── demo.c
    ├── sudoku.c
    └── sudoku.h

Usage of Demo

$ ./run
Usage:
   ./run -g -n <Num> [-o <Outfile>]
               Generate Num x Num sudoku to Outfile

   ./run -s [-i <Infile>] [-o <Outfile>] [-m]
               Write solution of sudo from Infile to Outfile

Generate Sudoku

Generate Num x Num randomly ordered sudoku, and make sure that the Num is valid.

e.g. The input filename could be default.

$ ./run -g -n 4
Generate 4 x 4 sudoku to 'data/output.txt'
 1 2 | 4 3
 4 3 | 1 2
-----+-----
 2 1 | 3 4
 3 4 | 2 1

e.g. The input filename could be specified.

$ ./run -g -n 16 -o out.md
Generate 16 x 16 sudoku to 'out.md'
  7 14  3  2 | 11  9  5  1 | 15 10 16  4 |  8 12  6 13
 11  9  5  1 |  7 14  3  2 |  8 12  6 13 | 15 10 16  4
 15 10 16  4 |  8 12  6 13 |  7 14  3  2 | 11  9  5  1
  8 12  6 13 | 15 10 16  4 | 11  9  5  1 |  7 14  3  2
-------------+-------------+-------------+-------------
 14  7  2  3 |  9 11  1  5 | 10 15  4 16 | 12  8 13  6
  9 11  1  5 | 14  7  2  3 | 12  8 13  6 | 10 15  4 16
 10 15  4 16 | 12  8 13  6 | 14  7  2  3 |  9 11  1  5
 12  8 13  6 | 10 15  4 16 |  9 11  1  5 | 14  7  2  3
-------------+-------------+-------------+-------------
  3  2  7 14 |  5  1 11  9 | 16  4 15 10 |  6 13  8 12
  5  1 11  9 |  3  2  7 14 |  6 13  8 12 | 16  4 15 10
 16  4 15 10 |  6 13  8 12 |  3  2  7 14 |  5  1 11  9
  6 13  8 12 | 16  4 15 10 |  5  1 11  9 |  3  2  7 14
-------------+-------------+-------------+-------------
  2  3 14  7 |  1  5  9 11 |  4 16 10 15 | 13  6 12  8
  1  5  9 11 |  2  3 14  7 | 13  6 12  8 |  4 16 10 15
  4 16 10 15 | 13  6 12  8 |  2  3 14  7 |  1  5  9 11
 13  6 12  8 |  4 16 10 15 |  1  5  9 11 |  2  3 14  7

Solve Sudoku

Before solve Num x Num sudoku, make sure that your input data is in 'input file'.

After executing the command, the result of solving sudoku is in 'output file' if it is existed.

e.g. Find only one solution.

$ ./run -s
Read 9 x 9 sudoku from 'data/input.txt'
       |     4 |      
       |       |     4
     4 |       |      
-------+-------+-------
 5 2   |     7 | 8 9 1
 8 9 1 | 5 2   |     7
 4     | 8 9 1 | 5 2 3
-------+-------+-------
     2 |       | 9 3 5
 9 3 5 |     2 |      
       | 9 3 5 |     2

Try to find solution(s)
 1 5 6 | 2 7 4 | 3 8 9
 2 7 9 | 3 6 8 | 1 5 4
 3 8 4 | 1 5 9 | 2 7 6
-------+-------+-------
 5 2 3 | 6 4 7 | 8 9 1
 8 9 1 | 5 2 3 | 4 6 7
 4 6 7 | 8 9 1 | 5 2 3
-------+-------+-------
 7 1 2 | 4 8 6 | 9 3 5
 9 3 5 | 7 1 2 | 6 4 8
 6 4 8 | 9 3 5 | 7 1 2

Write 1 solution(s) to 'data/output.txt'

e.g. Find All the solution(s).

$ ./run -s -m -i data/4x4_mult.txt -o out.txt
Read 4 x 4 sudoku from 'data/4x4_mult.txt'
   2 |   4
   3 |    
-----+-----
     |    
     |    

Try to find solution(s)
 1 2 | 3 4
 4 3 | 1 2
-----+-----
 2 1 | 4 3
 3 4 | 2 1

 1 2 | 3 4
 4 3 | 1 2
-----+-----
 3 4 | 2 1
 2 1 | 4 3

 1 2 | 3 4
 4 3 | 2 1
-----+-----
 2 1 | 4 3
 3 4 | 1 2

 1 2 | 3 4
 4 3 | 2 1
-----+-----
 2 4 | 1 3
 3 1 | 4 2

 1 2 | 3 4
 4 3 | 2 1
-----+-----
 3 1 | 4 2
 2 4 | 1 3

 1 2 | 3 4
 4 3 | 2 1
-----+-----
 3 4 | 1 2
 2 1 | 4 3

Write 6 solution(s) to 'out.txt'

e.g. No nolution(s).

$ ./run -s -m -i data/4x4_err.txt -o out.txt
Read 4 x 4 sudoku from 'data/4x4_err.txt'
   2 | 1 4
     |   2
-----+-----
 4 1 | 3  
     |   1

Try to find solution(s)
No solution(s) found

Unfinished


About

Sudoku generator and solver coded by C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published