스도쿠 - 솔버 기능에 문제가 있습니다. 백 트랙킹 프로세스를 수행하지 않고 이유를 알 수 없습니다. 역 추적이 오면 기능이 중지됩니다. 코드는 다음과 같습니다.스키마의 스도쿠 백 트랙킹 알고리즘
--------------- + + ----- ----- ----- +;:
(define (solve-sudoku grid)
(define blank-space (check-for-empty-space 0 '()))
(cond [(empty? blank-space) (begin (display "FIN\n") true)])
(define x (first blank-space))
(define y (first (rest blank-space)))
(display x) (display y) (display "\n")
(cond [(eqv? #f (try-value grid 1 x y)) false])
)
(define (try-value grid num x y)
(cond [(> num 9) false]
[(is-safe grid num x y)
(begin
(assign-to-pos grid num x y)
(cond [(solve-sudoku grid) true]
[else (begin (display "reset\n")
(assign-to-pos grid 0 x y))]
))]
[else (try-value grid (+ 1 num) x y)])
)
난 시험 행렬을 (row 0 (벡터 3 0 6 5 0 8 4 0 0) 정의)
(행 1 (벡터 5 2 0 0 0 0 0 0 0) 정의)
0 0 0 3 1))
--------------- + ----- + ----- + ----- + -
(행 3 정의 (벡터 0 0 3 0 1 0 0 8 0))가
(row4 (벡터 9 8 6 0 0 0 0 3 5))
(정의 row5 (벡터 0 5 0 0 0 9 0 0 6))를 정의
---- ----------- + ----- + ----- + ----- + -
(행 6 정의 (벡터 1 3 0 0 0 2 5 0))
(행 8 (벡터 0 0 5 2 0 6 3 0 0) 정의)
----------- ---- + ----- + ----- + ----- + -
(그리드 (vector row0 row1 row2 row3 r ow4 row5 row6 row7 row8))
출력은 :
빈 위치 : 0,1
빈 위치 : 0,4
빈 위치 : 0,7
베스가 위치 : 0,8
빈 위치 : 1,2-
빈 위치 : 1,3
빈 위치 : 1,4
빈 위치 : 1,5-
빈 위치 : 1,6-
빈 위치 : 1,7-
빈 위치 : 1,8-
리셋
결과
'# (# (3 1 6 5 8 2 4 9 7)
# (5 2 (0 8 7 0 0 0 3 1)
# (0 0 3 0 1 0 0 8 0)
# (9 0 0 0 6 0 0 0)
12351641061710 #
# (0 5 0 0 9 0 6 0 0)
# (1 3 0 0 0 2 5 0)
# (0 0 0 0 0 0 7 4)
# (0 0 5 2 0 6 3 0 0))