0
스도쿠를 풀기 위해 재귀를 쓰려고 시도했지만 재귀에 문제가 있습니다. 해결할 수 없다면 해결할 수 있지만 루프가 무한하게됩니다.재귀에 의한 스도쿠 해결
public static boolean recursion (int sodukuMatrix[][],int posRow, int posCol ,int i){
if (posRow==0 && posCol==0 && i==10)
return false;
if(there is existing number){
if (posCol==8 && posRow==8)
return true;
call recursion with next square
}
else {
i=sodukuMatrix[posRow][posCol]+1;
while (i<10){
if (function: if I put i at the current location it is ok){
sodukuMatrix[posRow][posCol]=i;
if (posCol==8 && posRow==8)
return true;
call recursion with next square
}
else
i++;
}
sodukuMatrix[posRow][posCol]=0;
return false;
}
return false;
}
}
* 컴파일 할 때 * 사용하는 코드가있는 것 같습니다. 그렇게하면 쉽게 파악할 수 있습니다. – femtoRgon
나는 프로그래밍을 할 때 아직 초보자입니다. 그래서 어떻게하는지 잘 모릅니다. 덕분에 –
게시 된 코드는 유효한 java가 아니기 때문에 * 무한 루프로 들어 가지 않습니다. 컴파일되지 않으므로 전혀 실행할 수 없습니다. 'if (함수 : 만약 내가 현재 위치에 놓으면 괜찮습니다.) {if (rec (cloneMatrix, sodukuMatrix, posRow, posCol + 1, i)}}'에서 문법 오류가 있습니다. '. – femtoRgon