Question: Challenge Bonus 15%: Write a function called knightsMove, to calculate how many knights moves it will take to get from two input numbers to two
- Challenge Bonus 15%: Write a function called knightsMove, to calculate how many knights moves it will take to get from two input numbers to two target numbers. A knights move is one that either adds 2 or subtracts 2 from one number and adds 1 or subtracts 1 from the other number. So if my inputs were: 1 and 4 and the target was: 6 and 0 then the moves I could make are: 1+2 = 3, 4-1=3 3+1 = 4, 4-2=1 4+2= 6, 1-1 =0 so the function would return 3, indicating that it would take 3 knights moves to reach the target. I would also like the function to output the steps it took to reach the goal. Extra bonus given if you can output it on a chessboard:
|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 0 |
|
|
|
|
|
|
|
|
| 1 |
|
|
|
| 1 |
|
|
|
| 2 |
|
|
|
|
|
|
|
|
| 3 |
|
|
| 2 |
|
|
|
|
| 4 |
| 3 |
|
|
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
| 6 | 4 |
|
|
|
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
