Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Created March 29, 2020 00:31
Show Gist options
  • Select an option

  • Save Nicknyr/e038d45170ee591cdbee75fe83dbd82a to your computer and use it in GitHub Desktop.

Select an option

Save Nicknyr/e038d45170ee591cdbee75fe83dbd82a to your computer and use it in GitHub Desktop.
CodeSignal - 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.
Example
For n = 10 and firstNumber = 2, the output should be
circleOfNumbers(n, firstNumber) = 7.
*/
function circleOfNumbers(n, firstNumber) {
let half = n / 2;
if(firstNumber < half) {
return firstNumber + half;
}
else {
return firstNumber - half;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment