Sdoku
Steve Paks
Question

•

•

•

나머지 빈 칸을 채우는 방식은 다음과 같다.
(1) 각각의 가로줄과 세로줄에는 1부터 9까지의 숫자가 한 번씩만 나타나야 한다.
(2) 굵은 선으로 구분되어 있는 3x3 정사각형 안에도 1부터 9까지의 숫자가 한 번씩만 나타나야 한다.
위의 예의 경우, 첫째 줄에는 1을 제외한 나머지 2부터 9까지의 숫자들이 이미 나타나 있으므로 첫째 줄 빈칸에는 1
이 들어가야 한다.

또한 위쪽 가운데 위치한 3x3 정사각형의 경우에는 3을 제외한 나머지 숫자들이 이미 쓰여 있으므로 가운데 빈 칸
에는 3이 들어가야 한다.
Question(Cont’d)
•

입력 예

035469278
782105609
060278135
321046897
804913506
596820413
917652080
603701952
258394760

출력 예

135469278
782135649
469278135
321546897
874913526
596827413
917652384
643781952
258394761
Algorithm
•

Find way to finish the sdoku
Algorithm(Cont’d)
•

find candidates
–

Get number of candidates

For(i){
if(sdoku[row][i] == 0){
noOfCandidates++;
}
}
–

Find candidates

For(i){
for(j){
if( i == sdoku[row][j]) break;
if( j == noOfRows - 1){
addCandidates(i);
}
}

035469278
782105609
060278135
321046897
804913506
596820413
917652080
603701952
258394760
Algorithm(Cont’d)
•

Check duplicate condition
–
–

Value(= 5)
Row(= 3)

–

Column(= 3)

Value
5

035469278
782105609
060278135
321046897
804913506
596820413
917652080
603701952
258394760
Algorithm(Cont’d)
•

Check duplicate condition(Cont’d)
–

3 X 3 matrix

3, 3 3, 4 3, 5
4, 3 4, 4 4, 5
5, 3 5, 4 5, 5

Row = 3;
Col = 3;
tempRowLimit = (Row % 3) + 3;
tempColLimit = (Col % 3) + 3;
Row = 5;
Col = 5;
tempRowLimit = (Row % 3) + 1;
tempColLimit = (Col % 3) + 1;
Row = 2;
Col = 0;
tempRowLimit = (Row % 3) + 1;
tempColLimit = (Col % 3) + 3;

Value
5

035469278
782105609
060278135
321046897
804913506
596820413
917652080
603701952
258394760

If(n % 3 == 0){
n + 3;
}else if{n % 3 == 1){
n + 2;
}else{
n + 1;
}
Algorithm(Cont’d)
•

Remain issue
–
–
–
–
–
–
–

In an order of visit among the candidates makes an issue
As following example we got the candidates 2, 7 at line 5
At first, 2 is put at the col 2.
In this case 2 makes an duplicate condition in the vertical line
So, we try to put 7 at the position.
And 2 will not be considered.
So, we will reconsider during return to the first recursion.

035469278
782105609
060278135
321046897
804913506
596820413
917652080
603701952
258394760
Core methods
• makeSdoku(int)
–
–
–
–

각 행에서 아직 선택되지 않은 후보들을 찾아서
빈 칸에 놓아 보고
중복 조건에 위배되면
조건을 만족할 때 까지 다른 빈 칸에 놓는 동작을 반복

• getCandidates(int)
– 아직 선택되지 않은 후보들을 찾음

• getVacancyCol(int)
– 빈 칸을 찾음

• isDuplicate(int, int, int)
– 중복 조건을 검토

More Related Content

PPTX
N queen
PDF
Fashion central international magazine december issue 2015
PPTX
Recursion & Complexity
PPT
The gravitational N -body pro
PPT
3장 자동적으로 움직이는 게임 에이전트 생성법
PPTX
Dynamically linked stacks
PPTX
Good numbers
PPT
FIGURAS GEOMETRICAS
N queen
Fashion central international magazine december issue 2015
Recursion & Complexity
The gravitational N -body pro
3장 자동적으로 움직이는 게임 에이전트 생성법
Dynamically linked stacks
Good numbers
FIGURAS GEOMETRICAS

Viewers also liked (15)

PPTX
Education systems in Europe
PPTX
Dynamically linked queues
PPTX
PPTX
Min inconmensurable weight
PPTX
Hemilton cycle circuit
PPTX
Evaluation expression
PDF
HEEC2015
PPTX
Polynomials
PPTX
8150.graphs
PPTX
Singly linked lists
DOCX
Norway
PPTX
Introduction au développement chimique pharmaceutique
PPTX
Sparse matrices
PPTX
Garden for princess
PDF
알고리즘과 자료구조
Education systems in Europe
Dynamically linked queues
Min inconmensurable weight
Hemilton cycle circuit
Evaluation expression
HEEC2015
Polynomials
8150.graphs
Singly linked lists
Norway
Introduction au développement chimique pharmaceutique
Sparse matrices
Garden for princess
알고리즘과 자료구조
Ad

Sdoku