One of my favorite games are chess. Let’s do something with chess. If you don’t know chess, that’s completely fine. You can still solve this problem.
A chess board has 8 rows and 8 columns. You can think of it as an 8-by-8 matrix. Now your board contains only one piece, a knight. It is placed at (x,y) position. For the picture below, the knight is at (5,5).
A knight has 8 possible valid moves that are marked as cross in the picture. For example, a knight can move – ‘two steps right and one step up’; which brings it to position (4,7).
Write a code to find out those 8 valid positions from any input value of (x,y).
Output: (4,7), (6,7), (4,3), (6,3), (3,4), (3,6), (7,4), (7,6).
- Use an 8 by 2 matrix to represent the answer.
- Use sortrows() function to match the output
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers14
Suggested Problems
-
Back to basics 8 - Matrix Diagonals
966 Solvers
-
Back to basics 23 - Triangular matrix
1122 Solvers
-
Return the first and last characters of a character array
11859 Solvers
-
399 Solvers
-
Circular Primes (based on Project Euler, problem 35)
651 Solvers
More from this Author8
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!