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

13.64% Correct | 86.36% Incorrect
Last Solution submitted on Jan 25, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers3

Suggested Problems

More from this Author244

Problem Tags

Community Treasure Hunt

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

Start Hunting!