Knight's tour: Difference between revisions

→‎{{header|PostScript}}: backtrack on failure (it gets too complicated)
(→‎{{header|PostScript}}: removing debug stuff...)
(→‎{{header|PostScript}}: backtrack on failure (it gets too complicated))
Line 690:
 
% draws checker board
/xbd { .7 1 .6 setrgbcolorsetgray
0 0 moveto 300 0 l 0 300 l -300 0 l closepath strokefill
.7 1 .6 c {setrgbcolor
0 1 n1 { dup 2 mod 2 n1 { 1 index bx fill } for pop } for
0 setgray
0 0 moveto 300 0 l 0 300 l -300 0 l closepath stroke
} def
 
Line 708 ⟶ 709:
-2 -1 0
-2 1 0
% 24 x y add 3 mul roll
} def
 
Line 749 ⟶ 750:
func /n var
/n1 n 1 sub def
/occupied n ar2 def
/x 0 def
/y 0 def
8 n div setlinewidth
 
xbd/c false def
 
s8 2n div dup translatesetlinewidth
/c true defgsave
n n mul 1 sub {
c {
0 setgray marker x s mul y s mul moveto
occupied x get y 1 put
neighbors
8 { pop y add exch x add exch 2 copy num_access 24 3 roll } repeat
7 { dup 4 index lt { 6 3 roll } if pop pop pop } repeat
9 ge { /c false def } if
 
0 1 n1 { /x exch def c /ynot exch def{
0 1 n1 /x exch def{
/occupied n ar2 def
n n mul 1 sub c not {
9 ge { /c falsetrue def } if
/y 0exch def
grestore xbd gsave
s 2 div dup translate
n n mul 2 sub -1 0 { /iter exch def
c {
0 setgray marker x s mul y s mul moveto
occupied x get y 1 put
neighbors
8 { pop y add exch x add exch 2 copy num_access 24 3 roll } repeat
7 { dup 4 index lt { 6 3 roll } if pop pop pop } repeat
 
.2 setgray x s mul y s mul lineto stroke 9 ge iter 0 gt and { /c false def } if
/y exch def
/x exch def
.2 setgray x s mul y s mul lineto stroke
} if } for
% to be nice, draw box at final position
.5 0 0 setrgbcolor marker
y .5 sub x .5 sub bx 1 setlinewidth stroke
stroke
} if
} repeatfor } if } for showpage
.5 0 0 setrgbcolor markergrestore
 
% to be nice, draw box at final position
y .5 sub x .5 sub bx 1 setlinewidth stroke
stroke showpage
end
} def
 
23 1 100 { solve } for
 
%%EOF</lang>
</lang>
 
=={{header|Python}}==
Anonymous user