스도쿠 해결 프로그램 소스에 대해 질문 하나만요.. 알고리즘을 모르겠어요
해긴
질문 제목 : 스도쿠 해결소스에서 알고리즘에 대해이 소스를 구했는데요... 이 소스의 알고리즘을 모르겠어요....
백트래킹이라든지 무작정 돌린다는 건지... 전혀 모르겠어요... 좀 도와주세요
질문 내용 :
#includestdio.h
void clear()
{
file * fn;
fn=fopen(result.txt, w);
fclose(fn);
}
void read(int (*s)[9])
{
int i, j;
file * fn;
fn=fopen(sudoku.txt, r);
for(i=0;i9;i++)
for(j=0;j9;j++)
fscanf(fn, %d, &s[j][i]);
fclose(fn);
}
void write(int (*s)[9])
{
int i,j;
file * fn;
fn=fopen(result.txt, a);
for(i=0;i9;i++)
{
for(j=0;j9;j++)
fprintf(fn, %d , s[j][i]);
fprintf(fn, \n);
}
fprintf(fn, \n);
fclose(fn);
}
void loops(int (*s)[9], int depth)
{
int x=depth%9, y=depth/9, bx=(x/3)*3, by=(y/3)*3, j, k, p[10]={0};
if(depth==81)
write(s);
else if(s[x][y]!=0)
loops(s, depth+1);
else
{
for(j=0;j9;j++)
{
p[s[x][j]]=1;
p[s[j][y]]=1;
p[s[bx+j/3][by+j%3]]=1;
}
for(j=1;j10;j++)
if(p[j]==0)
{
s[x][y]=j;
loops(s, depth+1);
s[x][y]=0;
}
}
}
void main()
{
int s[9][9], i, j;
read(s);
clear();
loops(s, 0);
}