Solve 96 using my Sudoku solver from college
This commit is contained in:
@@ -34,6 +34,40 @@ class Sudoku {
|
||||
System.out.println(fieldOut);
|
||||
}
|
||||
|
||||
int getThreeDigits() {
|
||||
int i = 0;
|
||||
i += fieldValues[2];
|
||||
i += fieldValues[1] * 10;
|
||||
i += fieldValues[0] * 100;
|
||||
return i;
|
||||
}
|
||||
|
||||
void loadFieldFromScanner(Scanner s) throws Exception {
|
||||
int currentField = 0;
|
||||
|
||||
if (!s.hasNextLine()) {
|
||||
throw new Exception("No lines to read");
|
||||
}
|
||||
|
||||
if (!s.nextLine().startsWith("Grid")) {
|
||||
throw new Exception("Not at start of grid");
|
||||
}
|
||||
|
||||
while (s.hasNextLine()) {
|
||||
String line = s.nextLine();
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
int v = line.charAt(i) - (int) '0';
|
||||
fieldValues[currentField] = v;
|
||||
currentField += 1;
|
||||
}
|
||||
if (currentField == 81) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** Function asks for an file name which
|
||||
* should contain a sudoku and this sudoku
|
||||
* into fieldValues, Empty fields should
|
||||
@@ -131,20 +165,5 @@ class Sudoku {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** This class is to test the
|
||||
* Sudoku class and it's functions
|
||||
*/
|
||||
class SudokuDemo {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Sudoku demo loading...");
|
||||
Sudoku s = new Sudoku();
|
||||
s.loadFieldFromFile();
|
||||
s.printField();
|
||||
//s.testAllowed();
|
||||
s.solveSudoku();
|
||||
s.printField();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user