Skip to content

Circle of Numbers

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.


For n = 10 and firstNumber = 2, the output should be

circle_of_numbers(n, firstNumber) = 7
Image Credit: CodeSignal


def circle_of_numbers(n, firstNumber):
    neighbour = int(firstNumber + (n/2))

    if neighbour > n:
        neighbour = int(firstNumber - (n/2))
    elif neighbour == n:
        neighbour = 0

    return neighbour

print(circle_of_numbers(6, 3))

my thoughts are neither my employer's nor my wife's