document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.company;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Random;
  5. public class Main {
  6.     private static Random Rnd = new Random();
  7.     private static Cell[][] Board = new Cell[9][9];
  8.     private static int[][][] Blks = new int[][][]
  9.             {{{0, 0}, {0, 1}, {0, 2}, {1, 0}, {1, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}},
  10.             {{0, 3}, {0, 4}, {0, 5}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}},
  11.             {{0, 6}, {0, 7}, {0, 8}, {1, 6}, {1, 7}, {1, 8}, {2, 6}, {2, 7}, {2, 8}},
  12.             {{3, 0}, {3, 1}, {3, 2}, {4, 0}, {4, 1}, {4, 2}, {5, 0}, {5, 1}, {5, 2}},
  13.             {{3, 3}, {3, 4}, {3, 5}, {4, 3}, {4, 4}, {4, 5}, {5, 3}, {5, 4}, {5, 5}},
  14.             {{3, 6}, {3, 7}, {3, 8}, {4, 6}, {4, 7}, {4, 8}, {5, 6}, {5, 7}, {5, 8}},
  15.             {{6, 0}, {6, 1}, {6, 2}, {7, 0}, {7, 1}, {7, 2}, {8, 0}, {8, 1}, {8, 2}},
  16.             {{6, 3}, {6, 4}, {6, 5}, {7, 3}, {7, 4}, {7, 5}, {8, 3}, {8, 4}, {8, 5}},
  17.             {{6, 6}, {6, 7}, {6, 8}, {7, 6}, {7, 7}, {7, 8}, {8, 6}, {8, 7}, {8, 8}}};
  18.     public static void main(String[] args) {
  19.         while (true) {
  20.             for (int x = 0; x < 9; x++) {
  21.                 for (int y = 0; y < 9; y++) {
  22.                     Board[x][y] = new Cell();
  23.                 }
  24.             }
  25.             List<Integer> ValidBlks = new ArrayList<Integer>();
  26.             for (int i =0; i < 9; i++) { ValidBlks.add(i); }
  27.             Boolean Retry = false;
  28.             do {
  29.                 List<Integer> ValidCells = new ArrayList<Integer>();
  30.                 for (int i =0; i < 9; i++) { ValidCells.add(i); }
  31.                 Integer B = ValidBlks.get(Rnd.nextInt(ValidBlks.size()));
  32.                 ValidBlks.remove(B);
  33.                 do {
  34.                     Integer C = ValidCells.get(Rnd.nextInt(ValidCells.size()));
  35.                     int X = Blks[B][C][0]; int Y = Blks[B][C][1];
  36.                     Integer R[] = Board[X][Y].Process(Rnd);
  37.                     if (R[0] == 1) {
  38.                         Retry = true;
  39.                         break;
  40.                     } else {
  41.                         ValidCells.remove(C);
  42.                         for (int i = 0; i < 9; i++) {
  43.                             Board[X][i].ValidNbrs.remove(R[1]); Board[i][Y].ValidNbrs.remove(R[1]);
  44.                             Board[Blks[B][i][0]][Blks[B][i][1]].ValidNbrs.remove(R[1]);
  45.                         }
  46.                     }
  47.                 } while (!(ValidCells.size() == 0));
  48.                 if (Retry) break;
  49.             } while (!(ValidBlks.size() == 0));
  50.             if (!(Retry)) break;
  51.         }
  52.         System.out.print("\\r\\n");
  53.         for (int x = 0; x < 3; x++) {
  54.             System.out.print(" ");
  55.             for (int y = 0; y < 3; y++) { System.out.print(Board[x][y].Value + " "); }
  56.             System.out.print(" ");
  57.             for (int y = 3; y < 6; y++) { System.out.print(Board[x][y].Value + " "); }
  58.             System.out.print(" ");
  59.             for (int y = 6; y < 9; y++) { System.out.print(Board[x][y].Value + " "); }
  60.             System.out.print("\\r\\n");
  61.         }
  62.         System.out.print("\\r\\n");
  63.         for (int x = 3; x < 6; x++) {
  64.             System.out.print(" ");
  65.             for (int y = 0; y < 3; y++) { System.out.print(Board[x][y].Value + " "); }
  66.             System.out.print(" ");
  67.             for (int y = 3; y < 6; y++) { System.out.print(Board[x][y].Value + " "); }
  68.             System.out.print(" ");
  69.             for (int y = 6; y < 9; y++) { System.out.print(Board[x][y].Value + " "); }
  70.             System.out.print("\\r\\n");
  71.         }
  72.         System.out.print("\\r\\n");
  73.         for (int x = 6; x < 9; x++) {
  74.             System.out.print(" ");
  75.             for (int y = 0; y < 3; y++) { System.out.print(Board[x][y].Value + " "); }
  76.             System.out.print(" ");
  77.             for (int y = 3; y < 6; y++) { System.out.print(Board[x][y].Value + " "); }
  78.             System.out.print(" ");
  79.             for (int y = 6; y < 9; y++) { System.out.print(Board[x][y].Value + " "); }
  80.             System.out.print("\\r\\n");
  81.         }
  82.     }
  83. }
  84. public class Cell {
  85.     public int Value = 0;
  86.     public List<Integer> ValidNbrs = new ArrayList<Integer>();
  87.     public Cell() { for (int i = 1; i < 10; i++) ValidNbrs.add(i); }
  88.     public Integer[] Process(Random Rnd) {
  89.         Integer[] R = new Integer[2];
  90.         if (ValidNbrs.size() == 0) {
  91.             R[0] = 1;
  92.             return R;
  93.         }
  94.         Value = ValidNbrs.get(Rnd.nextInt(ValidNbrs.size()));
  95.         R[0] = 0; R[1] = Value;
  96.         return R;
  97.     }
  98. }
');