-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcircleOfNumbers.R
More file actions
executable file
·32 lines (30 loc) · 877 Bytes
/
circleOfNumbers.R
File metadata and controls
executable file
·32 lines (30 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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
#
# For n = 10 and firstNumber = 2, the output should be
# circleOfNumbers(n, firstNumber) = 7.
#
# Input/Output
#
# [execution time limit] 5 seconds (r)
#
# [input] integer n
#
# A positive even integer.
#
# Guaranteed constraints:
# 4 ≤ n ≤ 20.
#
# [input] integer firstNumber
#
# Guaranteed constraints:
# 0 ≤ firstNumber ≤ n - 1.
# n = 10
# firstNumber = 7
circleOfNumbers <- function(n, firstNumber) {
DiagonallyOpposite = ifelse((n/2) > firstNumber,((n/2) + firstNumber),(firstNumber - (n/2)))
return(DiagonallyOpposite)
}