본문 바로가기
CodeSignal/Arcade

CodeSignal [50/60] chessKnight

by 벤진[Benzene] 2020. 5. 28.

Problem:

Given a position of a knight on the standard chessboard, find the number of different moves the knight can perform.

The knight can move to a square that is two squares horizontally and one square vertically, or two squares vertically and one square horizontally away from it. The complete move therefore looks like the letter L. Check out the image below to see all valid moves for a knight piece that is placed on one of the central squares.

Example

  • For cell = "a1", the output should be
    chessKnight(cell) = 2.

  • For cell = "c2", the output should be
    chessKnight(cell) = 6.

     

     

     

     

     

-Summary- 

1. Create a list of tuples for a valid move of a chess knight.

2. with the current position of 'cell', check if those moves are valid. (adding the current position of x and y to the valid moves).

모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]

https://codesignal.com/

'CodeSignal > Arcade' 카테고리의 다른 글

CodeSignal [52/60] longestWord  (0) 2020.05.28
CodeSignal [51/60] deleteDigit  (0) 2020.05.28
CodeSignal [49/60] lineEncoding  (0) 2020.05.27
CodeSignal [48/60] isDigit  (0) 2020.05.27
CodeSignal [47/60] isMAC48Address  (0) 2020.05.27

댓글