
Here we have sizes of our Sudoku grid and boxes. this GRID_SIZE, not ConstantsKt.GRID_SIZE. Thanks to you can use any of the constants simply typing e.g. Internal const val GRID_SIZE_SQUARE_ROOT = 3 Let’s create a file Constants.kt with constants shared in the whole project, just to keep tidiness in our project. Now you have everything to start implementing the Sudoku generator algorithm. Source package (default: ):Īnd that’s it. Project name (default: sudoku-lib-kotlin): Starting a Gradle Daemon, 1 busy Daemon could not be reused, use -status for detailsĮnter selection (default: basic) 3Įnter selection (default: Kotlin) 2

Below is how you do it in terminal (assuming you already have the Gradle): $ mkdir sudoku-lib-kotlin

I encourage you to use Gradle’s Build Init plugin as a tool to produce our library. I will provide you a link at the end of the post. Remove digits from the random cells only if the puzzle is still solvable after each removal and repeat that until the desired number of digits remain on a grid.Įverything we are going to do next, is in my GitHub repository.Fill the rest of empty cells in non-diagonal boxes with digits from 1 to 9 while checking if each is not already used in box, row or column.Fill diagonal boxes with digits from 1 to 9.Every sudoku puzzle has only one correct solutionīefore we start, I will describe the algorithm that we will use to make the generator.Each row and column of the grid also has to contain exactly 9 distinct digits from 1 to 9.Each of 9 boxes has to contain exactly 9 distinct digits from 1 to 9.The purpose of the puzzle is to fill the rest of the cells with digits from 1 to 9 considering the following principles:.

The grid is filled partially with digits from 1 to 9.The grid is divided into 9 smaller 3x3 boxes, each containing 9 cells.A classic Sudoku puzzle, which is an object of my interest, is a grid of 81 cells, so it’s size is 9x9.For those who stayed with me here, I have a few pieces of information/rules you should get familiar with: Therefore, if you know them, you can go to the next paragraph without worries. I guess that the first thing I should do is explaining the rules of Sudoku.
