Problem 54780. Trap a knight

Consider a knight on an infinite chessboard labeled with numbers spiraling outward. A knight starting on the square labeled 1 can reach 8 squares, marked in green below (i.e., squares 10, 12, 14, 16, 18, 20, 22, and 24). Take the smallest of these numbers, or 10. Repeating the step while avoiding squares already visited puts the knight at squares 3, 6, 9, 4, 7, 2, 5, etc. This tour continues until step 2016, when the knight reaches square 2084. At that point the knight is trapped: it has visited all eight possible squares.
Write a function that takes the starting square and returns the sequence of squares visited by the knight on the tour.

Solution Stats

17.39% Correct | 82.61% Incorrect
Last Solution submitted on Apr 30, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers4

Suggested Problems

More from this Author265

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!