Sudoku - Zulässigkeit

12/08/2014 11:13 The_Dentist#1
Hallo,

Ich habe noch ein zweites Problem, diesmal geht es um einen Sudokolöser:

Meine Methode sieht derzeit wie folgt aus:

Code:
static boolean zulaessig(int[][] feld, int x, int y) {

int wert = feld[x][y];
		


		for(int i = 0; i < 9; i++){
			if(wert == feld[i][y]) return false;
		}	
		for(int j = 0; j < 9; j++){
			if(wert == feld[x][j]) return false;
		}

	

		return true;

	}
Jetzt habe ich das Problem, dass ich noch einmal 3*3 Feld durchgehen soll. Die Aufgabenstellung ist: Dies möglichst effizient zu programmieren, also laufe ich einmal die Spalte durch mit dem Wert und einmal die Zeile.

Leider funktioniert dies noch nicht wie es soll. Zudem weiß ich auch noch nicht genau wie ich das 3*3 kleine Feld durchgehe.

Kann mir dabei Jemand helfen?

Vielen Dank.

LG

The_Dentist
12/08/2014 13:48 Belur#2
Ich habs jetzt nicht compiliert und gestestet obs klappt aber so müsste das in etwa gehen:

PHP Code:
public static boolean checkBox(int xint yint val) {

        
int xTemp = (x/3)*3;
        
int yTemp = (y/3)*3;
        

        for (
int row xTemprow xTemp+3row++) {
            for (
int col yTempcol yTemp+3col++) {
                if (
Field[row][col] == val) {
                    return 
false;
                }
            }
        }
        return 
true;
    } 
Dein Problem mit den springenden Damen schon gelöst? ;)