#K43697. Knight Moves in Chess

    ID: 27367 Type: Default 1000ms 256MiB

Knight Moves in Chess

Knight Moves in Chess

Given the initial position of a knight on a standard 8x8 chessboard in algebraic chess notation, compute all valid positions the knight can move to in exactly one move. The knight moves in an "L" shape which can be mathematically described by the set of offsets \(\{(2,1), (2,-1), (-2,1), (-2,-1), (1,2), (1,-2), (-1,2), (-1,-2)\}\). Only include moves that stay within the board boundaries.

For example:

  • Input: e4 produces output: c3 c5 d2 d6 f2 f6 g3 g5
  • Input: h8 produces output: f7 g6

inputFormat

The input consists of a single string in standard chess notation (e.g., "e4"). This string is provided via standard input (stdin).

outputFormat

The output should be a single line containing all possible destination positions for the knight in one move, sorted in lexicographical order and separated by a single space. The output is written to standard output (stdout).

## sample
e4
c3 c5 d2 d6 f2 f6 g3 g5