Created
April 6, 2023 21:21
-
-
Save HamsterofDeath/ad31e4cdc5d089c8fa3cfab3448626b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package superprof; | |
public class SudokuChecker { | |
public static void main(String[] args) { | |
// Ein Beispiel-Sudoku-Raster | |
int[][][] sudoku = { | |
{ | |
{5, 3, 4}, | |
{6, 7, 2}, | |
{1, 9, 8} | |
}, | |
{ | |
{6, 7, 8}, | |
{1, 9, 5}, | |
{3, 4, 2} | |
}, | |
{ | |
{9, 1, 2}, | |
{3, 4, 5}, | |
{6, 7, 8} | |
}, | |
{ | |
{8, 5, 9}, | |
{4, 2, 6}, | |
{7, 1, 3} | |
}, | |
{ | |
{4, 2, 6}, | |
{8, 5, 3}, | |
{7, 9, 1} | |
}, | |
{ | |
{7, 1, 3}, | |
{9, 8, 1}, | |
{4, 5, 6} | |
}, | |
{ | |
{9, 6, 1}, | |
{5, 3, 7}, | |
{2, 8, 4} | |
}, | |
{ | |
{2, 8, 7}, | |
{4, 1, 9}, | |
{5, 6, 3} | |
}, | |
{ | |
{3, 4, 5}, | |
{2, 8, 6}, | |
{1, 7, 9} | |
} | |
}; | |
System.out.println("Ist das Sudoku gültig? " + isSudokuValid(sudoku)); | |
} | |
public static boolean isSudokuValid(int[][][] sudoku) { | |
// Überprüfen Sie die Zeilen | |
// TODO: Vervollständigen Sie die Implementierung, um die Zeilen zu überprüfen. | |
// Überprüfen Sie die Spalten | |
// TODO: Vervollständigen Sie die Implementierung, um die Spalten zu überprüfen. | |
// Überprüfen Sie die 3x3-Blöcke | |
for (int[][] block : sudoku) { | |
if (!isBlockValid(block)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public static boolean isBlockValid(int[][] block) { | |
// TODO: Vervollständigen Sie die Implementierung, um die 3x3-Blöcke zu überprüfen. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment