Amazing post from a dear friend ðŸ™‚

Hi, I am going to explain to you how to make a sudoku puzzle generator in java. The algorithm followed by me is taken from Sudoku Algorithm. Though I will be explaining the code in detail it would be better if you read and understand the algorithm from the above-mentioned site.

**Generating a valid:Â **For a 9Ã—9 grid to be a valid Sudoku grid, the following 3 requirements should be fulfilled:

- for each row: every number from 1 to 9 should occur exactly once
- for each column: every number from 1 to 9 should occur exactly once
- for each 3Ã—3 square with a thicker border (there are 9 of them): every number from 1 to 9 should occur exactly once.

` public static void generate() { int k=1,n=1; for(int i=0;i<9;i++) { k=n; for(int j=0;j<9;j++) { if(k<=9){ a[i][j]=k; k++; }else{ k=1; a[i][j]=k; k++; } } n=k+3; if(k==10) n=4; if(n>9) n=(n%9)+1â€¦`

View original post 537 more words

Advertisements