Created
March 29, 2020 00:31
-
-
Save Nicknyr/e038d45170ee591cdbee75fe83dbd82a to your computer and use it in GitHub Desktop.
CodeSignal - Circle of Numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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