Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write down the code in C++ A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the
write down the code in C++
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard exactly once. He thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves the difficult" part. Your job is to write a program that takes two squares a and b as input and then determines the number of knight moves on a shortest route from a to b. Input The input file will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a...h) representing the column and a digit (1..8) representing the row on the chessboard. Output For each test case, print one line saying 'To get from xx to yy takes n knight moves.' Sample Input Sample Output e2 e4 To get from e2 to e4 takes 2 knight moves. al b2 To get from al to b2 takes 4 knight moves. b2c3 To get from b2 to c3 takes 2 knight moves. al h8 To get from al to h8 takes 6 knight moves. al h7 To get from al to h7 takes 5 knight moves. h8 al To get from h8 to al takes 6 knight moves. bl c3 To get from bl to c3 takes 1 knight moves. f6f6 To get from f6 to f6 takes O knight movesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started