-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_6.py
More file actions
22 lines (18 loc) · 727 Bytes
/
core_6.py
File metadata and controls
22 lines (18 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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.
def solution(n, firstNumber):
bound = n//2
if firstNumber>bound:
return firstNumber-bound
elif firstNumber==bound:
return 0
return firstNumber+bound
# alt solution
# def solution(n, firstNumber):
# mid_point = n//2
# if firstNumber>mid_point:
# return mid_point-(n-firstNumber)
# elif firstNumber==mid_point:
# return 0
# return mid_point+firstNumber