This is the first tutorial on Eniaksolution.com. Hope you enjoy it!

Today, we’re going to build a small algorithm to solve (almost) all sudoku tables… The algorithm is written in C, but it can easily be converted into any other language.

The algorithm is very simple and consists in three steps:

  1. We check any single cell.
  2. If free, we check the same cell’s row, column and “square”.
  3. If  there is only one number possible, we write it in the cell and start checking the table again.

Today we will prepare the first lines of code, we constants and function prototypes. We’ll soon implement the functions’ code… So :

/* Standard library inclusions */
#include 
#include

#define FALSE 0
#define TRUE 1
#define N 9 /* Sudoku table dimension */

/*
 Author : Alessandro Piana for Eniaksolution (http://www.eniaksolution.com)
 Versione : 0.1
 Description : you can freely distribute this code, but you can't be paid for it and you should keep
 copyright infos.
*/
/* FUNCTION PROTOTIPES. ANY FUNCTION WILL BE WELL DESCRIBED LATER. */
int get_row(int);
int get_column(int);
int get_index(int,int);
void check(int indice,int mat[][N], int arr_poss[]);
void check_row(int indice,int mat[][N], int arr_poss[]);
void check_column(int indice,int mat[][N], int arr_poss[]);
void check_square(int indice,int mat[][N], int arr_poss[]);
void insert_sudoku(int mat[][N]);
void print_sudoku(int mat[][N]);
void bufferize(int mat[][N]);

PLEASE BE CAREFUL! THE LAST LINE IS WRONG! IT HAS BEEN ADDED BY THE CODE VIEWER, BUT IT SHOULD NOT EXIST!

So, see you soon for the next part!

ap

PS : Post your impressions, suggestions and anything you like!!!

Comments are closed.