Java code to generate sudoku puzzle

Amazing post from a dear friend 🙂

Coder's Caffeine

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:

  1. for each row: every number from 1 to 9 should occur exactly once
  2. for each column: every number from 1 to 9 should occur exactly once
  3. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s