ע ¼  
 ӹע
   ʾһ  |  ر
ܰʾ΢֤Ƶ΢ʺŰѹڣ°󶨣°΢  |  ر

G G I C C I

 
 
 
 
 

־

 
 

, Sudoku ( Javaʵ֣ )  

2012-08-07 16:53:38|  ࣺ |  ǩ |ٱ |ֺС 

  LOFTER ҵƬ  |

Title :


Java Source Code :

   1: import java.io.File;
   2: import java.io.FileWriter;
   3: import java.io.IOException;
   4: import java.util.Random;
   5: import java.util.Scanner;
   6: import java.util.Stack;
   7: import java.util.Vector;
   8:  
   9: /*
  10:     Author: Ggicci
  11:     Title: Solve Sudoku Problems with Backtracking Algorithm and Generate Sudoku using Probabilistic Algorithm
  12:     Date: 2012.08.07
  13: */
  14:  
  15: public class Sudoku {
  16:     private final int NORMS = 9; //ģ9 X 9
  17:     private final int MAX_SOLUTIONS = 10000; //⵽10000Ͳ
  18:     private int[][] sudoku = new int[NORMS][NORMS]; //ݵľ
  19:     private int[][] sudoku_copy = new int[NORMS][NORMS]; //һ㷨ʵеһ
  20:     private SudokuSolution solutions = new SudokuSolution(); //Ž
  21:     private int[][][] ctbl; //źѡֵľ
  22:     
  23:     //ö٣򵥡еȡϷ׳̶
  24:     public enum DifficultyLevel {
  25:         EASY, MEDIUM, HARD
  26:     } // end enumeration DifficultyLevel
  27:  
  28:     //һ
  29:     public void generateSudoku() {
  30:         while (!generate()) {
  31:  
  32:         }
  33:         SudokuSolution.copySudoku(sudoku, sudoku_copy);
  34:     } // end method generateSudoku
  35:     
  36:     //ɵȡʵһϷ
  37:     public void newSudokuGame(DifficultyLevel level) {
  38:         generateSudoku();
  39:         int nRemove = 0;
  40:         switch (level) {
  41:         case EASY:
  42:             nRemove = 30;
  43:             break;
  44:         case MEDIUM:
  45:             nRemove = 50;
  46:             break;
  47:         case HARD:
  48:             nRemove = 70;
  49:             break;
  50:         default:
  51:             break;
  52:         }
  53:         Random random = new Random();
  54:         for (int i = 0; i < nRemove; i++) {
  55:             int x = random.nextInt(NORMS);
  56:             int y = random.nextInt(NORMS);
  57:             sudoku[x][y] = sudoku_copy[x][y] = 0;
  58:         }
  59:         System.out.println("New game:");
  60:         printSudoku(false);
  61:         System.out.println();
  62:     } // end method newSudokuGame
  63:  
  64:     //û
  65:     public void inputSudokuGame() {
  66:         Scanner scanner = new Scanner(System.in);
  67:         for (int row = 0; row < NORMS; row++) {
  68:             for (int col = 0; col < NORMS; col++) {
  69:                 sudoku[row][col] = scanner.nextInt();
  70:                 sudoku_copy[row][col] = sudoku[row][col];
  71:             }
  72:         }
  73:         System.out.println("Your input:");
  74:         printSudoku(false);
  75:     } // end method inputSudoku
  76:     
  77:     //ӡ
  78:     public void printSudoku(boolean sparse) {
  79:         for (int row = 0; row < NORMS; row++) {
  80:             for (int col = 0; col < NORMS; col++) {
  81:                 if (sudoku[row][col] > 0 && sparse)
  82:                     System.out.printf(" *%d", sudoku[row][col]);
  83:                 else
  84:                     System.out.printf("%3d", sudoku[row][col]);
  85:             }
  86:             System.out.println();
  87:         }
  88:     }// end method printSudoku
  89:  
  90:     //txtļ
  91:     public void saveSudoku() {
  92:         String filename = "";
  93:         File file = null;
  94:         for (int i = 1; i < 100; i++) {
  95:             filename = "sudoku_" + i + ".txt";
  96:             file = new File(filename);
  97:             if (!file.exists()) {
  98:                 break;
  99:             }
 100:             file = null;
 101:         }// end for: look for a valid file name
 102:         try {
 103:             if (null == file)
 104:                 file = new File("tmp.txt");
 105:             FileWriter writer = new FileWriter(file);
 106:             for (int row = 0; row < NORMS; row++) {
 107:                 String s = new String();
 108:                 for (int col = 0; col < NORMS; col++) {
 109:                     s += String.valueOf(sudoku[row][col]);
 110:                     s += " ";
 111:                 }// end for: write a row of the sudoku board
 112:                 s += "\r\n";
 113:                 writer.write(s);
 114:             }// end for
 115:             writer.close();
 116:         } catch (IOException e) {
 117:             e.printStackTrace();
 118:         } finally {
 119:             System.out.printf("File [%s] created!", filename);
 120:         }// end try-catch-finally block
 121:     }// end method saveSudoku
 122:     
 123:     //
 124:     public int solveSudoku() {
 125:         solutions.clearSolutions();
 126:         int count = 0;
 127:         boolean unique;
 128:         ctbl = new int[NORMS][NORMS][10];
 129:         for (int col = 0; col < NORMS; col++) {
 130:             for (int row = 0; row < NORMS; row++) {
 131:                 if (0 == sudoku[row][col]) {
 132:                     getConstraint(col, row, ctbl[row][col], true);
 133: //                    printArray(ctbl[row][col], new String("constraints(" + row
 134: //                            + ", " + col + ") "));
 135:                     count++;
 136:                 }
 137:             }
 138:         }// end for: ʼеĺѡ
 139:         while (true) {
 140:             unique = false;
 141:             for (int col = 0; col < NORMS; col++) {
 142:                 for (int row = 0; row < NORMS; row++) {
 143:                     if (1 == constraintSize(ctbl[row][col])) {
 144:                         sudoku_copy[row][col] = ctbl[row][col][0]; //ͬsudoku_copy
 145:                         setCell(row, col, ctbl[row][col][0]);
 146:                         count--;
 147:                         unique = true;
 148:                     }// ֻһѡ־
 149:                 }// end for
 150:             }// end for
 151:             if (0 == count) {
 152:                 solutions.addSolution(sudoku);
 153:                 break;
 154:             }// еĸˣô˵һ⣬Ҳֻһ⣬ؾͿ
 155:             if (unique == false) {
 156:                 return multipleSolutions(count);
 157:             }// end if: ûݷ
 158:         }// end while
 159:         return 1;
 160:     }// end method solveSudoku
 161:  
 162:     //ӡĽ
 163:     public void printSudokuSolutions() {        
 164:         solutions.printSolutions();
 165:     } // end method printSudokuSolutions
 166:  
 167:     //һѭ
 168:     private boolean generate() {
 169:         int[] constraint = new int[10];
 170:         resetSudoku();
 171:         for (int col = 0; col < NORMS; col++) {
 172:             for (int row = 0; row < NORMS; row++) {
 173:                 getConstraint(col, row, constraint, false);
 174:                 if (0 == constraint[0]) {
 175:                     return false;
 176:                 }
 177:                 sudoku[row][col] = randomCandidate(constraint);
 178:             }// end for
 179:         }// end for
 180:         return true;
 181:     } // end method generate
 182:  
 183:     //ݷ
 184:     private int multipleSolutions(int count) {
 185:         //count Ǵĸӵ
 186:         Stack<Integer> s = new Stack<Integer>();
 187:         int results = 0; //õĽ
 188:         int reach = 0; //¼Ѿдĸ
 189:         int row = 0;
 190:         int col = 0;
 191:         int next = -1; //ѡе
 192: //        System.out.println("After first step resolving:");
 193: //        printSudoku(false);
 194: //        System.out.println();
 195: //        System.out.println("Copy:");
 196: //        printSudoku(sudoku_copy);
 197: //        System.out.println();
 198:         while (true) {
 199:             next = (-1 == next) ? 0 : next;
 200:             if (0 == sudoku[row][col]) {
 201:                 while (next >= constraintSize(ctbl[row][col])) {
 202:                     if (s.isEmpty() || results == MAX_SOLUTIONS) {
 203:                         return results;
 204:                     }
 205:                     //
 206:                     next = s.pop() + 1;
 207:                     do {
 208:                         row--;
 209:                         if (-1 == row) {
 210:                             row = NORMS - 1;
 211:                             col--;
 212:                         }
 213:                     } while (0 != sudoku_copy[row][col]);
 214:                     sudoku[row][col] = 0;
 215:                     //ºѡ
 216:                     updateAllConstraints();
 217:                     reach--;
 218:                 }
 219:                 setCell(row, col, ctbl[row][col][next]);
 220:                 reach++;
 221:                 s.push(next);
 222:                 next = -1;
 223:             } 
 224:             if (reach == count) {
 225:                 //һ
 226:                 results++;
 227:                 solutions.addSolution(sudoku);
 228:                 
 229:                 //
 230:                 next = s.pop() + 1;
 231:                 sudoku[row][col] = 0;
 232:                 reach--;
 233:                 //ºѡ
 234:                 updateAllConstraints();
 235:                 row--;
 236:             }
 237:             row++;
 238:             if (NORMS == row) {
 239:                 row = 0;
 240:                 col++;
 241:             }
 242:         } // end while
 243:     }// end method multipleSolutions
 244:  
 245:     // øsudoku[row][col]ѡ val, ֲºѡ֣ͬСͬСͬ飩
 246:     private void setCell(int row, int col, int val) {
 247:         sudoku[row][col] = val;
 248:         updateConstraints(row, col, val);
 249:     }// end method setCell
 250:  
 251:     //ȡsudoku[row][col]ĺѡִconstraint
 252:     private void getConstraint(int col, int row, int[] constraint,
 253:             boolean allIter) {
 254:         int[] cc = new int[10];
 255:         int[] cr = new int[10];
 256:         int[] cb = new int[10];
 257:         for (int i = 1; i <= NORMS; i++) {
 258:             cc[i] = cr[i] = cb[i] = i;
 259:             constraint[i] = 0;
 260:         }// reset constraints
 261:         constraint[0] = 0;
 262:  
 263:         int end_row = allIter ? NORMS : row;
 264:         int end_col = allIter ? NORMS : col;
 265:         for (int r = 0; r < end_row; r++) {
 266:             cc[sudoku[r][col]] = 0;
 267:         }// get column constraint
 268:         for (int c = 0; c < end_col; c++) {
 269:             cr[sudoku[row][c]] = 0;
 270:         }// get row constraint
 271:         int br = (row / 3) * 3;
 272:         int bc = (col / 3) * 3;
 273:         for (int c = bc; c < bc + 3; c++) {
 274:             for (int r = br; r < br + 3; r++) {
 275:                 cb[sudoku[r][c]] = 0;
 276:             }
 277:         }// get block constraint
 278:         int idx = 0;
 279:         int count;
 280:  
 281:         for (int i = 1; i <= NORMS; i++) {
 282:             count = 0;
 283:             for (int j = 1; j <= NORMS; j++) {
 284:                 count += (cc[j] == i ? 1 : 0);
 285:                 count += (cr[j] == i ? 1 : 0);
 286:                 count += (cb[j] == i ? 1 : 0);
 287:                 if (3 == count)
 288:                     break;
 289:             }
 290:             if (3 == count) {
 291:                 constraint[idx] = i;
 292:                 idx++;
 293:             }
 294:         }// end for(join constraints)
 295:  
 296:     }// end method getConstraint
 297:  
 298:     //еĸӵĺѡ
 299:     private void updateAllConstraints() {
 300:         for (int col = 0; col < NORMS; col++) {
 301:             for (int row = 0; row < NORMS; row++) {
 302:                 if (0 == sudoku[row][col]) {
 303:                     getConstraint(col, row, ctbl[row][col], true);
 304:                 }
 305:             }
 306:         }// end for
 307:     }// end method updateAllConstraints
 308:  
 309:     //sudoku[row][col]ĺѡ֣ȥval
 310:     private void updateConstraints(int row, int col, int val) {
 311:         int len;
 312:         boolean shouldMove;
 313:         for (int _col = 0; _col < NORMS; _col++) {
 314:             len = constraintSize(ctbl[row][_col]);
 315:             shouldMove = false;
 316:             for (int i = 0; i < len; i++) {
 317:                 if (false == shouldMove && ctbl[row][_col][i] == val) {
 318:                     ctbl[row][_col][i] = 0;
 319:                     shouldMove = true;
 320:                 }
 321:                 if (shouldMove) {
 322:                     ctbl[row][_col][i] = ctbl[row][_col][i + 1];
 323:                 }
 324:             }
 325:         }// cut out the value from the constraints of the cells in the same row
 326:         for (int _row = 0; _row < NORMS; _row++) {
 327:             len = constraintSize(ctbl[_row][col]);
 328:             shouldMove = false;
 329:             for (int i = 0; i < len; i++) {
 330:                 if (false == shouldMove && ctbl[_row][col][i] == val) {
 331:                     ctbl[_row][col][i] = 0;
 332:                     shouldMove = true;
 333:                 }
 334:                 if (shouldMove) {
 335:                     ctbl[_row][col][i] = ctbl[_row][col][i + 1];
 336:                 }
 337:             }
 338:         }// cut out the value from the constraints of the cells in the same
 339:             // column
 340:         for (int i = row / 3 * 3; i < row / 3 * 3 + 3; i++) {
 341:             for (int j = col / 3 * 3; j < col / 3 * 3 + 3; j++) {
 342:                 if (i != row && j != col) {
 343:                     len = constraintSize(ctbl[i][j]);
 344:                     shouldMove = false;
 345:                     for (int s = 0; s < len; s++) {
 346:                         if (false == shouldMove && ctbl[i][j][s] == val) {
 347:                             ctbl[i][j][s] = 0;
 348:                             shouldMove = true;
 349:                         }
 350:                         if (shouldMove) {
 351:                             ctbl[i][j][s] = ctbl[i][j][s + 1];
 352:                         }
 353:                     }
 354:                 }
 355:             }
 356:         }// cut out the value from the constraints of the cells in the same
 357:             // block
 358:     }// end method updateConstraints
 359:  
 360:     //Ӻѡconstraintлȡһĺѡ
 361:     private int randomCandidate(int[] constraint) {
 362:         int len = constraintSize(constraint);
 363:         Random r = new Random();
 364:         int result = r.nextInt(len);
 365:         return constraint[result];
 366:     }// end method randomCandidate
 367:  
 368:     //sudoku_copy
 369:     private void resetSudoku() {
 370:         for (int row = 0; row < NORMS; row++) {
 371:             for (int col = 0; col < NORMS; col++) {
 372:                 sudoku[row][col] = sudoku_copy[row][col];
 373:             }
 374:         }// end for
 375:     }// end method resetSudoku
 376:  
 377:     //ȡѡĴС
 378:     private int constraintSize(int[] constraint) {
 379:         int len = 0;
 380:         for (int i = 0; i < 10; i++) {
 381:             if (0 == constraint[i]) {
 382:                 len = i;
 383:                 break;
 384:             }
 385:         }// end for
 386:         return len;
 387:     }// end method constraintSize
 388:  
 389:     //ӡsudokuڵԵʱõ
 390:     private void printSudoku(int[][] sudoku) {
 391:  
 392:         for (int row = 0; row < NORMS; row++) {
 393:             for (int col = 0; col < NORMS; col++) {
 394:                 System.out.printf("%3d", sudoku[row][col]);
 395:             }// end for
 396:             System.out.println();
 397:         }// end for
 398:  
 399:     }
 400:  
 401:     //ӡһһά飬Եʱõ
 402:     private void printArray(int[] array, String description) {
 403:         System.out.print(description + ": ");
 404:         for (int i = 0; i < array.length; i++) {
 405:             System.out.print(array[i] + " ");
 406:         }
 407:         System.out.println();
 408:     }// end method printArray: for test, print a 1-d vector(array)
 409: }// end class test
 410:  
 411: //һʾĽ⣬ҪһVectorĽ
 412: class SudokuSolution {
 413:     private static final int NORMS = 9;
 414:  
 415:     class Node {
 416:         int[][] Sudoku = new int[NORMS][NORMS];
 417:  
 418:         Node(int[][] solution) {
 419:             copySudoku(solution, Sudoku);
 420:         }
 421:     }// end inner class Node
 422:  
 423:     Vector<Node> Solutions;
 424:  
 425:     SudokuSolution() {
 426:         Solutions = new Vector<Node>();
 427:     }
 428:  
 429:     void addSolution(int[][] solution) {
 430:         Node node = new Node(solution);
 431:         Solutions.add(node);
 432:     }
 433:  
 434:     void clearSolutions() {
 435:         Solutions.clear();
 436:     }
 437:  
 438:     //ӡеĽ
 439:     void printSolutions() {
 440:         int[][] solution;
 441:         for (int i = 0; i < Solutions.size(); i++) {
 442:             solution = Solutions.get(i).Sudoku;
 443:             System.out.println("Solution: " + (i + 1));
 444:             for (int row = 0; row < NORMS; row++) {
 445:                 for (int col = 0; col < NORMS; col++) {
 446:                     System.out.print(solution[row][col] + "  ");
 447:                 }
 448:                 System.out.println();
 449:             }// end for: print row by row
 450:         }// end for
 451:     }// end method printSolutions
 452:  
 453:     //һ̬Ŀ֮俽ݵķ
 454:     static void copySudoku(int[][] src, int[][] dest) {
 455:         for (int row = 0; row < NORMS; row++) {
 456:             for (int col = 0; col < NORMS; col++) {
 457:                 dest[row][col] = src[row][col];
 458:             }
 459:         }
 460:     }// end method copySudoku
 461: }// end inner class SodukuSolution: for storing the solutions of the board

Test :

   1: public class Sudoku_test {
   2:  
   3:     public static void main(String[] args) {
   4:         Sudoku sudoku = new Sudoku();
   5:         sudoku.newSudokuGame(Sudoku.DifficultyLevel.HARD);
   6:         
   7:         if(sudoku.solveSudoku() == 0) {
   8:             System.out.println("No solutions found!");
   9:         }
  10:         else {
  11:             sudoku.printSudokuSolutions();            
  12:         }
  13:     }// end main
  14: }

Result :

   1: New game:
   2:   0  7  0  0  8  0  0  2  3
   3:   9  0  0  0  0  0  4  0  8
   4:   0  8  3  0  0  0  5  9  0
   5:   0  1  0  0  3  0  0  5  6
   6:   0  9  0  0  5  0  2  0  0
   7:   3  0  0  0  0  9  0  8  0
   8:   7  2  0  0  0  8  0  0  0
   9:   1  0  0  2  7  6  0  0  9
  10:   8  0  0  3  9  5  0  0  0
  11:  
  12: Solution: 1
  13:   5  7  4  9  8  1  6  2  3
  14:   9  6  1  5  2  3  4  7  8
  15:   2  8  3  6  4  7  5  9  1
  16:   4  1  7  8  3  2  9  5  6
  17:   6  9  8  1  5  4  2  3  7
  18:   3  5  2  7  6  9  1  8  4
  19:   7  2  9  4  1  8  3  6  5
  20:   1  3  5  2  7  6  8  4  9
  21:   8  4  6  3  9  5  7  1  2
  22: Solution: 2
  23:   5  7  4  9  8  1  6  2  3
  24:   9  6  1  5  2  3  4  7  8
  25:   2  8  3  7  6  4  5  9  1
  26:   4  1  7  8  3  2  9  5  6
  27:   6  9  8  1  5  7  2  3  4
  28:   3  5  2  6  4  9  1  8  7
  29:   7  2  9  4  1  8  3  6  5
  30:   1  3  5  2  7  6  8  4  9
  31:   8  4  6  3  9  5  7  1  2
  32: Solution: 3
  33:   5  7  1  9  8  4  6  2  3
  34:   9  6  2  5  1  3  4  7  8
  35:   4  8  3  7  6  2  5  9  1
  36:   2  1  4  8  3  7  9  5  6
  37:   6  9  8  4  5  1  2  3  7
  38:   3  5  7  6  2  9  1  8  4
  39:   7  2  9  1  4  8  3  6  5
  40:   1  3  5  2  7  6  8  4  9
  41:   8  4  6  3  9  5  7  1  2
  42: Solution: 4
  43:   5  7  1  9  8  4  6  2  3
  44:   9  6  2  5  1  3  4  7  8
  45:   4  8  3  7  6  2  5  9  1
  46:   2  1  8  4  3  7  9  5  6
  47:   6  9  4  8  5  1  2  3  7
  48:   3  5  7  6  2  9  1  8  4
  49:   7  2  9  1  4  8  3  6  5
  50:   1  3  5  2  7  6  8  4  9
  51:   8  4  6  3  9  5  7  1  2
  52: Solution: 5
  53:   5  7  1  9  8  4  6  2  3
  54:   9  6  2  5  1  3  4  7  8
  55:   4  8  3  7  6  2  5  9  1
  56:   2  1  8  4  3  7  9  5  6
  57:   6  9  7  8  5  1  2  3  4
  58:   3  5  4  6  2  9  1  8  7
  59:   7  2  9  1  4  8  3  6  5
  60:   1  3  5  2  7  6  8  4  9
  61:   8  4  6  3  9  5  7  1  2
   1: New game:
   2:   7  6  1  8  0  4  9  0  0
   3:   3  0  0  0  0  0  1  2  4
   4:   0  5  2  0  0  0  0  7  8
   5:   0  0  0  6  0  0  0  4  0
   6:   0  0  9  1  0  0  7  0  0
   7:   0  0  0  9  0  0  0  0  2
   8:   0  0  0  2  0  0  0  5  6
   9:   0  3  6  4  9  0  2  0  0
  10:   0  2  0  0  6  0  4  9  0
  11:  
  12: Solution: 1
  13:   7  6  1  8  2  4  9  3  5
  14:   3  9  8  7  5  6  1  2  4
  15:   4  5  2  3  1  9  6  7  8
  16:   1  7  5  6  3  2  8  4  9
  17:   2  4  9  1  8  5  7  6  3
  18:   6  8  3  9  4  7  5  1  2
  19:   9  1  4  2  7  8  3  5  6
  20:   5  3  6  4  9  1  2  8  7
  21:   8  2  7  5  6  3  4  9  1
  22: Solution: 2
  23:   7  6  1  8  2  4  9  3  5
  24:   3  9  8  7  5  6  1  2  4
  25:   4  5  2  3  1  9  6  7  8
  26:   1  7  3  6  8  2  5  4  9
  27:   2  8  9  1  4  5  7  6  3
  28:   6  4  5  9  3  7  8  1  2
  29:   9  1  4  2  7  8  3  5  6
  30:   5  3  6  4  9  1  2  8  7
  31:   8  2  7  5  6  3  4  9  1
  32: Solution: 3
  33:   7  6  1  8  2  4  9  3  5
  34:   3  9  8  7  5  6  1  2  4
  35:   4  5  2  3  1  9  6  7  8
  36:   1  7  5  6  3  2  8  4  9
  37:   2  8  9  1  4  5  7  6  3
  38:   6  4  3  9  7  8  5  1  2
  39:   9  1  4  2  8  7  3  5  6
  40:   5  3  6  4  9  1  2  8  7
  41:   8  2  7  5  6  3  4  9  1
  42: Solution: 4
  43:   7  6  1  8  2  4  9  3  5
  44:   3  9  8  7  5  6  1  2  4
  45:   4  5  2  3  1  9  6  7  8
  46:   1  7  5  6  3  2  8  4  9
  47:   2  8  9  1  4  5  7  6  3
  48:   6  4  3  9  8  7  5  1  2
  49:   9  1  4  2  7  8  3  5  6
  50:   5  3  6  4  9  1  2  8  7
  51:   8  2  7  5  6  3  4  9  1
  52: Solution: 5
  53:   7  6  1  8  2  4  9  3  5
  54:   3  9  8  5  7  6  1  2  4
  55:   4  5  2  3  1  9  6  7  8
  56:   2  1  3  6  5  7  8  4  9
  57:   5  8  9  1  4  2  7  6  3
  58:   6  4  7  9  3  8  5  1  2
  59:   9  7  4  2  8  1  3  5  6
  60:   1  3  6  4  9  5  2  8  7
  61:   8  2  5  7  6  3  4  9  1
  62: Solution: 6
  63:   7  6  1  8  2  4  9  3  5
  64:   3  9  8  5  7  6  1  2  4
  65:   4  5  2  3  1  9  6  7  8
  66:   2  1  7  6  3  8  5  4  9
  67:   5  8  9  1  4  2  7  6  3
  68:   6  4  3  9  5  7  8  1  2
  69:   9  7  4  2  8  1  3  5  6
  70:   1  3  6  4  9  5  2  8  7
  71:   8  2  5  7  6  3  4  9  1
  72: Solution: 7
  73:   7  6  1  8  2  4  9  3  5
  74:   3  9  8  5  7  6  1  2  4
  75:   4  5  2  3  1  9  6  7  8
  76:   2  1  3  6  5  7  8  4  9
  77:   5  8  9  1  4  2  7  6  3
  78:   6  7  4  9  3  8  5  1  2
  79:   9  4  7  2  8  1  3  5  6
  80:   1  3  6  4  9  5  2  8  7
  81:   8  2  5  7  6  3  4  9  1
  82: Solution: 8
  83:   7  6  1  8  2  4  9  3  5
  84:   3  9  8  5  7  6  1  2  4
  85:   4  5  2  3  1  9  6  7  8
  86:   5  1  7  6  3  2  8  4  9
  87:   2  4  9  1  5  8  7  6  3
  88:   6  8  3  9  4  7  5  1  2
  89:   9  7  4  2  8  1  3  5  6
  90:   1  3  6  4  9  5  2  8  7
  91:   8  2  5  7  6  3  4  9  1
   1: New game:
   2:   2  0  0  0  0  3  0  7  0
   3:   8  4  7  0  0  0  0  2  3
   4:   5  3  0  0  8  0  0  0  0
   5:   0  0  4  0  0  0  3  0  2
   6:   1  2  0  0  0  0  0  0  0
   7:   3  8  6  0  0  4  9  0  5
   8:   0  0  0  0  1  0  2  0  0
   9:   0  0  2  0  0  0  8  0  1
  10:   7  1  3  0  0  0  0  0  0
  11:  
  12: Solution: 1
  13:   2  6  9  1  4  3  5  7  8
  14:   8  4  7  5  6  9  1  2  3
  15:   5  3  1  2  8  7  4  6  9
  16:   9  7  4  6  5  1  3  8  2
  17:   1  2  5  9  3  8  7  4  6
  18:   3  8  6  7  2  4  9  1  5
  19:   4  5  8  3  1  6  2  9  7
  20:   6  9  2  4  7  5  8  3  1
  21:   7  1  3  8  9  2  6  5  4
  22: Solution: 2
  23:   2  6  9  1  4  3  5  7  8
  24:   8  4  7  5  6  9  1  2  3
  25:   5  3  1  2  8  7  6  4  9
  26:   9  7  4  6  5  1  3  8  2
  27:   1  2  5  9  3  8  7  6  4
  28:   3  8  6  7  2  4  9  1  5
  29:   4  5  8  3  1  6  2  9  7
  30:   6  9  2  4  7  5  8  3  1
  31:   7  1  3  8  9  2  4  5  6
  32: Solution: 3
  33:   2  6  9  1  4  3  5  7  8
  34:   8  4  7  5  9  6  1  2  3
  35:   5  3  1  2  8  7  6  9  4
  36:   9  7  4  6  5  1  3  8  2
  37:   1  2  5  9  3  8  7  4  6
  38:   3  8  6  7  2  4  9  1  5
  39:   4  5  8  3  1  9  2  6  7
  40:   6  9  2  4  7  5  8  3  1
  41:   7  1  3  8  6  2  4  5  9
  42:  
  43: ...
  44:  
  45: Solution: 235
  46:   2  6  9  5  4  3  1  7  8
  47:   8  4  7  9  6  1  5  2  3
  48:   5  3  1  7  8  2  6  4  9
  49:   9  7  4  1  5  8  3  6  2
  50:   1  2  5  3  9  6  7  8  4
  51:   3  8  6  2  7  4  9  1  5
  52:   6  9  8  4  1  5  2  3  7
  53:   4  5  2  6  3  7  8  9  1
  54:   7  1  3  8  2  9  4  5  6
  55: Solution: 236
  56:   2  6  9  5  4  3  1  7  8
  57:   8  4  7  9  6  1  5  2  3
  58:   5  3  1  7  8  2  4  9  6
  59:   9  7  4  1  5  6  3  8  2
  60:   1  2  5  8  3  9  7  6  4
  61:   3  8  6  2  7  4  9  1  5
  62:   6  9  8  3  1  5  2  4  7
  63:   4  5  2  6  9  7  8  3  1
  64:   7  1  3  4  2  8  6  5  9
  65: Solution: 237
  66:   2  6  9  5  4  3  1  7  8
  67:   8  4  7  9  6  1  5  2  3
  68:   5  3  1  7  8  2  6  9  4
  69:   9  7  4  1  5  6  3  8  2
  70:   1  2  5  8  3  9  7  4  6
  71:   3  8  6  2  7  4  9  1  5
  72:   6  9  8  4  1  5  2  3  7
  73:   4  5  2  3  9  7  8  6  1
  74:   7  1  3  6  2  8  4  5  9

End :

Author : Ggicci

ллĶϣָ

ϴ:

Sudoku_Java.rar(4.28K)   
 
 
Ķ(738)| (0)
Ƽ

ʷϵĽ

<#--־Ⱥ־--> <#--Ƽ־--> <#--ü¼--> <#--Ƽ--> <#--Ķ--> <#--ҳƼ--> <#--ʷϵĽ--> <#--Ƽ־--> <#--һƪһƪ--> <#-- ȶ --> <#-- Ź --> <#--ұģṹ--> <#--ģṹ--> <#--ģṹ--> <#--ͶƱ-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

ҳ

ҵƬ - ͷ - ֻ - LOFTER APP - Ĵ˲

׹˾Ȩ ©1997-2017