Anonymous user
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 {
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
%
} def
Line 749 ⟶ 750:
func /n var
/n1 n 1 sub def
/occupied n ar2 def▼
/y 0 def▼
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
0 1 n1
▲ /occupied n ar2 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
/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
}
▲ % to be nice, draw box at final position
▲ y .5 sub x .5 sub bx 1 setlinewidth stroke
end
} def
%%EOF</lang>
=={{header|Python}}==
|