Anonymous user
Knight's tour: Difference between revisions
→{{header|Mathematica}}
Line 1,833:
Find a Hamiltonian cycle (a path that visits each square exactly one time.)
<lang Mathematica>
hamiltonianCycle = ((FindHamiltonianCycle[knightsGraph] /. UndirectedEdge -> DirectedEdge) /. labels)[[1]];
</lang>
Line 1,842:
<lang Mathematica>
end = Cases[hamiltonianCycle, (x_ \[DirectedEdge] start) :> x][[1]];
<
Find shortest path from the start square to the end square.
<lang Mathematica>
FindShortestPath[g, start, end]]
▲<\lang>
=={{header|Mathprog}}==
|