[Solution] Journey of the Knight solution codechef

Journey of the Knight solution codechef – Chef has an 8×88×8 chessboard. He placed a knight on the square (X1,Y1)(X1,Y1). Note that, the square at the intersection of the ithith row and jthjth column is denoted by (i,j)(i,j).

Table of Contents

[Solution] Journey of the Knight solution codechef

Chef wants to determine whether the knight can end up at the square (X2,Y2)(X2,Y2) in exactly 100100 moves or not.

For reference, a knight can move to a square which is:

  • One square horizontally and two squares vertically away from the current square, or
  • One square vertically and two squares horizontally away from the current square

A visual description of this may be found here.

Input Format

  • The first line contains a single integer TT — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains 44 integers X1,Y1,X2,Y2X1,Y1,X2,Y2 — where (X1,Y1)(X1,Y1) denotes the starting square of the knight and (X2,Y2)(X2,Y2) denotes the ending square of the knight.

[Solution] Journey of the Knight solution codechef

For each test case, output YES if knight can move from (X1,Y1)(X1,Y1) to (X2,Y2)(X2,Y2) in exactly 100100 moves. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yesyEsYes will be considered identical).


  • 1T10001≤T≤1000
  • 1X1,Y1,X2,Y281≤X1,Y1,X2,Y2≤8

Sample Input 1 

1 1 1 1
8 8 7 6
8 8 8 6

[Solution] Journey of the Knight solution codechef




Test Case 1: Knight can first move to (2,3)(2,3) and then back to (1,1)(1,1). He can repeat this 5050 times and he will end up at (1,1)(1,1) after 100100 moves.

Test Case 2: It can be proven that it is not possible for the knight to end at (7,6)(7,6) after 100100 moves.

Test Case 3: Knight can first move to (6,7)(6,7) and then to (8,6)(8,6). After that, he can alternate between (6,7)(6,7) and (8,6)(8,6) for 4949 times and he will end up at (8,6)(8,6) after 100100 moves.

For Solution

Click Here

Leave a Comment