A Knightly Tour

By | August 30, 2015

I recently sat in on an interview in which the candidate was given the Knight’s Tour problem.  The intent was to see how the candidate would reason about the problem.  I have to admit I’m not sure I’d do well in an interview with this problem.  Until recently I had never actually attempted to solve it myself.  The funny thing is, even though I had a rough understanding of the approach I’d take, it took me better part of a Saturday to implement a solution.  Of course I wasn’t rushing through it and I was also thinking about how to represent the solution graphically since I knew I wanted to add a blog post about this problem.

I think it was a worthwhile exercise to work on if you haven’t tried to solve this problem before.  I also enjoyed the additional task of representing the solution graphically.  I used one of my favorite Java Script libraries KineticJS to render the board and solution.  For me, it was a fun exercise in a non stressful situation like an interview.  In any event, a demo of the solution is shown at the bottom of this post.  The solution is for a 5 square by 5 square board.  The source code is available on my GitHub account as well if you are interested.

Leave a Reply