Knight's tour: Difference between revisions

no edit summary
(oops, wrong task)
No edit summary
Line 3,784:
</pre>
cf. [[Solve a Holy Knight's tour#Ruby|Solve a Holy Knight's tour]]:
 
 
 
 
 
 
 
 
=={{header|Scheme}}==
<lang scheme>
;;/usr/bin/petite
;;encoding:utf-8
;;Author:Panda
;;Mail:panbaoxiang@hotmail.com
;;Created Time:Thu 29 Jan 2015 10:18:49 AM CST
;;Description:
 
;;size of the chessboard
(define X 8)
(define Y 8)
;;position is an integer that could be decoded into the x coordinate and y coordinate
(define(decode position)
(cons (div position Y) (remainder position Y)))
;;record the paths and number of territories you have conquered
(define dictionary '())
(define counter 1)
;;define the forbiddend territories(conquered and cul-de-sac)
(define forbiddened '())
;;renew when havn't conquered the world.
(define (renew position)
(define possible
(let ((rules (list (+ (* 2 Y) 1 position)
(+ (* 2 Y) -1 position)
(+ (* -2 Y) 1 position)
(+ (* -2 Y) -1 position)
(+ Y 2 position)
(+ Y -2 position)
(- position Y 2)
(- position Y -2))))
(filter (lambda(x) (not (or (member x forbiddened) (< x 0) (>= x (* X Y))))) rules)))
(if (null? possible)
(begin (set! forbiddened (cons (car dictionary) forbiddened))
(set! dictionary (cdr dictionary))
(set! counter (- counter 1))
(car dictionary))
(begin (set! dictionary (cons (car possible) dictionary))
(set! forbiddened dictionary)
(set! counter (+ counter 1))
(car possible))))
;;go to search
(define (go position)
(if (= counter (* X Y))
(begin
(set! result (reverse dictionary))
(display (map (lambda(x) (decode x)) result)))
(go (renew position))))
</lang>
{{out}}
<pre>
(go 35)
((6 . 4) (4 . 5) (6 . 6) (4 . 7) (7 . 0) (5 . 1) (7 . 2) (5 . 3) (7 . 4) (5 . 5) (7 . 6) (5 . 7) (4 . 0) (6 . 1) (4 . 2) (6 . 3) (4 . 4) (6 . 5) (4 . 6) (6 . 7) (5 . 0) (7 . 1) (5 . 2) (7 . 3) (5 . 4) (7 . 5) (5 . 6) (7 . 7) (6 . 0) (4 . 1) (6 . 2) (4 . 3) (2 . 4) (0 . 5) (2 . 6) (0 . 7) (3 . 0) (1 . 1) (3 . 2) (1 . 3) (3 . 4) (1 . 5) (3 . 6) (1 . 7) (0 . 0) (2 . 1) (0 . 2) (2 . 3) (0 . 4) (2 . 5) (0 . 6) (2 . 7) (1 . 0) (3 . 1) (1 . 2) (3 . 3) (1 . 4) (3 . 5) (1 . 6) (3 . 7) (2 . 0) (0 . 1) (2 . 2))
</pre>
 
=={{header|Tcl}}==
5

edits