Find path traveling which bishop traverse each black cell atleast once
Last Updated : 6 Apr, 2023
Given two integers X and Y such that X+Y is even, Which denotes the initial position of the bishop on a chessboard of 8 x 8 dimension. Then the task is to output a continuous path with not more than 32 coordinates(total black cells on board) such that traveling on that path bishop covers all the cells (i, j) having even sum (i + j = even). These cells need to be covered at least once over the course of travel, return the number of coordinates taken in the path, and the coordinates of the path to be followed.
Note: A single cell can be traversed more than once.
Initially, the bishop is placed at (5, 3). Then it moves as follows: A (4, 4) -> B (1, 1) -> C (8, 8 ) -> D (7, 7) -> E (8, 6) -> F (3, 1) and so on. So, In total there are 19 moves, Which are shown in the output. Following this output coordinates all the cells (i, j) having even sum, ie. (i + j) = even, will be traversed. Formally, all black cells will be traversed.
Input: X =1, Y = 1 Output: 17 1 1 8 8 7 7 8 6 . . . . and so on. Explanation: In total there will be 17 moves, and the starting of the path is as: (1, 1) -> (8, 8) -> (7, 7) -> (8, 6) and so on . . . .
Approach: Implement the idea below to solve the problem:
The problem is observation based and can be solved by using those observations. There exists a common path that applies for all the inputs of X and Y. By thinking about this problem deeply, we can observe a common path.
Steps were taken to solve the problem:
Create a method commonPath() containing the below co-ordinates: