Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Jonathan Itschner
- import java.io.FileReader;
- import java.util.Scanner;
- public class Sudoku{
- static int puzzle [][] = new int [6][6];
- public static void main(String [] args) throws Exception{
- Scanner console = new Scanner(new FileReader("Puzzle.txt"));
- int puzzle2[][] = new int [6][6];
- int box[][] = new int [2][3];
- for (int i = 0; i < 6; i++){
- for (int j = 0; j < 6; j++){
- puzzle [i][j] = console.nextInt();
- }
- }//end of for
- for (int i = 0; i < 6; i++){
- for (int j = 0; j < 6; j++){
- puzzle2 [i][j] = puzzle[i][j];
- }
- }//end of for
- for (int i = 0; i<2; i++){
- for (int j = 0; j<3; j++){
- box [i][j] = puzzle [i][j];
- }
- }
- solveBox(box);
- //printArray(box);
- }//end of main
- public static int[][] solveBox(int box [][]){
- int [] choices = {1,2,3,4,5,6};
- //Determine which numbers are available to pick
- for (int i = 0; i <2; i++){
- for (int j = 0; j<3; j++){
- for(int r = 0; r < 6; r++){
- if (box[i][j] = choices[r])
- choices[r] = -1;
- }
- }
- }
- for (int i = 0; i <2; i++){
- for (int j = 0; j<3; j++){
- if(box[i][j] == 0){
- for(int q = 0; q<6; q++){
- if(choices[q] != -1){
- box[i][j] = choices[q];
- }
- }
- }
- }
- }
- for (int i = 0; i <2; i++){
- for (int j = 0; j<3; j++){
- System.out.print(" " + box[i][j]);
- }
- System.out.println();
- }
- for(int q = 0; q < 6; q++)
- System.out.print(" " + choices[q]);
- return box;
- }//end of solveBox
- /*
- public static boolean solveRow(int i, int j){
- boolean q = false;
- int p = 0;
- //Check to see if point is valid
- if (i<0 || i>5)
- return false;
- if (puzzle[i][j] != 0)
- return false;
- if (puzzle[i][j] == 0)
- return true;
- do
- {
- p++;
- switch(p)
- { case 1: q = solveRow(i+1, j);
- break;
- }
- //was move successful
- if (q) return true;
- System.out.println ("on return and not successful, i = " + i + " j = " + j);
- //try another move while there are still moves to make
- }while (!q && p < 4);
- return false;
- }//end of solveRow
- */
- public static void printArray(int array[][]){
- for (int i = 0; i < 6; i++){
- System.out.println();
- for (int j = 0; j <6; j++){
- System.out.print(array[i][j] + " ");
- }
- }
- System.out.println();
- }//end of printArray
- }//end of Sudoku
Add Comment
Please, Sign In to add comment