info@meritcampus.com    +91-85006-22255
...

In chess, assuming that the columns are numbered A to H and the rows are numbered 1 to 8. Write a program to find all the possible positions which a black horse can move to without getting killed by white camel. Assume that there is nothing else on the chess board apart from these two.
NOTE: The list returned should be first sorted by columns and then by rows, so A4 comes before B1 and C7 comes before D5 etc.,

Input (Black Horse Position, White Camel Position) Output (Sorted List of Positions)
Horse = C3, Camel = B7 [A2, A4, B1, B5, D1, E2]
Horse = D3, Camel = C6 [B2, B4, C1, C5, E1, E5, F2, F4]
Horse = G4, Camel = F8 [E3, E5, F2, F6, H2]
Horse = E5, Camel = D5 [D3, D7, G4, G6]

``` class FindBlackHorsePositionsWithWhiteCamel {    public static void main(String s[])    {        ChessPosition blackHorse = new ChessPosition('H', 3);        ChessPosition whiteCamel = new ChessPosition('H', 2);        System.out.println("The positions which the black horse can move to with out getting killed : " + getPossiblePositions(blackHorse, whiteCamel));    } public static List<ChessPosition> getPossiblePositions(ChessPosition blackHorse, ChessPosition whiteCamel) { //Write code here to get all the possible positions which a black horse can move to without getting killed by white camel. } } class ChessPosition { char column; int row; public ChessPosition(char column, int row) { this.column = column; this.row = row; } @Override public String toString() { return column + "" + row; } } ```
0
Wrong
Score more than 2 points