Sudoku module
@author: Vincent Magnin and Norwid Behrnd
This module contains a set of procedures to generate sudokus grids and solve them.
Returns true if the grid is full.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(9, 9) | :: | grid |
Sudoky grid. |
Validation routines
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(1:9) | :: | vector |
A row or a column |
Returns true if the row, column and region of a digit are all valid:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(9, 9) | :: | grid |
Sudoky grid. |
|
integer, | intent(in) | :: | row |
Row number of the region. |
||
integer, | intent(in) | :: | col |
Column number of the region. |
Check if the whole grid is valid.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(9, 9) | :: | grid |
Sudoku grid. |
Validation of a zone/region.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(1:3, 1:3) | :: | region |
Sudoku’s subregion |
Provides a solution for a puzzle passed by CLI:
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | dimension(9, 9) | :: | grid |
Sudoku Grid |
|
character(len=*), | intent(in) | :: | file |
Filepath |
Puzzle generators
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out), | dimension(9, 9) | :: | grid |
Sudoku grid |
Creates a puzzle by brute force. But we are not 100% sure that the solution is unique (just a “high” probability).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | dimension(9, 9) | :: | grid |
Sudoku grid. |
|
integer, | intent(in) | :: | givens |
Number of given digits in the puzzle. |
Creates a minimal puzzle. Digits are randomly removed one by one. The process ends when it is not possible anymore to remove a digit while keeping a unique solution. The number of remaining digits is therefore a priori unknown.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | dimension(9, 9) | :: | grid | ||
integer, | intent(out) | :: | nb_empty |
Display a grid on the terminal.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(9, 9) | :: | grid |
System independent initialization of pseudo-random generator
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | optional | :: | user_seed |
Procedure to create a list of allowed digits in the present empty cell.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(9, 9) | :: | grid |
Sudoku grid |
|
integer, | intent(in) | :: | row |
Row number |
||
integer, | intent(in) | :: | col |
Column number |
||
integer, | intent(out) | :: | nb_possible | |||
integer, | intent(out), | optional, | dimension(1:9) | :: | possible_digit |
Read a grid from a provided the path to a file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out), | dimension(9, 9) | :: | grid |
Output grid |
|
character(len=*), | intent(in) | :: | filename |
File path |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | dimension(9, 9) | :: | grid |
Input/Output routines
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | dimension(9, 9) | :: | grid | ||
character(len=*), | intent(in) | :: | filename |
Receives a puzzle grid and solves it.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | dimension(9, 9) | :: | grid |
Input problem grid and returns solved grid. |
Solver routines
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(inout), | dimension(1:81, 1:3) | :: | empty_cells | ||
integer, | intent(in) | :: | p |
The sort starts at position p (included) |
||
integer, | intent(in) | :: | n |
Number of empty cells in the list |