1. 程式人生 > >Code Signal_練習題_Circle of Numbers

Code Signal_練習題_Circle of Numbers

練習題 哈哈哈 signal .com style first one sign hide

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 - 1are neighboring, too).

Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber.

Example

For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.

技術分享圖片

我的解答:

def circleOfNumbers(n, firstNumber):
    return (firstNumber+n/2) % n

技術分享圖片
我的解法和排名第一的大佬寫的一樣....哈哈哈
膜拜大佬

Code Signal_練習題_Circle of Numbers