문제: Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1 are neighboring, too).
Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.
Example:
Example
For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.
-문제해결 정리-
1. 수학적으로 계산하면 원의 반대편에 있는 점은 다음과 같다.
firstNumber가 n // 2 보다 작을경우:
반대편에 있는 점 --> (firstNumber) + (n // 2)
firstNumber가 n // 2 보다 클 경우:
반대편에 있는 점 --> (firstNumber) - (n // 2)
2. 이 수식을 그대로 코드에 구현
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [32/60] absoluteValuesSumMinimization (0) | 2020.05.22 |
---|---|
CodeSignal [31/60] depositProfit (0) | 2020.05.22 |
CodeSignal [29/60] chessBoardCellColor (0) | 2020.05.20 |
CodeSignal [28/60] alphabeticShift (0) | 2020.05.19 |
CodeSignal [27/60] variableName (0) | 2020.05.18 |
댓글