mirror of https://github.com/01-edu/public.git
test: adding subject and main
This commit is contained in:
parent
a89a441036
commit
caaa46afe6
|
@ -0,0 +1,33 @@
|
|||
public class ExerciseRunner {
|
||||
public static void main(String[] args) {
|
||||
ValidSudoku validSudoku = new ValidSudoku();
|
||||
|
||||
// Test case 1
|
||||
char[][] board1 = {
|
||||
{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
|
||||
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
|
||||
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
|
||||
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
|
||||
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
|
||||
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
|
||||
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
|
||||
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
|
||||
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
|
||||
};
|
||||
System.out.println("Is board1 valid? " + validSudoku.isValidSudoku(board1)); // Expected output: true
|
||||
|
||||
// Test case 2
|
||||
char[][] board2 = {
|
||||
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
|
||||
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
|
||||
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
|
||||
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
|
||||
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
|
||||
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
|
||||
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
|
||||
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
|
||||
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
|
||||
};
|
||||
System.out.println("Is board2 valid? " + validSudoku.isValidSudoku(board2)); // Expected output: false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
## Valid Sudoku
|
||||
|
||||
### Instructions
|
||||
|
||||
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
|
||||
|
||||
1. Each row must contain the digits 1-9 without repetition.
|
||||
2. Each column must contain the digits 1-9 without repetition.
|
||||
3. Each of the nine 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.
|
||||
|
||||
The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
|
||||
|
||||
### Expected Class
|
||||
|
||||
```java
|
||||
public class ValidSudoku {
|
||||
public boolean isValidSudoku(char[][] board) {
|
||||
// Implementation to determine if the Sudoku board is valid
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Here is a possible `ExerciseRunner.java` to test your class:
|
||||
|
||||
```java
|
||||
public class ExerciseRunner {
|
||||
public static void main(String[] args) {
|
||||
ValidSudoku validSudoku = new ValidSudoku();
|
||||
|
||||
// Test case 1
|
||||
char[][] board1 = {
|
||||
{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
|
||||
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
|
||||
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
|
||||
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
|
||||
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
|
||||
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
|
||||
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
|
||||
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
|
||||
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
|
||||
};
|
||||
System.out.println("Is board1 valid? " + validSudoku.isValidSudoku(board1)); // Expected output: true
|
||||
|
||||
// Test case 2
|
||||
char[][] board2 = {
|
||||
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
|
||||
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
|
||||
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
|
||||
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
|
||||
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
|
||||
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
|
||||
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
|
||||
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
|
||||
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
|
||||
};
|
||||
System.out.println("Is board2 valid? " + validSudoku.isValidSudoku(board2)); // Expected output: false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Expected Output
|
||||
|
||||
```shell
|
||||
$ javac *.java -d build
|
||||
$ java -cp build ExerciseRunner
|
||||
Is board1 valid? true
|
||||
Is board2 valid? false
|
||||
$
|
||||
```
|
Loading…
Reference in New Issue