王室の夜


質問する


8つの8座標平面があります.一室にナイトクラブが立っている.ナイト移動時はL字でしか移動できません.チェスしかできません.nightは、次の2つの状況に移動できます.
  • 水平に2つの格子を移動した後、垂直に1つの格子
  • を移動する.
  • 垂直に2つの格子を移動した後、水平に1つの格子
  • を移動する.
    8 x 8平面において、あるノードの位置が与えられた場合、そのノードが移動可能な数が出力される.行位置は1〜8、列位置はa〜hで表す.


    ナイトがa 1にいた時

  • 右2グリッド、下1グリッド(c 2)
  • 下2格、右側1格(b 3)
  • 出力:2

    ナイトがc 2にいた時

  • 左に2つのグリッドを上へ(1)
  • 左2グリッド、下1グリッド(a 3)
  • 下2グリッド、左1グリッド(b 4)
  • 下2グリッド、右側グリッド(4 d)
  • 右2グリッド、上1グリッド(e 1)
  • 右2グリッド、下1グリッド(e 3)
  • 出力:6

    に道を教える


    計算:[(-2, 1), (-2, -1), (2, 1), (2, -1), (1, 2), (-1, 2), (1, -2), (-1, -2)]
    input_data = input() 
    
    column = int(ord(input_data[0])) - int(ord('a')) + 1
    row = int(input_data[1])
    
    steps = [(-2, 1), (-2, -1), (2, 1), (2, -1), (1, 2), (-1, 2), (1, -2), (-1, -2)]
    
    result = 0 
    for step in steps: 
      next_column = column + step[0]
      next_row = row + step[1]
      if (next_column >= 1) and (next_column <= 8) and (next_row >= 1) and (next_column <= 8): 
        result += 1 
    
    print(result)