NAKANJC - Minimum knight moves Challenge
Anjali and Nakul are good friends. They had quarrelled and you had written a program for Anjali to know the
minimum number of moves a knight takes to reach from one square to another square of a chess board
(8X8).
Nakul is brilliant and knows Anjali didn't write it herself and says her program is too slow by all standards. He is
unimpressed so she asks you to try solve the problem faster this time using as few keystrokes as possible.
She wants to know whether you can actually do it. Anjali is very weak in programming. Help her to solve the
problem.
Since you are busy and tend to forget she reminds you that "A knight can move in the shape of an "L" in a chessboard - two squares either forward, backward, left, or right and then one square to its left or right. A knight move is valid if it moves as mentioned above and it is within the boundary of the chessboard (8 X 8).Since you are busy and tend to forget she reminds you that-
"A knight can move in the shape of an "L" in a chessboard - two squares either forward, backward, left,
or right and then one square to its left or right. A knight move is valid if it moves as mentioned above and
it is within the boundary of the chessboard (8 X 8)."
first solve problem http://www.spoj.com/problems/NAKANJ/
Input
There are T test cases in total. The next T lines contain two strings (start and destination) separated by a
space.
T<=200001
The strings start and destination will only contain two characters - First character is an alphabet between
'a' and 'h' (inclusive), Second character is a digit between '1' and '8' (inclusive) - (Quotes just for clarity).
Output
Print the minimum number of moves a knight takes to reach from start to destination in a separate line.
Example
Input:
EDIT: Time limit increased 28-11-2012. All submissions rejudged3 a1 h8 a1 c2 h8 c3Output:6Score:
1
4Your source code length (if you are successful in avoiding TLE and WA)
The smaller code the better
hide comments
hwb_worwa:
2018-03-01 06:18:52
Cut 4059 B of fully documented wonderfull C++ code to 658 B of unreadable junk. And still did not crack top 100 :(. Last edit: 2018-03-01 06:24:40 |
|
e869120:
2016-08-01 07:44:45
C in 365B. |
|
nadavishe:
2014-04-13 10:00:56
Haskell - 319 B Last edit: 2014-04-13 10:01:23 |
|
Aditya Pande:
2012-12-26 07:27:08
i would like to congratulate language wise best submissions:
|
|
Aditya Pande:
2012-12-13 08:28:36
|
Added by: | Aditya Pande |
Date: | 2012-11-26 |
Time limit: | 0.100s-1s |
Source limit: | 5000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | own |