Anonymous user
Knight's tour: Difference between revisions
→{{header|Icon}} and {{header|Unicon}}: split off debug code
(→{{header|Python}}: (Excerpts from) 200x200 example shown.) |
(→{{header|Icon}} and {{header|Unicon}}: split off debug code) |
||
Line 219:
<lang Icon>procedure main(A)
B := KnightsTour(8) # Try a tour
(\DumpBoard)(B)
end
procedure KnightsTour(N)
moves := []
visited := set()
B := Board(N)
sq := ?B.cols || ?B.rows
repeat {
put(moves,sq)
insert(visited,sq)
choices := B.movesto[sq] -- visited
sq := ?(choices ** \!B.accessibility) | break # least accessible
Line 281:
}
every write(hdr2|hdr1)
end</lang>
<lang Icon>procedure DumpBoard(B) #: dump the board structure for analysis
write("Board size=",B.N)
every put(K := [],key(B.movesto))
Line 314:
+-------------------------+
a b c d e f g h</pre>
=={{header|J}}==
|