2019-4: Knight Moves
1 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 |
2 1 | 2 2 | 2 3 | 2 4 | 2 5 | 2 6 | 2 7 | 2 8 |
3 1 | 3 2 | 3 3 | 3 4 | 3 5 | 3 6 | 3 7 | 3 8 |
4 1 | 4 2 | 4 3 | 4 4 | 4 5 | 4 6 | 4 7 | 4 8 |
5 1 | 5 2 | 5 3 | 5 4 | 5 5 | 5 6 | 5 7 | 5 8 |
6 1 | 6 2 | 6 3 | 6 4 | 6 5 | 6 6 | 6 7 | 6 8 |
7 1 | 7 2 | 7 3 | 7 4 | 7 5 | 7 6 | 7 7 | 7 8 |
8 1 | 8 2 | 8 3 | 8 4 | 8 5 | 8 6 | 8 7 | 8 8 |
Consider a chess board as an 8Γ8 matrix with square (1 1)
in the upper left corner and square (8 8)
in the lower right corner. For those not familiar with the game of chess, the knight, generally depicted as a horse (β), can move 2 spaces right or left and then 1 space up or down, or 2 spaces up or down and then 1 space right or left. This means that a knight on square (5 4)
can move to any of the indicated squares. Given a 2-element vector representing the current square for a knight, return a vector of 2-element vectors representing (in any order) all the squares that the knight can move to.
π‘ Hint: The outer product operator β.
could be useful for generating the coordinates.
Examples:
(your_function) 5 4 β ]Box on is used to display the result
βββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ
β3 3β3 5β4 2β4 6β6 2β6 6β7 3β7 5β
βββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ
(your_function) 1 1
βββββ¬ββββ
β2 3β3 2β
βββββ΄ββββ
your_function β
Solutions

