Guest User

Untitled

a guest
Jun 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. //Jonathan Itschner
  2.  
  3. import java.io.FileReader;
  4. import java.util.Scanner;
  5.  
  6. public class Sudoku{
  7.   static int puzzle [][] = new int [6][6];
  8.  
  9.   public static void main(String [] args) throws Exception{
  10.     Scanner console = new Scanner(new FileReader("Puzzle.txt"));
  11.     int puzzle2[][] = new int [6][6];
  12.     int box[][] = new int [2][3];
  13.    
  14.     for (int i = 0; i < 6; i++){
  15.       for (int j = 0; j < 6; j++){
  16.         puzzle [i][j] = console.nextInt();
  17.       }
  18.     }//end of for
  19.    
  20.  
  21.     for (int i = 0; i < 6; i++){
  22.       for (int j = 0; j < 6; j++){
  23.         puzzle2 [i][j] = puzzle[i][j];
  24.       }
  25.     }//end of for
  26.    
  27.     for (int i = 0; i<2; i++){
  28.       for (int j = 0; j<3; j++){
  29.         box [i][j] = puzzle [i][j];
  30.       }
  31.     }
  32.    
  33.    
  34.    solveBox(box);    
  35.    //printArray(box);    
  36.    
  37.   }//end of main
  38.  
  39.  
  40.   public static int[][] solveBox(int box [][]){
  41.    
  42.     int [] choices = {1,2,3,4,5,6};
  43.    
  44.     //Determine which numbers are available to pick
  45.     for (int i = 0; i <2; i++){
  46.       for (int j = 0; j<3; j++){
  47.          for(int r = 0; r < 6; r++){
  48.             if (box[i][j] = choices[r])
  49.               choices[r] = -1;
  50.           }
  51.         }
  52.       }
  53.    
  54.     for (int i = 0; i <2; i++){
  55.       for (int j = 0; j<3; j++){
  56.         if(box[i][j] == 0){
  57.          
  58.           for(int q = 0; q<6; q++){
  59.             if(choices[q] != -1){
  60.               box[i][j] = choices[q];
  61.             }
  62.          
  63.           }          
  64.         }
  65.        
  66.       }
  67.     }
  68.  
  69.     for (int i = 0; i <2; i++){
  70.       for (int j = 0; j<3; j++){
  71.         System.out.print(" " + box[i][j]);      
  72.         }
  73.       System.out.println();
  74.       }
  75.    
  76.    for(int q = 0; q < 6; q++)
  77.       System.out.print(" " + choices[q]);
  78.      
  79.         return box;
  80.   }//end of solveBox
  81.  
  82.   /*
  83.   public static boolean solveRow(int i, int j){
  84.     boolean q = false;
  85.     int p = 0;
  86.    
  87.     //Check to see if point is valid
  88.     if (i<0 || i>5)
  89.       return false;
  90.     if (puzzle[i][j] != 0)
  91.       return false;
  92.     if (puzzle[i][j] == 0)
  93.       return true;
  94.    
  95.     do
  96.     {
  97.       p++;
  98.       switch(p)
  99.       { case 1: q = solveRow(i+1, j);
  100.         break;
  101.       }
  102.       //was move successful
  103.       if (q) return true;
  104.       System.out.println ("on return and not successful, i = " + i + " j = " + j);
  105.       //try another move while there are still moves to make
  106.     }while (!q && p < 4);
  107.    
  108.     return false;
  109.   }//end of solveRow
  110.  
  111.   */
  112.  
  113.  
  114.  
  115.  
  116.  
  117.     public static void printArray(int array[][]){
  118.  for (int i = 0; i < 6; i++){
  119.      System.out.println();
  120.      for (int j = 0; j <6; j++){
  121.   System.out.print(array[i][j] + " ");
  122.      }  
  123.  }
  124.  System.out.println();
  125.     }//end of printArray
  126.  
  127.  
  128. }//end of Sudoku
Add Comment
Please, Sign In to add comment